deps: upgrade to cjs-module-lexer@1.0.0
PR-URL: https://github.com/nodejs/node/pull/35928 Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
parent
b600b9a903
commit
a5f99b8d20
7
deps/cjs-module-lexer/CHANGELOG.md
vendored
7
deps/cjs-module-lexer/CHANGELOG.md
vendored
@ -1,3 +1,10 @@
|
|||||||
|
1.0.0
|
||||||
|
- Unsafe getter tracking (https://github.com/guybedford/cjs-module-lexer/pull/29)
|
||||||
|
|
||||||
|
0.6.0
|
||||||
|
- API-only breaking change: Unify JS and Wasm interfaces (https://github.com/guybedford/cjs-module-lexer/pull/27)
|
||||||
|
- Add type definitions (https://github.com/guybedford/cjs-module-lexer/pull/28)
|
||||||
|
|
||||||
0.5.2
|
0.5.2
|
||||||
- Support named getter functions (https://github.com/guybedford/cjs-module-lexer/pull/26)
|
- Support named getter functions (https://github.com/guybedford/cjs-module-lexer/pull/26)
|
||||||
|
|
||||||
|
72
deps/cjs-module-lexer/README.md
vendored
72
deps/cjs-module-lexer/README.md
vendored
@ -19,7 +19,9 @@ npm install cjs-module-lexer
|
|||||||
For use in CommonJS:
|
For use in CommonJS:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const parse = require('cjs-module-lexer');
|
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(`
|
const { exports, reexports } = parse(`
|
||||||
// named exports detection
|
// named exports detection
|
||||||
@ -84,7 +86,9 @@ EXPORTS_SPREAD: `...` (IDENTIFIER | REQUIRE)
|
|||||||
|
|
||||||
EXPORTS_MEMBER: EXPORTS_DOT_ASSIGN | EXPORTS_LITERAL_COMPUTED_ASSIGN
|
EXPORTS_MEMBER: EXPORTS_DOT_ASSIGN | EXPORTS_LITERAL_COMPUTED_ASSIGN
|
||||||
|
|
||||||
EXPORTS_DEFINE: `Object` `.` `defineProperty `(` IDENTIFIER_STRING `, {`
|
EXPORTS_DEFINE: `Object` `.` `defineProperty `(` EXPORTS_IDENFITIER `,` IDENTIFIER_STRING
|
||||||
|
|
||||||
|
EXPORTS_DEFINE_VALUE: EXPORTS_DEFINE `, {`
|
||||||
(`enumerable: true,`)?
|
(`enumerable: true,`)?
|
||||||
(
|
(
|
||||||
`value:` |
|
`value:` |
|
||||||
@ -119,7 +123,9 @@ EXPORT_STAR_LIB: `Object.keys(` IDENTIFIER$1 `).forEach(function (` IDENTIFIER$2
|
|||||||
|
|
||||||
Spacing between tokens is taken to be any ECMA-262 whitespace, ECMA-262 block comment or ECMA-262 line comment.
|
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 the `IDENTIFIER` and `IDENTIFIER_STRING` slots for all `EXPORTS_MEMBER`, `EXPORTS_LITERAL` and `EXPORTS_DEFINE` matches.
|
* The returned export names are taken to be the combination of:
|
||||||
|
1. All `IDENTIFIER` and `IDENTIFIER_STRING` slots for `EXPORTS_MEMBER` and `EXPORTS_LITERAL` matches.
|
||||||
|
2. The first `IDENTIFIER_STRING` 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 the combination of:
|
* The reexport specifiers are taken to be the the combination of:
|
||||||
1. The `REQUIRE` matches of the last matched of either `MODULE_EXPORTS_ASSIGN` or `EXPORTS_LITERAL`.
|
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`.
|
2. All _top-level_ `EXPORT_STAR` `REQUIRE` matches and `EXPORTS_ASSIGN` matches whose `IDENTIFIER` also matches the first `IDENTIFIER` in `EXPORT_STAR_LIB`.
|
||||||
@ -160,6 +166,8 @@ It will in turn underclassify in cases where the identifiers are renamed:
|
|||||||
})(exports);
|
})(exports);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Getter Exports Parsing
|
||||||
|
|
||||||
`Object.defineProperty` is detected for specifically value and getter forms returning an identifier or member expression:
|
`Object.defineProperty` is detected for specifically value and getter forms returning an identifier or member expression:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
@ -186,6 +194,24 @@ Object.defineProperty(exports, 'd', { value: 'd' });
|
|||||||
Object.defineProperty(exports, '__esModule', { value: true });
|
Object.defineProperty(exports, '__esModule', { value: true });
|
||||||
```
|
```
|
||||||
|
|
||||||
|
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', {
|
||||||
|
value: 'no problem'
|
||||||
|
});
|
||||||
|
|
||||||
|
if (false) {
|
||||||
|
Object.defineProperty(module.exports, 'a', {
|
||||||
|
get () {
|
||||||
|
return dynamic();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Alternative object definition structures or getter function bodies are not detected:
|
Alternative object definition structures or getter function bodies are not detected:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
@ -335,63 +361,63 @@ JS Build:
|
|||||||
|
|
||||||
```
|
```
|
||||||
Module load time
|
Module load time
|
||||||
> 5ms
|
> 4ms
|
||||||
Cold Run, All Samples
|
Cold Run, All Samples
|
||||||
test/samples/*.js (3635 KiB)
|
test/samples/*.js (3635 KiB)
|
||||||
> 323ms
|
> 299ms
|
||||||
|
|
||||||
Warm Runs (average of 25 runs)
|
Warm Runs (average of 25 runs)
|
||||||
test/samples/angular.js (1410 KiB)
|
test/samples/angular.js (1410 KiB)
|
||||||
> 14.84ms
|
> 13.96ms
|
||||||
test/samples/angular.min.js (303 KiB)
|
test/samples/angular.min.js (303 KiB)
|
||||||
> 4.8ms
|
> 4.72ms
|
||||||
test/samples/d3.js (553 KiB)
|
test/samples/d3.js (553 KiB)
|
||||||
> 7.84ms
|
> 6.76ms
|
||||||
test/samples/d3.min.js (250 KiB)
|
test/samples/d3.min.js (250 KiB)
|
||||||
> 4ms
|
> 4ms
|
||||||
test/samples/magic-string.js (34 KiB)
|
test/samples/magic-string.js (34 KiB)
|
||||||
> 0.72ms
|
> 0.64ms
|
||||||
test/samples/magic-string.min.js (20 KiB)
|
test/samples/magic-string.min.js (20 KiB)
|
||||||
> 0.4ms
|
> 0ms
|
||||||
test/samples/rollup.js (698 KiB)
|
test/samples/rollup.js (698 KiB)
|
||||||
> 9.32ms
|
> 8.48ms
|
||||||
test/samples/rollup.min.js (367 KiB)
|
test/samples/rollup.min.js (367 KiB)
|
||||||
> 6.52ms
|
> 5.36ms
|
||||||
|
|
||||||
Warm Runs, All Samples (average of 25 runs)
|
Warm Runs, All Samples (average of 25 runs)
|
||||||
test/samples/*.js (3635 KiB)
|
test/samples/*.js (3635 KiB)
|
||||||
> 44ms
|
> 40.28ms
|
||||||
```
|
```
|
||||||
|
|
||||||
Wasm Build:
|
Wasm Build:
|
||||||
```
|
```
|
||||||
Module load time
|
Module load time
|
||||||
> 11ms
|
> 10ms
|
||||||
Cold Run, All Samples
|
Cold Run, All Samples
|
||||||
test/samples/*.js (3635 KiB)
|
test/samples/*.js (3635 KiB)
|
||||||
> 42ms
|
> 43ms
|
||||||
|
|
||||||
Warm Runs (average of 25 runs)
|
Warm Runs (average of 25 runs)
|
||||||
test/samples/angular.js (1410 KiB)
|
test/samples/angular.js (1410 KiB)
|
||||||
> 9.92ms
|
> 9.32ms
|
||||||
test/samples/angular.min.js (303 KiB)
|
test/samples/angular.min.js (303 KiB)
|
||||||
> 3.2ms
|
> 3.16ms
|
||||||
test/samples/d3.js (553 KiB)
|
test/samples/d3.js (553 KiB)
|
||||||
> 5.2ms
|
> 5ms
|
||||||
test/samples/d3.min.js (250 KiB)
|
test/samples/d3.min.js (250 KiB)
|
||||||
> 2.52ms
|
> 2.32ms
|
||||||
test/samples/magic-string.js (34 KiB)
|
test/samples/magic-string.js (34 KiB)
|
||||||
> 0.16ms
|
> 0.16ms
|
||||||
test/samples/magic-string.min.js (20 KiB)
|
test/samples/magic-string.min.js (20 KiB)
|
||||||
> 0.04ms
|
> 0ms
|
||||||
test/samples/rollup.js (698 KiB)
|
test/samples/rollup.js (698 KiB)
|
||||||
> 6.44ms
|
> 6.28ms
|
||||||
test/samples/rollup.min.js (367 KiB)
|
test/samples/rollup.min.js (367 KiB)
|
||||||
> 3.96ms
|
> 3.6ms
|
||||||
|
|
||||||
Warm Runs, All Samples (average of 25 runs)
|
Warm Runs, All Samples (average of 25 runs)
|
||||||
test/samples/*.js (3635 KiB)
|
test/samples/*.js (3635 KiB)
|
||||||
> 30.48ms
|
> 27.76ms
|
||||||
```
|
```
|
||||||
|
|
||||||
### Wasm Build Steps
|
### Wasm Build Steps
|
||||||
|
2
deps/cjs-module-lexer/dist/lexer.js
vendored
2
deps/cjs-module-lexer/dist/lexer.js
vendored
File diff suppressed because one or more lines are too long
4
deps/cjs-module-lexer/dist/lexer.mjs
vendored
4
deps/cjs-module-lexer/dist/lexer.mjs
vendored
File diff suppressed because one or more lines are too long
21
deps/cjs-module-lexer/lexer.js
vendored
21
deps/cjs-module-lexer/lexer.js
vendored
@ -11,6 +11,7 @@ let openTokenDepth,
|
|||||||
starExportMap,
|
starExportMap,
|
||||||
lastStarExportSpecifier,
|
lastStarExportSpecifier,
|
||||||
_exports,
|
_exports,
|
||||||
|
unsafeGetters,
|
||||||
reexports;
|
reexports;
|
||||||
|
|
||||||
function resetState () {
|
function resetState () {
|
||||||
@ -27,6 +28,7 @@ function resetState () {
|
|||||||
lastStarExportSpecifier = null;
|
lastStarExportSpecifier = null;
|
||||||
|
|
||||||
_exports = new Set();
|
_exports = new Set();
|
||||||
|
unsafeGetters = new Set();
|
||||||
reexports = new Set();
|
reexports = new Set();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +39,7 @@ const ExportStar = 2;
|
|||||||
|
|
||||||
const strictReserved = new Set(['implements', 'interface', 'let', 'package', 'private', 'protected', 'public', 'static', 'yield', 'enum']);
|
const strictReserved = new Set(['implements', 'interface', 'let', 'package', 'private', 'protected', 'public', 'static', 'yield', 'enum']);
|
||||||
|
|
||||||
module.exports = function parseCJS (source, name = '@') {
|
function parseCJS (source, name = '@') {
|
||||||
resetState();
|
resetState();
|
||||||
try {
|
try {
|
||||||
parseSource(source);
|
parseSource(source);
|
||||||
@ -47,7 +49,7 @@ module.exports = function parseCJS (source, name = '@') {
|
|||||||
e.loc = pos;
|
e.loc = pos;
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
const result = { exports: [..._exports], reexports: [...reexports] };
|
const result = { exports: [..._exports].filter(expt => !unsafeGetters.has(expt)), reexports: [...reexports] };
|
||||||
resetState();
|
resetState();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -260,6 +262,7 @@ function tryParseObjectDefineOrKeys (keys) {
|
|||||||
pos++;
|
pos++;
|
||||||
ch = commentWhitespace();
|
ch = commentWhitespace();
|
||||||
if (ch === 100/*d*/ && source.startsWith('efineProperty', pos + 1)) {
|
if (ch === 100/*d*/ && source.startsWith('efineProperty', pos + 1)) {
|
||||||
|
let expt;
|
||||||
while (true) {
|
while (true) {
|
||||||
pos += 14;
|
pos += 14;
|
||||||
revertPos = pos - 1;
|
revertPos = pos - 1;
|
||||||
@ -276,7 +279,7 @@ function tryParseObjectDefineOrKeys (keys) {
|
|||||||
let quot = ch;
|
let quot = ch;
|
||||||
const exportPos = ++pos;
|
const exportPos = ++pos;
|
||||||
if (!identifier() || source.charCodeAt(pos) !== quot) break;
|
if (!identifier() || source.charCodeAt(pos) !== quot) break;
|
||||||
const expt = source.slice(exportPos, pos);
|
expt = source.slice(exportPos, pos);
|
||||||
pos++;
|
pos++;
|
||||||
ch = commentWhitespace();
|
ch = commentWhitespace();
|
||||||
if (ch !== 44/*,*/) break;
|
if (ch !== 44/*,*/) break;
|
||||||
@ -304,9 +307,9 @@ function tryParseObjectDefineOrKeys (keys) {
|
|||||||
pos += 5;
|
pos += 5;
|
||||||
ch = commentWhitespace();
|
ch = commentWhitespace();
|
||||||
if (ch !== 58/*:*/) break;
|
if (ch !== 58/*:*/) break;
|
||||||
pos++;
|
|
||||||
addExport(expt);
|
addExport(expt);
|
||||||
break;
|
pos = revertPos;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else if (ch === 103/*g*/) {
|
else if (ch === 103/*g*/) {
|
||||||
if (!source.startsWith('et', pos + 1)) break;
|
if (!source.startsWith('et', pos + 1)) break;
|
||||||
@ -372,6 +375,9 @@ function tryParseObjectDefineOrKeys (keys) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (expt) {
|
||||||
|
unsafeGetters.add(expt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (keys && ch === 107/*k*/ && source.startsWith('eys', pos + 1)) {
|
else if (keys && ch === 107/*k*/ && source.startsWith('eys', pos + 1)) {
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -1320,3 +1326,8 @@ function isExpressionTerminator (curPos) {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const initPromise = Promise.resolve();
|
||||||
|
|
||||||
|
module.exports.init = () => initPromise;
|
||||||
|
module.exports.parse = parseCJS;
|
||||||
|
6
deps/cjs-module-lexer/package.json
vendored
6
deps/cjs-module-lexer/package.json
vendored
@ -1,12 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "cjs-module-lexer",
|
"name": "cjs-module-lexer",
|
||||||
"version": "0.5.2",
|
"version": "1.0.0",
|
||||||
"description": "Lexes CommonJS modules, returning their named exports metadata",
|
"description": "Lexes CommonJS modules, returning their named exports metadata",
|
||||||
"main": "lexer.js",
|
"main": "lexer.js",
|
||||||
"exports": {
|
"exports": {
|
||||||
"import": "./dist/lexer.mjs",
|
"import": "./dist/lexer.mjs",
|
||||||
"default": "./lexer.js"
|
"default": "./lexer.js"
|
||||||
},
|
},
|
||||||
|
"types": "lexer.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test-js": "mocha -b -u tdd test/*.js",
|
"test-js": "mocha -b -u tdd test/*.js",
|
||||||
"test-wasm": "WASM=1 mocha -b -u tdd test/*.js",
|
"test-wasm": "WASM=1 mocha -b -u tdd test/*.js",
|
||||||
@ -28,7 +29,8 @@
|
|||||||
"terser": "^4.1.4"
|
"terser": "^4.1.4"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"dist"
|
"dist",
|
||||||
|
"lexer.d.ts"
|
||||||
],
|
],
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -1287,7 +1287,7 @@ success!
|
|||||||
[`transformSource` hook]: #esm_transformsource_source_context_defaulttransformsource
|
[`transformSource` hook]: #esm_transformsource_source_context_defaulttransformsource
|
||||||
[`string`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
|
[`string`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
|
||||||
[`util.TextDecoder`]: util.md#util_class_util_textdecoder
|
[`util.TextDecoder`]: util.md#util_class_util_textdecoder
|
||||||
[cjs-module-lexer]: https://github.com/guybedford/cjs-module-lexer/tree/0.5.2
|
[cjs-module-lexer]: https://github.com/guybedford/cjs-module-lexer/tree/1.0.0
|
||||||
[special scheme]: https://url.spec.whatwg.org/#special-scheme
|
[special scheme]: https://url.spec.whatwg.org/#special-scheme
|
||||||
[the official standard format]: https://tc39.github.io/ecma262/#sec-modules
|
[the official standard format]: https://tc39.github.io/ecma262/#sec-modules
|
||||||
[transpiler loader example]: #esm_transpiler_loader
|
[transpiler loader example]: #esm_transpiler_loader
|
||||||
|
@ -63,7 +63,7 @@ const { emitWarningSync } = require('internal/process/warning');
|
|||||||
let cjsParse;
|
let cjsParse;
|
||||||
async function initCJSParse() {
|
async function initCJSParse() {
|
||||||
if (typeof WebAssembly === 'undefined') {
|
if (typeof WebAssembly === 'undefined') {
|
||||||
cjsParse = require('internal/deps/cjs-module-lexer/lexer');
|
cjsParse = require('internal/deps/cjs-module-lexer/lexer').parse;
|
||||||
} else {
|
} else {
|
||||||
const { parse, init } =
|
const { parse, init } =
|
||||||
require('internal/deps/cjs-module-lexer/dist/lexer');
|
require('internal/deps/cjs-module-lexer/dist/lexer');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user