Skip to content

Commit e0a1541

Browse files
guybedfordtargos
authored andcommitted
deps: update to [email protected]
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]>
1 parent 6590f8c commit e0a1541

File tree

6 files changed

+84
-16
lines changed

6 files changed

+84
-16
lines changed

deps/cjs-module-lexer/CHANGELOG.md

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

deps/cjs-module-lexer/dist/lexer.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deps/cjs-module-lexer/dist/lexer.mjs

+2-2
Large diffs are not rendered by default.

deps/cjs-module-lexer/lexer.js

+73-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ let openTokenDepth,
1010
nextBraceIsClass,
1111
starExportMap,
1212
lastStarExportSpecifier,
13-
lastExportsAssignSpecifier,
1413
_exports,
1514
reexports;
1615

@@ -26,7 +25,6 @@ function resetState () {
2625
nextBraceIsClass = false;
2726
starExportMap = Object.create(null);
2827
lastStarExportSpecifier = null;
29-
lastExportsAssignSpecifier = null;
3028

3129
_exports = new Set();
3230
reexports = new Set();
@@ -49,8 +47,6 @@ module.exports = function parseCJS (source, name = '@') {
4947
e.loc = pos;
5048
throw e;
5149
}
52-
if (lastExportsAssignSpecifier)
53-
reexports.add(lastExportsAssignSpecifier);
5450
const result = { exports: [..._exports], reexports: [...reexports] };
5551
resetState();
5652
return result;
@@ -330,8 +326,8 @@ function tryParseObjectDefineOrKeys (keys) {
330326
if (ch !== 123/*{*/) break;
331327
pos++;
332328
ch = commentWhitespace();
333-
if (ch !== 105/*i*/ || !source.startsWith('f ', pos + 1)) break;
334-
pos += 3;
329+
if (ch !== 105/*i*/ || source.charCodeAt(pos + 1) !== 102/*f*/) break;
330+
pos += 2;
335331
ch = commentWhitespace();
336332
if (ch !== 40/*(*/) break;
337333
pos++;
@@ -398,6 +394,61 @@ function tryParseObjectDefineOrKeys (keys) {
398394
}
399395
else break;
400396

397+
// `if (` IDENTIFIER$2 `in` EXPORTS_IDENTIFIER `&&` EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] ===` IDENTIFIER$1 `[` IDENTIFIER$2 `]) return` `;`?
398+
if (ch === 105/*i*/ && source.charCodeAt(pos + 1) === 102/*f*/) {
399+
pos += 2;
400+
ch = commentWhitespace();
401+
if (ch !== 40/*(*/) break;
402+
pos++;
403+
ch = commentWhitespace();
404+
if (!source.startsWith(it_id, pos)) break;
405+
pos += it_id.length;
406+
ch = commentWhitespace();
407+
if (ch !== 105/*i*/ || !source.startsWith('n ', pos + 1)) break;
408+
pos += 3;
409+
ch = commentWhitespace();
410+
if (!readExportsOrModuleDotExports(ch)) break;
411+
ch = commentWhitespace();
412+
if (ch !== 38/*&*/ || source.charCodeAt(pos + 1) !== 38/*&*/) break;
413+
pos += 2;
414+
ch = commentWhitespace();
415+
if (!readExportsOrModuleDotExports(ch)) break;
416+
ch = commentWhitespace();
417+
if (ch !== 91/*[*/) break;
418+
pos++;
419+
ch = commentWhitespace();
420+
if (!source.startsWith(it_id, pos)) break;
421+
pos += it_id.length;
422+
ch = commentWhitespace();
423+
if (ch !== 93/*]*/) break;
424+
pos++;
425+
ch = commentWhitespace();
426+
if (ch !== 61/*=*/ || !source.startsWith('==', pos + 1)) break;
427+
pos += 3;
428+
ch = commentWhitespace();
429+
if (!source.startsWith(id, pos)) break;
430+
pos += id.length;
431+
ch = commentWhitespace();
432+
if (ch !== 91/*[*/) break;
433+
pos++;
434+
ch = commentWhitespace();
435+
if (!source.startsWith(it_id, pos)) break;
436+
pos += it_id.length;
437+
ch = commentWhitespace();
438+
if (ch !== 93/*]*/) break;
439+
pos++;
440+
ch = commentWhitespace();
441+
if (ch !== 41/*)*/) break;
442+
pos++;
443+
ch = commentWhitespace();
444+
if (ch !== 114/*r*/ || !source.startsWith('eturn', pos + 1)) break;
445+
pos += 6;
446+
ch = commentWhitespace();
447+
if (ch === 59/*;*/)
448+
pos++;
449+
ch = commentWhitespace();
450+
}
451+
401452
// EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] =` IDENTIFIER$1 `[` IDENTIFIER$2 `]`
402453
if (readExportsOrModuleDotExports(ch)) {
403454
ch = commentWhitespace();
@@ -622,6 +673,8 @@ function tryParseExportsDotAssign (assign) {
622673
// module.exports =
623674
case 61/*=*/: {
624675
if (assign) {
676+
if (reexports.size)
677+
reexports = new Set();
625678
pos++;
626679
ch = commentWhitespace();
627680
// { ... }
@@ -641,9 +694,9 @@ function tryParseExportsDotAssign (assign) {
641694

642695
function tryParseRequire (requireType) {
643696
// require('...')
697+
const revertPos = pos;
644698
if (source.startsWith('equire', pos + 1)) {
645699
pos += 7;
646-
const revertPos = pos - 1;
647700
let ch = commentWhitespace();
648701
if (ch === 40/*(*/) {
649702
pos++;
@@ -656,7 +709,7 @@ function tryParseRequire (requireType) {
656709
if (ch === 41/*)*/) {
657710
switch (requireType) {
658711
case ExportAssign:
659-
lastExportsAssignSpecifier = source.slice(reexportStart, reexportEnd);
712+
reexports.add(source.slice(reexportStart, reexportEnd));
660713
return true;
661714
case ExportStar:
662715
reexports.add(source.slice(reexportStart, reexportEnd));
@@ -674,7 +727,7 @@ function tryParseRequire (requireType) {
674727
if (ch === 41/*)*/) {
675728
switch (requireType) {
676729
case ExportAssign:
677-
lastExportsAssignSpecifier = source.slice(reexportStart, reexportEnd);
730+
reexports.add(source.slice(reexportStart, reexportEnd));
678731
return true;
679732
case ExportStar:
680733
reexports.add(source.slice(reexportStart, reexportEnd));
@@ -711,6 +764,17 @@ function tryParseLiteralExports () {
711764
}
712765
addExport(source.slice(startPos, endPos));
713766
}
767+
else if (ch === 46/*.*/ && source.startsWith('..', pos + 1)) {
768+
pos += 3;
769+
if (source.charCodeAt(pos) === 114/*r*/ && tryParseRequire(ExportAssign)) {
770+
pos++;
771+
}
772+
else if (!identifier()) {
773+
pos = revertPos;
774+
return;
775+
}
776+
ch = commentWhitespace();
777+
}
714778
else if (ch === 39/*'*/ || ch === 34/*"*/) {
715779
const startPos = ++pos;
716780
if (identifier() && source.charCodeAt(pos) === ch) {

deps/cjs-module-lexer/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cjs-module-lexer",
3-
"version": "0.4.2",
3+
"version": "0.4.3",
44
"description": "Lexes CommonJS modules, returning their named exports metadata",
55
"main": "lexer.js",
66
"exports": {
@@ -14,8 +14,8 @@
1414
"bench": "node --expose-gc bench/index.mjs",
1515
"build": "node build.js && babel dist/lexer.mjs | terser -o dist/lexer.js",
1616
"build-wasm": "make lib/lexer.wasm && node build.js",
17-
"prepublishOnly": "make optimize && npm run build",
18-
"footprint": "make optimize && npm run build && cat dist/lexer.js | gzip -9f | wc -c"
17+
"prepublishOnly": "make && npm run build",
18+
"footprint": "npm run build && cat dist/lexer.js | gzip -9f | wc -c"
1919
},
2020
"author": "Guy Bedford",
2121
"license": "MIT",

doc/api/esm.md

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

0 commit comments

Comments
 (0)