mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Reduce parser plugins used in js-analyze
This makes the parsing 3 -4x faster
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user