Skip to content

Commit

Permalink
deps: update to [email protected]
Browse files Browse the repository at this point in the history
PR-URL: #35745
Reviewed-By: Jan Krems <[email protected]>
Reviewed-By: Myles Borins <[email protected]>
Reviewed-By: Ujjwal Sharma <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
  • Loading branch information
guybedford authored and MylesBorins committed Nov 3, 2020
1 parent fecb59f commit 69625bc
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 16 deletions.
4 changes: 4 additions & 0 deletions deps/cjs-module-lexer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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

0 comments on commit 69625bc

Please sign in to comment.