Reduce parser plugins used in js-analyze

This makes the parsing 3 -4x faster
This commit is contained in:
zodern
2023-06-26 18:15:35 -05:00
parent cfcc3ac8d4
commit e3e50ddaad

View File

@@ -1,7 +1,7 @@
import { parse } from '@meteorjs/babel';
import { analyze as analyzeScope } from 'escope';
import LRU from "lru-cache";
import { Profile } from '../tool-env/profile';
import Visitor from "@meteorjs/reify/lib/visitor.js";
import { findPossibleIndexes } from "@meteorjs/reify/lib/utils.js";
@@ -26,9 +26,23 @@ function tryToParse(source, hash) {
}
let ast;
try {
ast = parse(source);
Profile.time('jsAnalyze.parse', () => {
ast = parse(source, {
strictMode: false,
sourceType: 'module',
allowImportExportEverywhere: true,
allowReturnOutsideFunction: true,
allowUndeclaredExports: true,
plugins: [
// Only plugins for stage 3 features are enabled
// Enabling some plugins significantly affects parser performance
'importAttributes',
'explicitResourceManagement',
'decorators'
]
});
});
} catch (e) {
if (typeof e.loc === 'object') {
e.$ParseError = true;
@@ -71,7 +85,10 @@ export function findImportedModuleIdentifiers(source, hash) {
}
const ast = tryToParse(source, hash);
importedIdentifierVisitor.visit(ast, source, possibleIndexes);
Profile.time('findImportedModuleIdentifiersVisitor', () => {
importedIdentifierVisitor.visit(ast, source, possibleIndexes);
});
return importedIdentifierVisitor.identifiers;
}