Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: update to cjs-module-lexer@0.4.3 #35745

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions deps/cjs-module-lexer/CHANGELOG.md
@@ -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)
2 changes: 1 addition & 1 deletion deps/cjs-module-lexer/dist/lexer.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions deps/cjs-module-lexer/dist/lexer.mjs

Large diffs are not rendered by default.

82 changes: 73 additions & 9 deletions deps/cjs-module-lexer/lexer.js
Expand Up @@ -10,7 +10,6 @@ let openTokenDepth,
nextBraceIsClass,
starExportMap,
lastStarExportSpecifier,
lastExportsAssignSpecifier,
_exports,
reexports;

Expand All @@ -26,7 +25,6 @@ function resetState () {
nextBraceIsClass = false;
starExportMap = Object.create(null);
lastStarExportSpecifier = null;
lastExportsAssignSpecifier = null;

_exports = new Set();
reexports = new Set();
Expand All @@ -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;
Expand Down Expand Up @@ -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++;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -622,6 +673,8 @@ function tryParseExportsDotAssign (assign) {
// module.exports =
case 61/*=*/: {
if (assign) {
if (reexports.size)
reexports = new Set();
pos++;
ch = commentWhitespace();
// { ... }
Expand All @@ -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++;
Expand All @@ -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));
Expand All @@ -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));
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions deps/cjs-module-lexer/package.json
@@ -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": {
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion doc/api/esm.md
Expand Up @@ -1282,7 +1282,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