diff --git a/scripts/dev-bundle-tool-package.js b/scripts/dev-bundle-tool-package.js index d57634cc0d..60cc8d69fa 100644 --- a/scripts/dev-bundle-tool-package.js +++ b/scripts/dev-bundle-tool-package.js @@ -69,7 +69,7 @@ var packageJson = { "ws": "7.4.5", "open":"8.4.2", "@swc/core": "1.11.11", - "swc-to-babel": "4.0.0", + "acorn": "8.14.1", } }; diff --git a/tools/isobuild/js-analyze.js b/tools/isobuild/js-analyze.js index 35a929c083..9ed7b5fae3 100644 --- a/tools/isobuild/js-analyze.js +++ b/tools/isobuild/js-analyze.js @@ -4,6 +4,7 @@ import LRUCache 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"; +import acorn from 'acorn'; const hasOwn = Object.prototype.hasOwnProperty; const objToStr = Object.prototype.toString @@ -15,7 +16,7 @@ function isRegExp(value) { var AST_CACHE = new LRUCache({ max: Math.pow(2, 12), length(ast) { - return ast.loc.end.line; + return ast.end; } }); @@ -28,20 +29,32 @@ function tryToParse(source, hash) { let ast; try { 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' - ] - }); + try { + ast = acorn.parse(source, { + ecmaVersion: 'latest', + sourceType: 'script', + allowAwaitOutsideFunction: true, + allowImportExportEverywhere: true, + allowReturnOutsideFunction: true, + allowHashBang: true, + checkPrivateFields: false + }); + } catch (error) { + 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') {