From e3e50ddaadaedfe344184d8dfd4ab59ec6623f3e Mon Sep 17 00:00:00 2001 From: zodern Date: Mon, 26 Jun 2023 18:15:35 -0500 Subject: [PATCH] Reduce parser plugins used in js-analyze This makes the parsing 3 -4x faster --- tools/isobuild/js-analyze.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/tools/isobuild/js-analyze.js b/tools/isobuild/js-analyze.js index 24bda2b580..5f2bf258b0 100644 --- a/tools/isobuild/js-analyze.js +++ b/tools/isobuild/js-analyze.js @@ -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; }