UNPKG

@aquaori/deplens

Version:

A precise dependency analysis tool for npm and pnpm projects

38 lines 1.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseAST = parseAST; const parser_1 = require("@babel/parser"); /** * 将代码解析为抽象语法树(AST) * @param fileContentList 文件内容列表 * @returns AST 列表 */ async function parseAST(fileContentList) { const asts = []; for (let i = 0; i < fileContentList.length; i++) { const content = fileContentList[i]; if (typeof content !== 'string') { console.warn(`Warning: Skipping non-string content at index ${i}`); continue; } try { const ast = (0, parser_1.parse)(content, { sourceType: 'module', allowImportExportEverywhere: true, plugins: [ 'jsx', 'typescript', 'dynamicImport', 'classProperties', 'typescript' ], }); asts.push(ast); } catch (error) { throw new Error(`\nFailed to parse file at index ${i}: \n${error instanceof Error ? error.message : String(error)}\nContent snippet: ${content.substring(0, 100)}...`); } } return asts; } //# sourceMappingURL=parser.js.map