From b2ec70494c55389638ba6c78711a9668141e4907 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Wed, 21 Jan 2026 13:45:15 -0500 Subject: [PATCH] build,deps: replace cjs-module-lexer with merve --- LICENSE | 24 +- configure.py | 28 +- deps/cjs-module-lexer/LICENSE | 10 - deps/cjs-module-lexer/README.md | 483 ----- deps/cjs-module-lexer/dist/lexer.js | 1 - deps/cjs-module-lexer/dist/lexer.mjs | 2 - deps/cjs-module-lexer/lexer.js | 1607 -------------- deps/cjs-module-lexer/src/.babelrc | 10 - deps/cjs-module-lexer/src/CHANGELOG.md | 40 - deps/cjs-module-lexer/src/LICENSE | 10 - deps/cjs-module-lexer/src/Makefile | 19 - deps/cjs-module-lexer/src/README.md | 483 ----- deps/cjs-module-lexer/src/build.js | 25 - deps/cjs-module-lexer/src/build/Makefile | 24 - deps/cjs-module-lexer/src/build/wasm.js | 54 - .../src/include-wasm/cjs-module-lexer.h | 238 --- deps/cjs-module-lexer/src/lexer.d.mts | 1 - deps/cjs-module-lexer/src/lexer.d.ts | 8 - deps/cjs-module-lexer/src/lexer.js | 1607 -------------- deps/cjs-module-lexer/src/lib/lexer.wasm | Bin 22164 -> 0 bytes deps/cjs-module-lexer/src/package-lock.json | 1901 ----------------- deps/cjs-module-lexer/src/package.json | 48 - deps/cjs-module-lexer/src/src/lexer.c | 1518 ------------- deps/cjs-module-lexer/src/src/lexer.js | 282 --- deps/merve/LICENSE-MIT | 18 + deps/merve/merve.cpp | 1721 +++++++++++++++ deps/merve/merve.gyp | 35 + deps/merve/merve.h | 166 ++ doc/api/process.md | 2 +- lib/internal/modules/esm/translators.js | 39 +- node.gyp | 1 + node.gypi | 4 + src/cjs_module_lexer_version.h | 6 - src/node_binding.cc | 1 + src/node_builtins.cc | 15 - src/node_cjs_lexer.cc | 107 + src/node_metadata.cc | 4 +- src/node_metadata.h | 2 +- test/parallel/test-process-versions.js | 7 +- tools/dep_updaters/update-cjs-module-lexer.sh | 109 - tools/dep_updaters/update-merve.sh | 65 + tools/license-builder.sh | 4 +- typings/globals.d.ts | 2 + typings/internalBinding/cjs_lexer.d.ts | 5 + 44 files changed, 2175 insertions(+), 8561 deletions(-) delete mode 100644 deps/cjs-module-lexer/LICENSE delete mode 100644 deps/cjs-module-lexer/README.md delete mode 100644 deps/cjs-module-lexer/dist/lexer.js delete mode 100644 deps/cjs-module-lexer/dist/lexer.mjs delete mode 100755 deps/cjs-module-lexer/lexer.js delete mode 100755 deps/cjs-module-lexer/src/.babelrc delete mode 100644 deps/cjs-module-lexer/src/CHANGELOG.md delete mode 100755 deps/cjs-module-lexer/src/LICENSE delete mode 100755 deps/cjs-module-lexer/src/Makefile delete mode 100755 deps/cjs-module-lexer/src/README.md delete mode 100755 deps/cjs-module-lexer/src/build.js delete mode 100755 deps/cjs-module-lexer/src/build/Makefile delete mode 100644 deps/cjs-module-lexer/src/build/wasm.js delete mode 100755 deps/cjs-module-lexer/src/include-wasm/cjs-module-lexer.h delete mode 100644 deps/cjs-module-lexer/src/lexer.d.mts delete mode 100755 deps/cjs-module-lexer/src/lexer.d.ts delete mode 100755 deps/cjs-module-lexer/src/lexer.js delete mode 100755 deps/cjs-module-lexer/src/lib/lexer.wasm delete mode 100644 deps/cjs-module-lexer/src/package-lock.json delete mode 100755 deps/cjs-module-lexer/src/package.json delete mode 100755 deps/cjs-module-lexer/src/src/lexer.c delete mode 100755 deps/cjs-module-lexer/src/src/lexer.js create mode 100644 deps/merve/LICENSE-MIT create mode 100644 deps/merve/merve.cpp create mode 100644 deps/merve/merve.gyp create mode 100644 deps/merve/merve.h delete mode 100644 src/cjs_module_lexer_version.h create mode 100644 src/node_cjs_lexer.cc delete mode 100755 tools/dep_updaters/update-cjs-module-lexer.sh create mode 100644 tools/dep_updaters/update-merve.sh create mode 100644 typings/internalBinding/cjs_lexer.d.ts diff --git a/LICENSE b/LICENSE index df0947155c7e57..86b230b2342d61 100644 --- a/LICENSE +++ b/LICENSE @@ -104,18 +104,26 @@ The externally maintained libraries used by Node.js are: SOFTWARE. """ -- cjs-module-lexer, located at deps/cjs-module-lexer, is licensed as follows: +- commonjs-lexer, located at deps/commonjs-lexer, is licensed as follows: """ - MIT License - ----------- - - Copyright (C) 2018-2020 Guy Bedford + Copyright 2026 Yagiz Nizipli - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: - The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ - ittapi, located at deps/v8/third_party/ittapi, is licensed as follows: diff --git a/configure.py b/configure.py index 4fb061aae7a955..35b87f26ddbee3 100755 --- a/configure.py +++ b/configure.py @@ -58,9 +58,7 @@ maglev_enabled_architectures = ('x64', 'arm', 'arm64', 's390x') # builtins may be removed later if they have been disabled by options -shareable_builtins = {'cjs_module_lexer/lexer': 'deps/cjs-module-lexer/lexer.js', - 'cjs_module_lexer/dist/lexer': 'deps/cjs-module-lexer/dist/lexer.js', - 'undici/undici': 'deps/undici/undici.js', +shareable_builtins = {'undici/undici': 'deps/undici/undici.js', 'amaro/dist/index': 'deps/amaro/dist/index.js' } @@ -556,7 +554,6 @@ dest='shared_simdutf_libpath', help='a directory to search for the shared simdutf DLL') - shared_optgroup.add_argument('--shared-ada', action='store_true', dest='shared_ada', @@ -579,6 +576,28 @@ dest='shared_ada_libpath', help='a directory to search for the shared ada DLL') +shared_optgroup.add_argument('--shared-merve', + action='store_true', + dest='shared_merve', + default=None, + help='link to a shared merve DLL instead of static linking') + +shared_optgroup.add_argument('--shared-merve-includes', + action='store', + dest='shared_merve_includes', + help='directory containing merve header files') + +shared_optgroup.add_argument('--shared-merve-libname', + action='store', + dest='shared_merve_libname', + default='merve', + help='alternative lib name to link to [default: %(default)s]') + +shared_optgroup.add_argument('--shared-merve-libpath', + action='store', + dest='shared_merve_libpath', + help='a directory to search for the shared merve DLL') + shared_optgroup.add_argument('--shared-brotli', action='store_true', dest='shared_brotli', @@ -2482,6 +2501,7 @@ def make_bin_override(): configure_library('cares', output, pkgname='libcares') configure_library('gtest', output) configure_library('hdr_histogram', output) +configure_library('merve', output) configure_library('nbytes', output) configure_library('nghttp2', output, pkgname='libnghttp2') configure_library('nghttp3', output, pkgname='libnghttp3') diff --git a/deps/cjs-module-lexer/LICENSE b/deps/cjs-module-lexer/LICENSE deleted file mode 100644 index 935b357962d08b..00000000000000 --- a/deps/cjs-module-lexer/LICENSE +++ /dev/null @@ -1,10 +0,0 @@ -MIT License ------------ - -Copyright (C) 2018-2020 Guy Bedford - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/deps/cjs-module-lexer/README.md b/deps/cjs-module-lexer/README.md deleted file mode 100644 index addf5edc6b1193..00000000000000 --- a/deps/cjs-module-lexer/README.md +++ /dev/null @@ -1,483 +0,0 @@ -# CJS Module Lexer - -[![Build Status][travis-image]][travis-url] - -A [very fast](#benchmarks) JS CommonJS module syntax lexer used to detect the most likely list of named exports of a CommonJS module. - -Outputs the list of named exports (`exports.name = ...`) and possible module reexports (`module.exports = require('...')`), including the common transpiler variations of these cases. - -Forked from https://github.com/guybedford/es-module-lexer. - -_Comprehensively handles the JS language grammar while remaining small and fast. - ~90ms per MB of JS cold and ~15ms per MB of JS warm, [see benchmarks](#benchmarks) for more info._ - -### Project Status - -This project is used in Node.js core for detecting the named exports available when importing a CJS module into ESM, and is maintained for this purpose. - -PRs will be accepted and upstreamed for parser bugs, performance improvements or new syntax support only. - -_Detection patterns for this project are **frozen**_. This is because adding any new export detection patterns would result in fragmented backwards-compatibility. Specifically, it would be very difficult to figure out why an ES module named export for CommonJS might work in newer Node.js versions but not older versions. This problem would only be discovered downstream of module authors, with the fix for module authors being to then have to understand which patterns in this project provide full backwards-compatibily. Rather, by fully freezing the detected patterns, if it works in any Node.js version it will work in any other. Build tools can also reliably treat the supported syntax for this project as a part of their output target for ensuring syntax support. - -### Usage - -``` -npm install cjs-module-lexer -``` - -For use in CommonJS: - -```js -const { parse } = require('cjs-module-lexer'); - -// `init` return a promise for parity with the ESM API, but you do not have to call it - -const { exports, reexports } = parse(` - // named exports detection - module.exports.a = 'a'; - (function () { - exports.b = 'b'; - })(); - Object.defineProperty(exports, 'c', { value: 'c' }); - /* exports.d = 'not detected'; */ - - // reexports detection - if (maybe) module.exports = require('./dep1.js'); - if (another) module.exports = require('./dep2.js'); - - // literal exports assignments - module.exports = { a, b: c, d, 'e': f } - - // __esModule detection - Object.defineProperty(module.exports, '__esModule', { value: true }) -`); - -// exports === ['a', 'b', 'c', '__esModule'] -// reexports === ['./dep1.js', './dep2.js'] -``` - -When using the ESM version, Wasm is supported instead: - -```js -import { parse, init } from 'cjs-module-lexer'; -// init() needs to be called and waited upon, or use initSync() to compile -// Wasm blockingly and synchronously. -await init(); -const { exports, reexports } = parse(source); -``` - -The Wasm build is around 1.5x faster and without a cold start. - -### Grammar - -CommonJS exports matches are run against the source token stream. - -The token grammar is: - -``` -IDENTIFIER: As defined by ECMA-262, without support for identifier `\` escapes, filtered to remove strict reserved words: - "implements", "interface", "let", "package", "private", "protected", "public", "static", "yield", "enum" - -STRING_LITERAL: A `"` or `'` bounded ECMA-262 string literal. - -MODULE_EXPORTS: `module` `.` `exports` - -EXPORTS_IDENTIFIER: MODULE_EXPORTS_IDENTIFIER | `exports` - -EXPORTS_DOT_ASSIGN: EXPORTS_IDENTIFIER `.` IDENTIFIER `=` - -EXPORTS_LITERAL_COMPUTED_ASSIGN: EXPORTS_IDENTIFIER `[` STRING_LITERAL `]` `=` - -EXPORTS_LITERAL_PROP: (IDENTIFIER (`:` IDENTIFIER)?) | (STRING_LITERAL `:` IDENTIFIER) - -EXPORTS_SPREAD: `...` (IDENTIFIER | REQUIRE) - -EXPORTS_MEMBER: EXPORTS_DOT_ASSIGN | EXPORTS_LITERAL_COMPUTED_ASSIGN - -EXPORTS_DEFINE: `Object` `.` `defineProperty `(` EXPORTS_IDENFITIER `,` STRING_LITERAL - -EXPORTS_DEFINE_VALUE: EXPORTS_DEFINE `, {` - (`enumerable: true,`)? - ( - `value:` | - `get` (`: function` IDENTIFIER? )? `() {` return IDENTIFIER (`.` IDENTIFIER | `[` STRING_LITERAL `]`)? `;`? `}` `,`? - ) - `})` - -EXPORTS_LITERAL: MODULE_EXPORTS `=` `{` (EXPORTS_LITERAL_PROP | EXPORTS_SPREAD) `,`)+ `}` - -REQUIRE: `require` `(` STRING_LITERAL `)` - -EXPORTS_ASSIGN: (`var` | `const` | `let`) IDENTIFIER `=` (`_interopRequireWildcard (`)? REQUIRE - -MODULE_EXPORTS_ASSIGN: MODULE_EXPORTS `=` REQUIRE - -EXPORT_STAR: (`__export` | `__exportStar`) `(` REQUIRE - -EXPORT_STAR_LIB: `Object.keys(` IDENTIFIER$1 `).forEach(function (` IDENTIFIER$2 `) {` - ( - ( - `if (` IDENTIFIER$2 `===` ( `'default'` | `"default"` ) `||` IDENTIFIER$2 `===` ( '__esModule' | `"__esModule"` ) `) return` `;`? - ( - (`if (Object` `.prototype`? `.hasOwnProperty.call(` IDENTIFIER `, ` IDENTIFIER$2 `)) return` `;`?)? - (`if (` IDENTIFIER$2 `in` EXPORTS_IDENTIFIER `&&` EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] ===` IDENTIFIER$1 `[` IDENTIFIER$2 `]) return` `;`)? - )? - ) | - `if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) (`&& !` (`Object` `.prototype`? `.hasOwnProperty.call(` IDENTIFIER `, ` IDENTIFIER$2 `)` | IDENTIFIER `.hasOwnProperty(` IDENTIFIER$2 `)`))? `)` - ) - ( - EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] =` IDENTIFIER$1 `[` IDENTIFIER$2 `]` `;`? | - `Object.defineProperty(` EXPORTS_IDENTIFIER `, ` IDENTIFIER$2 `, { enumerable: true, get` (`: function` IDENTIFIER? )? `() { return ` IDENTIFIER$1 `[` IDENTIFIER$2 `]` `;`? `}` `,`? `})` `;`? - ) - `})` -``` - -Spacing between tokens is taken to be any ECMA-262 whitespace, ECMA-262 block comment or ECMA-262 line comment. - -* The returned export names are taken to be the combination of: - 1. All `IDENTIFIER` and `STRING_LITERAL` slots for `EXPORTS_MEMBER` and `EXPORTS_LITERAL` matches. - 2. The first `STRING_LITERAL` slot for all `EXPORTS_DEFINE_VALUE` matches where that same string is not an `EXPORTS_DEFINE` match that is not also an `EXPORTS_DEFINE_VALUE` match. -* The reexport specifiers are taken to be the combination of: - 1. The `REQUIRE` matches of the last matched of either `MODULE_EXPORTS_ASSIGN` or `EXPORTS_LITERAL`. - 2. All _top-level_ `EXPORT_STAR` `REQUIRE` matches and `EXPORTS_ASSIGN` matches whose `IDENTIFIER` also matches the first `IDENTIFIER` in `EXPORT_STAR_LIB`. - -### Parsing Examples - -#### Named Exports Parsing - -The basic matching rules for named exports are `exports.name`, `exports['name']` or `Object.defineProperty(exports, 'name', ...)`. This matching is done without scope analysis and regardless of the expression position: - -```js -// DETECTS EXPORTS: a, b -(function (exports) { - exports.a = 'a'; - exports['b'] = 'b'; -})(exports); -``` - -Because there is no scope analysis, the above detection may overclassify: - -```js -// DETECTS EXPORTS: a, b, c -(function (exports, Object) { - exports.a = 'a'; - exports['b'] = 'b'; - if (false) - exports.c = 'c'; -})(NOT_EXPORTS, NOT_OBJECT); -``` - -It will in turn underclassify in cases where the identifiers are renamed: - -```js -// DETECTS: NO EXPORTS -(function (e) { - e.a = 'a'; - e['b'] = 'b'; -})(exports); -``` - -#### Getter Exports Parsing - -`Object.defineProperty` is detected for specifically value and getter forms returning an identifier or member expression: - -```js -// DETECTS: a, b, c, d, __esModule -Object.defineProperty(exports, 'a', { - enumerable: true, - get: function () { - return q.p; - } -}); -Object.defineProperty(exports, 'b', { - enumerable: true, - get: function () { - return q['p']; - } -}); -Object.defineProperty(exports, 'c', { - enumerable: true, - get () { - return b; - } -}); -Object.defineProperty(exports, 'd', { value: 'd' }); -Object.defineProperty(exports, '__esModule', { value: true }); -``` - -Value properties are also detected specifically: - -```js -Object.defineProperty(exports, 'a', { - value: 'no problem' -}); -``` - -To avoid matching getters that have side effects, any getter for an export name that does not support the forms above will -opt-out of the getter matching: - -```js -// DETECTS: NO EXPORTS -Object.defineProperty(exports, 'a', { - get () { - return 'nope'; - } -}); - -if (false) { - Object.defineProperty(module.exports, 'a', { - get () { - return dynamic(); - } - }) -} -``` - -Alternative object definition structures or getter function bodies are not detected: - -```js -// DETECTS: NO EXPORTS -Object.defineProperty(exports, 'a', { - enumerable: false, - get () { - return p; - } -}); -Object.defineProperty(exports, 'b', { - configurable: true, - get () { - return p; - } -}); -Object.defineProperty(exports, 'c', { - get: () => p -}); -Object.defineProperty(exports, 'd', { - enumerable: true, - get: function () { - return dynamic(); - } -}); -Object.defineProperty(exports, 'e', { - enumerable: true, - get () { - return 'str'; - } -}); -``` - -`Object.defineProperties` is also not supported. - -#### Exports Object Assignment - -A best-effort is made to detect `module.exports` object assignments, but because this is not a full parser, arbitrary expressions are not handled in the -object parsing process. - -Simple object definitions are supported: - -```js -// DETECTS EXPORTS: a, b, c -module.exports = { - a, - 'b': b, - c: c, - ...d -}; -``` - -Object properties that are not identifiers or string expressions will bail out of the object detection, while spreads are ignored: - -```js -// DETECTS EXPORTS: a, b -module.exports = { - a, - ...d, - b: require('c'), - c: "not detected since require('c') above bails the object detection" -} -``` - -`Object.defineProperties` is not currently supported either. - -#### module.exports reexport assignment - -Any `module.exports = require('mod')` assignment is detected as a reexport, but only the last one is returned: - -```js -// DETECTS REEXPORTS: c -module.exports = require('a'); -(module => module.exports = require('b'))(NOT_MODULE); -if (false) module.exports = require('c'); -``` - -This is to avoid over-classification in Webpack bundles with externals which include `module.exports = require('external')` in their source for every external dependency. - -In exports object assignment, any spread of `require()` are detected as multiple separate reexports: - -```js -// DETECTS REEXPORTS: a, b -module.exports = require('ignored'); -module.exports = { - ...require('a'), - ...require('b') -}; -``` - -#### Transpiler Re-exports - -For named exports, transpiler output works well with the rules described above. - -But for star re-exports, special care is taken to support common patterns of transpiler outputs from Babel and TypeScript as well as bundlers like RollupJS. -These reexport and star reexport patterns are restricted to only be detected at the top-level as provided by the direct output of these tools. - -For example, `export * from 'external'` is output by Babel as: - -```js -"use strict"; - -exports.__esModule = true; - -var _external = require("external"); - -Object.keys(_external).forEach(function (key) { - if (key === "default" || key === "__esModule") return; - exports[key] = _external[key]; -}); -``` - -Where the `var _external = require("external")` is specifically detected as well as the `Object.keys(_external)` statement, down to the exact -for of that entire expression including minor variations of the output. The `_external` and `key` identifiers are carefully matched in this -detection. - -Similarly for TypeScript, `export * from 'external'` is output as: - -```js -"use strict"; -function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; -} -Object.defineProperty(exports, "__esModule", { value: true }); -__export(require("external")); -``` - -Where the `__export(require("external"))` statement is explicitly detected as a reexport, including variations `tslib.__export` and `__exportStar`. - -### Environment Support - -Node.js 10+, and [all browsers with Web Assembly support](https://caniuse.com/#feat=wasm). - -### JS Grammar Support - -* Token state parses all line comments, block comments, strings, template strings, blocks, parens and punctuators. -* Division operator / regex token ambiguity is handled via backtracking checks against punctuator prefixes, including closing brace or paren backtracking. -* Always correctly parses valid JS source, but may parse invalid JS source without errors. - -### Benchmarks - -Benchmarks can be run with `npm run bench`. - -Current results: - -JS Build: - -``` -Module load time -> 4ms -Cold Run, All Samples -test/samples/*.js (3635 KiB) -> 299ms - -Warm Runs (average of 25 runs) -test/samples/angular.js (1410 KiB) -> 13.96ms -test/samples/angular.min.js (303 KiB) -> 4.72ms -test/samples/d3.js (553 KiB) -> 6.76ms -test/samples/d3.min.js (250 KiB) -> 4ms -test/samples/magic-string.js (34 KiB) -> 0.64ms -test/samples/magic-string.min.js (20 KiB) -> 0ms -test/samples/rollup.js (698 KiB) -> 8.48ms -test/samples/rollup.min.js (367 KiB) -> 5.36ms - -Warm Runs, All Samples (average of 25 runs) -test/samples/*.js (3635 KiB) -> 40.28ms -``` - -Wasm Build: -``` -Module load time -> 10ms -Cold Run, All Samples -test/samples/*.js (3635 KiB) -> 43ms - -Warm Runs (average of 25 runs) -test/samples/angular.js (1410 KiB) -> 9.32ms -test/samples/angular.min.js (303 KiB) -> 3.16ms -test/samples/d3.js (553 KiB) -> 5ms -test/samples/d3.min.js (250 KiB) -> 2.32ms -test/samples/magic-string.js (34 KiB) -> 0.16ms -test/samples/magic-string.min.js (20 KiB) -> 0ms -test/samples/rollup.js (698 KiB) -> 6.28ms -test/samples/rollup.min.js (367 KiB) -> 3.6ms - -Warm Runs, All Samples (average of 25 runs) -test/samples/*.js (3635 KiB) -> 27.76ms -``` - -### Wasm Build Steps - -The build uses docker and make, they must be installed first. - -To build the lexer wasm run `npm run build-wasm`. - -Optimization passes are run with [Binaryen](https://github.com/WebAssembly/binaryen) -prior to publish to reduce the Web Assembly footprint. - -After building the lexer wasm, build the final distribution components -(lexer.js and lexer.mjs) by running `npm run build`. - -If you need to build lib/lexer.wat (optional) you must first install -[wabt](https://github.com/WebAssembly/wabt) as a sibling folder to this -project. The wat file is then build by running `make lib/lexer.wat` - -### Creating a Release -These are the steps to create and publish a release. You will need docker -installed as well as having installed [wabt](https://github.com/WebAssembly/wabt) -as outlined above: - -- [ ] Figure out if the release should be semver patch, minor or major based on the changes since - the last release and determine the new version. -- [ ] Update the package.json version, and run a full build and test - - npm install - - npm run build - - npm run test -- [ ] Commit and tag the changes, pushing up to main and the tag - - For example - - `git tag -a 1.4.2 -m "1.4.2"` - - `git push origin tag 1.4.2` -- [ ] Create the GitHub release -- [ ] Run npm publish from an account with access (asking somebody with access - the nodejs-foundation account is an option if you don't have access. - -### License - -MIT - -[travis-url]: https://travis-ci.org/guybedford/es-module-lexer -[travis-image]: https://travis-ci.org/guybedford/es-module-lexer.svg?branch=master diff --git a/deps/cjs-module-lexer/dist/lexer.js b/deps/cjs-module-lexer/dist/lexer.js deleted file mode 100644 index e1a05b5b260684..00000000000000 --- a/deps/cjs-module-lexer/dist/lexer.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";exports.init=init;exports.initSync=initSync;exports.parse=parse;let A;const B=1===new Uint8Array(new Uint16Array([1]).buffer)[0];function parse(E,g="@"){if(!A)throw new Error("Not initialized");const w=E.length+1,D=(A.__heap_base.value||A.__heap_base)+4*w-A.memory.buffer.byteLength;D>0&&A.memory.grow(Math.ceil(D/65536));const G=A.sa(w);(B?C:I)(E,new Uint16Array(A.memory.buffer,G,w));const S=A.parseCJS(G,E.length,0,0,0);if(S){const B=new Error(`Parse error ${g}${A.e()}:${E.slice(0,A.e()).split("\n").length}:${A.e()-E.lastIndexOf("\n",A.e()-1)}`);throw Object.assign(B,{idx:A.e()}),5!==S&&6!==S&&7!==S||Object.assign(B,{code:"ERR_LEXER_ESM_SYNTAX"}),B}let o=new Set,R=new Set,y=new Set;for(;A.rre();){const B=Q(E.slice(A.res(),A.ree()));B&&R.add(B)}for(;A.ru();)y.add(Q(E.slice(A.us(),A.ue())));for(;A.re();){let B=Q(E.slice(A.es(),A.ee()));void 0===B||y.has(B)||o.add(B)}return{exports:[...o],reexports:[...R]}}function Q(A){if('"'!==A[0]&&"'"!==A[0])return A;try{const B=function(A){const B=A[0];if('"'===B)try{return JSON.parse(A)}catch{}else if("'"===B&&A.length>1&&"'"===A[A.length-1]&&-1===A.indexOf('"'))try{return JSON.parse('"'+A.slice(1,-1)+'"')}catch{}let Q="",g={v:1};for(;g.v1114111)throw new SyntaxError;++B.v}while("}"!==A[B.v]);++B.v}else for(let E=0;E<4;++E)Q=16*Q+g(A[B.v]),++B.v;return String.fromCodePoint(Q)}(A,B);case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":return function(A,B,Q){let E=A<="3"?2:1,g=+A;do{if((A=B[Q.v])<"0"||A>"7")break;g=8*g+ +A,++Q.v,--E}while(E>0);return String.fromCodePoint(g)}(Q,A,B);default:return Q}}function g(A){if(A>="0"&&A<="9")return+A;if(A>="a"&&A<="f")return A.charCodeAt(0)-87;if(A>="A"&&A<="F")return A.charCodeAt(0)-55;throw new SyntaxError}function I(A,B){const Q=A.length;let E=0;for(;E>>8}}function C(A,B){const Q=A.length;let E=0;for(;EA.charCodeAt(0))}let D;function init(){return D||(D=(async()=>{const B=await WebAssembly.compile(w()),{exports:Q}=await WebAssembly.instantiate(B);A=Q})())}function initSync(){if(A)return;const B=new WebAssembly.Module(w()),{exports:Q}=new WebAssembly.Instance(B);A=Q} \ No newline at end of file diff --git a/deps/cjs-module-lexer/dist/lexer.mjs b/deps/cjs-module-lexer/dist/lexer.mjs deleted file mode 100644 index 44a2f3eb0d1c35..00000000000000 --- a/deps/cjs-module-lexer/dist/lexer.mjs +++ /dev/null @@ -1,2 +0,0 @@ -/* cjs-module-lexer 2.2.0 */ -let A;const B=1===new Uint8Array(new Uint16Array([1]).buffer)[0];export function parse(E,g="@"){if(!A)throw new Error("Not initialized");const w=E.length+1,D=(A.__heap_base.value||A.__heap_base)+4*w-A.memory.buffer.byteLength;D>0&&A.memory.grow(Math.ceil(D/65536));const G=A.sa(w);(B?C:I)(E,new Uint16Array(A.memory.buffer,G,w));const S=A.parseCJS(G,E.length,0,0,0);if(S){const B=new Error(`Parse error ${g}${A.e()}:${E.slice(0,A.e()).split("\n").length}:${A.e()-E.lastIndexOf("\n",A.e()-1)}`);throw Object.assign(B,{idx:A.e()}),5!==S&&6!==S&&7!==S||Object.assign(B,{code:"ERR_LEXER_ESM_SYNTAX"}),B}let o=new Set,R=new Set,y=new Set;for(;A.rre();){const B=Q(E.slice(A.res(),A.ree()));B&&R.add(B)}for(;A.ru();)y.add(Q(E.slice(A.us(),A.ue())));for(;A.re();){let B=Q(E.slice(A.es(),A.ee()));void 0===B||y.has(B)||o.add(B)}return{exports:[...o],reexports:[...R]}}function Q(A){if('"'!==A[0]&&"'"!==A[0])return A;try{const B=function(A){const B=A[0];if('"'===B)try{return JSON.parse(A)}catch{}else if("'"===B&&A.length>1&&"'"===A[A.length-1]&&-1===A.indexOf('"'))try{return JSON.parse('"'+A.slice(1,-1)+'"')}catch{}let Q="",g={v:1};for(;g.v1114111)throw new SyntaxError;++B.v}while("}"!==A[B.v]);++B.v}else for(let E=0;E<4;++E)Q=16*Q+g(A[B.v]),++B.v;return String.fromCodePoint(Q)}(A,B);case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":return function(A,B,Q){let E=A<="3"?2:1,g=+A;do{if((A=B[Q.v])<"0"||A>"7")break;g=8*g+ +A,++Q.v,--E}while(E>0);return String.fromCodePoint(g)}(Q,A,B);default:return Q}}function g(A){if(A>="0"&&A<="9")return+A;if(A>="a"&&A<="f")return A.charCodeAt(0)-87;if(A>="A"&&A<="F")return A.charCodeAt(0)-55;throw new SyntaxError}function I(A,B){const Q=A.length;let E=0;for(;E>>8}}function C(A,B){const Q=A.length;let E=0;for(;EA.charCodeAt(0))}let D;export function init(){return D||(D=(async()=>{const B=await WebAssembly.compile(w()),{exports:Q}=await WebAssembly.instantiate(B);A=Q})())}export function initSync(){if(A)return;const B=new WebAssembly.Module(w()),{exports:Q}=new WebAssembly.Instance(B);A=Q} \ No newline at end of file diff --git a/deps/cjs-module-lexer/lexer.js b/deps/cjs-module-lexer/lexer.js deleted file mode 100755 index 1614fd9e62d88f..00000000000000 --- a/deps/cjs-module-lexer/lexer.js +++ /dev/null @@ -1,1607 +0,0 @@ -let source, pos, end; -let openTokenDepth, - templateDepth, - lastTokenPos, - lastSlashWasDivision, - templateStack, - templateStackDepth, - openTokenPosStack, - openClassPosStack, - nextBraceIsClass, - starExportMap, - lastStarExportSpecifier, - _exports, - unsafeGetters, - reexports; - -function resetState () { - openTokenDepth = 0; - templateDepth = -1; - lastTokenPos = -1; - lastSlashWasDivision = false; - templateStack = new Array(1024); - templateStackDepth = 0; - openTokenPosStack = new Array(1024); - openClassPosStack = new Array(1024); - nextBraceIsClass = false; - starExportMap = Object.create(null); - lastStarExportSpecifier = null; - - _exports = new Set(); - unsafeGetters = new Set(); - reexports = new Set(); -} - -// RequireType -const Import = 0; -const ExportAssign = 1; -const ExportStar = 2; - -function parseCJS (source, name = '@') { - resetState(); - try { - parseSource(source); - } - catch (e) { - e.message += `\n at ${name}:${source.slice(0, pos).split('\n').length}:${pos - source.lastIndexOf('\n', pos - 1)}`; - e.loc = pos; - throw e; - } - const result = { exports: [..._exports].filter(expt => expt !== undefined && !unsafeGetters.has(expt)), reexports: [...reexports].filter(reexpt => reexpt !== undefined) }; - resetState(); - return result; -} - -function decode (str) { - if (str[0] === '"' || str[0] === '\'') { - try { - const decoded = scanStringLiteral(str); - // Filter to exclude non-matching UTF-16 surrogate strings - for (let i = 0; i < decoded.length; i++) { - const surrogatePrefix = decoded.charCodeAt(i) & 0xFC00; - if (surrogatePrefix < 0xD800) { - // Not a surrogate - continue; - } - else if (surrogatePrefix === 0xD800) { - // Validate surrogate pair - if ((decoded.charCodeAt(++i) & 0xFC00) !== 0xDC00) - return; - } - else { - // Out-of-range surrogate code (above 0xD800) - return; - } - } - return decoded; - } - catch {} - } - else { - return str; - } -} - -function parseSource (cjsSource) { - source = cjsSource; - pos = -1; - end = source.length - 1; - let ch = 0; - - // Handle #! - if (source.charCodeAt(0) === 35/*#*/ && source.charCodeAt(1) === 33/*!*/) { - if (source.length === 2) - return true; - pos += 2; - while (pos++ < end) { - ch = source.charCodeAt(pos); - if (ch === 10/*\n*/ || ch === 13/*\r*/) - break; - } - } - - while (pos++ < end) { - ch = source.charCodeAt(pos); - - if (ch === 32 || ch < 14 && ch > 8) - continue; - - if (openTokenDepth === 0) { - switch (ch) { - case 105/*i*/: - if (source.startsWith('mport', pos + 1) && keywordStart(pos)) - throwIfImportStatement(); - lastTokenPos = pos; - continue; - case 114/*r*/: - const startPos = pos; - if (tryParseRequire(Import) && keywordStart(startPos)) - tryBacktrackAddStarExportBinding(startPos - 1); - lastTokenPos = pos; - continue; - case 95/*_*/: - if (source.startsWith('interopRequireWildcard', pos + 1) && (keywordStart(pos) || source.charCodeAt(pos - 1) === 46/*.*/)) { - const startPos = pos; - pos += 23; - if (source.charCodeAt(pos) === 40/*(*/) { - pos++; - openTokenPosStack[openTokenDepth++] = lastTokenPos; - if (tryParseRequire(Import) && keywordStart(startPos)) { - tryBacktrackAddStarExportBinding(startPos - 1); - } - } - } - else if (source.startsWith('_export', pos + 1) && (keywordStart(pos) || source.charCodeAt(pos - 1) === 46/*.*/)) { - pos += 8; - if (source.startsWith('Star', pos)) - pos += 4; - if (source.charCodeAt(pos) === 40/*(*/) { - openTokenPosStack[openTokenDepth++] = lastTokenPos; - if (source.charCodeAt(pos + 1) === 114/*r*/) { - pos++; - tryParseRequire(ExportStar); - } - } - } - lastTokenPos = pos; - continue; - } - } - - switch (ch) { - case 101/*e*/: - if (source.startsWith('xport', pos + 1) && keywordStart(pos)) { - if (source.charCodeAt(pos + 6) === 115/*s*/) - tryParseExportsDotAssign(false); - else if (openTokenDepth === 0) - throwIfExportStatement(); - } - break; - case 99/*c*/: - if (keywordStart(pos) && source.startsWith('lass', pos + 1) && isBrOrWs(source.charCodeAt(pos + 5))) - nextBraceIsClass = true; - break; - case 109/*m*/: - if (source.startsWith('odule', pos + 1) && keywordStart(pos)) - tryParseModuleExportsDotAssign(); - break; - case 79/*O*/: - if (source.startsWith('bject', pos + 1) && keywordStart(pos)) - tryParseObjectDefineOrKeys(openTokenDepth === 0); - break; - case 40/*(*/: - openTokenPosStack[openTokenDepth++] = lastTokenPos; - break; - case 41/*)*/: - if (openTokenDepth === 0) - throw new Error('Unexpected closing bracket.'); - openTokenDepth--; - break; - case 123/*{*/: - openClassPosStack[openTokenDepth] = nextBraceIsClass; - nextBraceIsClass = false; - openTokenPosStack[openTokenDepth++] = lastTokenPos; - break; - case 125/*}*/: - if (openTokenDepth === 0) - throw new Error('Unexpected closing brace.'); - if (openTokenDepth-- === templateDepth) { - templateDepth = templateStack[--templateStackDepth]; - templateString(); - } - else { - if (templateDepth !== -1 && openTokenDepth < templateDepth) - throw new Error('Unexpected closing brace.'); - } - break; - case 60/*>*/: - // TODO: