deps: update to cjs-module-lexer@0.4.3

PR-URL: https://github.com/nodejs/node/pull/35745
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Ujjwal Sharma <ryzokuken@disroot.org>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
This commit is contained in:
Guy Bedford
2020-10-21 13:35:28 -07:00
parent e6b1d74b8d
commit fdaf9cbfe3
6 changed files with 84 additions and 16 deletions

4
deps/cjs-module-lexer/CHANGELOG.md vendored Normal file
View File

@@ -0,0 +1,4 @@
0.4.3
- Support for Babel 7.12 reexports (https://github.com/guybedford/cjs-module-lexer/pull/16)
- Support module.exports = { ...require('x') } reexports (https://github.com/guybedford/cjs-module-lexer/pull/18)
- "if" keyword space parsing in exports matching (https://github.com/guybedford/cjs-module-lexer/pull/17)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -10,7 +10,6 @@ let openTokenDepth,
nextBraceIsClass,
starExportMap,
lastStarExportSpecifier,
lastExportsAssignSpecifier,
_exports,
reexports;
@@ -26,7 +25,6 @@ function resetState () {
nextBraceIsClass = false;
starExportMap = Object.create(null);
lastStarExportSpecifier = null;
lastExportsAssignSpecifier = null;
_exports = new Set();
reexports = new Set();
@@ -49,8 +47,6 @@ module.exports = function parseCJS (source, name = '@') {
e.loc = pos;
throw e;
}
if (lastExportsAssignSpecifier)
reexports.add(lastExportsAssignSpecifier);
const result = { exports: [..._exports], reexports: [...reexports] };
resetState();
return result;
@@ -330,8 +326,8 @@ function tryParseObjectDefineOrKeys (keys) {
if (ch !== 123/*{*/) break;
pos++;
ch = commentWhitespace();
if (ch !== 105/*i*/ || !source.startsWith('f ', pos + 1)) break;
pos += 3;
if (ch !== 105/*i*/ || source.charCodeAt(pos + 1) !== 102/*f*/) break;
pos += 2;
ch = commentWhitespace();
if (ch !== 40/*(*/) break;
pos++;
@@ -398,6 +394,61 @@ function tryParseObjectDefineOrKeys (keys) {
}
else break;
// `if (` IDENTIFIER$2 `in` EXPORTS_IDENTIFIER `&&` EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] ===` IDENTIFIER$1 `[` IDENTIFIER$2 `]) return` `;`?
if (ch === 105/*i*/ && source.charCodeAt(pos + 1) === 102/*f*/) {
pos += 2;
ch = commentWhitespace();
if (ch !== 40/*(*/) break;
pos++;
ch = commentWhitespace();
if (!source.startsWith(it_id, pos)) break;
pos += it_id.length;
ch = commentWhitespace();
if (ch !== 105/*i*/ || !source.startsWith('n ', pos + 1)) break;
pos += 3;
ch = commentWhitespace();
if (!readExportsOrModuleDotExports(ch)) break;
ch = commentWhitespace();
if (ch !== 38/*&*/ || source.charCodeAt(pos + 1) !== 38/*&*/) break;
pos += 2;
ch = commentWhitespace();
if (!readExportsOrModuleDotExports(ch)) break;
ch = commentWhitespace();
if (ch !== 91/*[*/) break;
pos++;
ch = commentWhitespace();
if (!source.startsWith(it_id, pos)) break;
pos += it_id.length;
ch = commentWhitespace();
if (ch !== 93/*]*/) break;
pos++;
ch = commentWhitespace();
if (ch !== 61/*=*/ || !source.startsWith('==', pos + 1)) break;
pos += 3;
ch = commentWhitespace();
if (!source.startsWith(id, pos)) break;
pos += id.length;
ch = commentWhitespace();
if (ch !== 91/*[*/) break;
pos++;
ch = commentWhitespace();
if (!source.startsWith(it_id, pos)) break;
pos += it_id.length;
ch = commentWhitespace();
if (ch !== 93/*]*/) break;
pos++;
ch = commentWhitespace();
if (ch !== 41/*)*/) break;
pos++;
ch = commentWhitespace();
if (ch !== 114/*r*/ || !source.startsWith('eturn', pos + 1)) break;
pos += 6;
ch = commentWhitespace();
if (ch === 59/*;*/)
pos++;
ch = commentWhitespace();
}
// EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] =` IDENTIFIER$1 `[` IDENTIFIER$2 `]`
if (readExportsOrModuleDotExports(ch)) {
ch = commentWhitespace();
@@ -622,6 +673,8 @@ function tryParseExportsDotAssign (assign) {
// module.exports =
case 61/*=*/: {
if (assign) {
if (reexports.size)
reexports = new Set();
pos++;
ch = commentWhitespace();
// { ... }
@@ -641,9 +694,9 @@ function tryParseExportsDotAssign (assign) {
function tryParseRequire (requireType) {
// require('...')
const revertPos = pos;
if (source.startsWith('equire', pos + 1)) {
pos += 7;
const revertPos = pos - 1;
let ch = commentWhitespace();
if (ch === 40/*(*/) {
pos++;
@@ -656,7 +709,7 @@ function tryParseRequire (requireType) {
if (ch === 41/*)*/) {
switch (requireType) {
case ExportAssign:
lastExportsAssignSpecifier = source.slice(reexportStart, reexportEnd);
reexports.add(source.slice(reexportStart, reexportEnd));
return true;
case ExportStar:
reexports.add(source.slice(reexportStart, reexportEnd));
@@ -674,7 +727,7 @@ function tryParseRequire (requireType) {
if (ch === 41/*)*/) {
switch (requireType) {
case ExportAssign:
lastExportsAssignSpecifier = source.slice(reexportStart, reexportEnd);
reexports.add(source.slice(reexportStart, reexportEnd));
return true;
case ExportStar:
reexports.add(source.slice(reexportStart, reexportEnd));
@@ -711,6 +764,17 @@ function tryParseLiteralExports () {
}
addExport(source.slice(startPos, endPos));
}
else if (ch === 46/*.*/ && source.startsWith('..', pos + 1)) {
pos += 3;
if (source.charCodeAt(pos) === 114/*r*/ && tryParseRequire(ExportAssign)) {
pos++;
}
else if (!identifier()) {
pos = revertPos;
return;
}
ch = commentWhitespace();
}
else if (ch === 39/*'*/ || ch === 34/*"*/) {
const startPos = ++pos;
if (identifier() && source.charCodeAt(pos) === ch) {

View File

@@ -1,6 +1,6 @@
{
"name": "cjs-module-lexer",
"version": "0.4.2",
"version": "0.4.3",
"description": "Lexes CommonJS modules, returning their named exports metadata",
"main": "lexer.js",
"exports": {
@@ -14,8 +14,8 @@
"bench": "node --expose-gc bench/index.mjs",
"build": "node build.js && babel dist/lexer.mjs | terser -o dist/lexer.js",
"build-wasm": "make lib/lexer.wasm && node build.js",
"prepublishOnly": "make optimize && npm run build",
"footprint": "make optimize && npm run build && cat dist/lexer.js | gzip -9f | wc -c"
"prepublishOnly": "make && npm run build",
"footprint": "npm run build && cat dist/lexer.js | gzip -9f | wc -c"
},
"author": "Guy Bedford",
"license": "MIT",

View File

@@ -1287,7 +1287,7 @@ success!
[`transformSource` hook]: #esm_transformsource_source_context_defaulttransformsource
[`string`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
[`util.TextDecoder`]: util.md#util_class_util_textdecoder
[cjs-module-lexer]: https://github.com/guybedford/cjs-module-lexer/tree/0.4.2
[cjs-module-lexer]: https://github.com/guybedford/cjs-module-lexer/tree/0.4.3
[special scheme]: https://url.spec.whatwg.org/#special-scheme
[the official standard format]: https://tc39.github.io/ecma262/#sec-modules
[transpiler loader example]: #esm_transpiler_loader