Skip to content

Commit d56079a

Browse files
committedApr 14, 2021
deps: update to cjs-module-lexer@1.1.1
PR-URL: #38002 Backport-PR-URL: #37992 Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com>
1 parent f70aee0 commit d56079a

File tree

7 files changed

+226
-80
lines changed

7 files changed

+226
-80
lines changed
 

‎deps/cjs-module-lexer/CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
1.1.1
2+
- Better support for Babel reexport getter function forms (https://github.com/guybedford/cjs-module-lexer/issues/50)
3+
- Support Babel interopRequireWildcard reexports patterns (https://github.com/guybedford/cjs-module-lexer/issues/52)
4+
5+
1.1.0
6+
- Support for Babel reexport conflict filter (https://github.com/guybedford/cjs-module-lexer/issues/36, @nicolo-ribaudo)
7+
- Support trailing commas in getter patterns (https://github.com/guybedford/cjs-module-lexer/issues/31)
8+
- Support for RollupJS reexports property checks (https://github.com/guybedford/cjs-module-lexer/issues/38)
9+
110
1.0.0
211
- Unsafe getter tracking (https://github.com/guybedford/cjs-module-lexer/pull/29)
312

‎deps/cjs-module-lexer/README.md

+24-11
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ EXPORTS_DOT_ASSIGN: EXPORTS_IDENTIFIER `.` IDENTIFIER `=`
8080
8181
EXPORTS_LITERAL_COMPUTED_ASSIGN: EXPORTS_IDENTIFIER `[` IDENTIFIER_STRING `]` `=`
8282
83-
EXPORTS_LITERAL_PROP: (IDENTIFIER `:` IDENTIFIER)?) | (IDENTIFIER_STRING `:` IDENTIFIER)
83+
EXPORTS_LITERAL_PROP: (IDENTIFIER (`:` IDENTIFIER)?) | (IDENTIFIER_STRING `:` IDENTIFIER)
8484
8585
EXPORTS_SPREAD: `...` (IDENTIFIER | REQUIRE)
8686
@@ -92,31 +92,34 @@ EXPORTS_DEFINE_VALUE: EXPORTS_DEFINE `, {`
9292
(`enumerable: true,`)?
9393
(
9494
`value:` |
95-
`get` (`: function` IDENTIFIER? )? `()` {` return IDENTIFIER (`.` IDENTIFIER | `[` IDENTIFIER_STRING `]`)? `;`? `}`
95+
`get` (`: function` IDENTIFIER? )? `() {` return IDENTIFIER (`.` IDENTIFIER | `[` IDENTIFIER_STRING `]`)? `;`? `}` `,`?
9696
)
9797
`})`
9898
9999
EXPORTS_LITERAL: MODULE_EXPORTS `=` `{` (EXPORTS_LITERAL_PROP | EXPORTS_SPREAD) `,`)+ `}`
100100
101101
REQUIRE: `require` `(` STRING_LITERAL `)`
102102
103-
EXPORTS_ASSIGN: (`var` | `const` | `let`) IDENTIFIER `=` REQUIRE
103+
EXPORTS_ASSIGN: (`var` | `const` | `let`) IDENTIFIER `=` (`_interopRequireWildcard (`)? REQUIRE
104104
105105
MODULE_EXPORTS_ASSIGN: MODULE_EXPORTS `=` REQUIRE
106106
107107
EXPORT_STAR: (`__export` | `__exportStar`) `(` REQUIRE
108108
109109
EXPORT_STAR_LIB: `Object.keys(` IDENTIFIER$1 `).forEach(function (` IDENTIFIER$2 `) {`
110110
(
111-
`if (` IDENTIFIER$2 `===` ( `'default'` | `"default"` ) `||` IDENTIFIER$2 `===` ( '__esModule' | `"__esModule"` ) `) return` `;`? |
112-
`if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) `)`
111+
(
112+
`if (` IDENTIFIER$2 `===` ( `'default'` | `"default"` ) `||` IDENTIFIER$2 `===` ( '__esModule' | `"__esModule"` ) `) return` `;`?
113+
(
114+
(`if (Object` `.prototype`? `.hasOwnProperty.call(` IDENTIFIER `, ` IDENTIFIER$2 `)) return` `;`?)?
115+
(`if (` IDENTIFIER$2 `in` EXPORTS_IDENTIFIER `&&` EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] ===` IDENTIFIER$1 `[` IDENTIFIER$2 `]) return` `;`)?
116+
)?
117+
) |
118+
`if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) (`&& !` (`Object` `.prototype`? `.hasOwnProperty.call(` IDENTIFIER$1 `, ` IDENTIFIER$2 `)` | IDENTIFIER$1 `.hasOwnProperty(` IDENTIFIER$2 `)`))? `)`
113119
)
114-
(
115-
`if (` IDENTIFIER$2 `in` EXPORTS_IDENTIFIER `&&` EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] ===` IDENTIFIER$1 `[` IDENTIFIER$2 `]) return` `;`?
116-
)?
117120
(
118121
EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] =` IDENTIFIER$1 `[` IDENTIFIER$2 `]` `;`? |
119-
`Object.defineProperty(` EXPORTS_IDENTIFIER `, ` IDENTIFIER$2 `, { enumerable: true, get: function () { return ` IDENTIFIER$1 `[` IDENTIFIER$2 `]` `;`? } })` `;`?
122+
`Object.defineProperty(` EXPORTS_IDENTIFIER `, ` IDENTIFIER$2 `, { enumerable: true, get` (`: function` IDENTIFIER? )? `() { return ` IDENTIFIER$1 `[` IDENTIFIER$2 `]` `;`? `}` `,`? `})` `;`?
120123
)
121124
`})`
122125
```
@@ -126,7 +129,7 @@ Spacing between tokens is taken to be any ECMA-262 whitespace, ECMA-262 block co
126129
* The returned export names are taken to be the combination of:
127130
1. All `IDENTIFIER` and `IDENTIFIER_STRING` slots for `EXPORTS_MEMBER` and `EXPORTS_LITERAL` matches.
128131
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.
129-
* The reexport specifiers are taken to be the the combination of:
132+
* The reexport specifiers are taken to be the combination of:
130133
1. The `REQUIRE` matches of the last matched of either `MODULE_EXPORTS_ASSIGN` or `EXPORTS_LITERAL`.
131134
2. All _top-level_ `EXPORT_STAR` `REQUIRE` matches and `EXPORTS_ASSIGN` matches whose `IDENTIFIER` also matches the first `IDENTIFIER` in `EXPORT_STAR_LIB`.
132135

@@ -194,13 +197,23 @@ Object.defineProperty(exports, 'd', { value: 'd' });
194197
Object.defineProperty(exports, '__esModule', { value: true });
195198
```
196199

200+
Value properties are also detected specifically:
201+
202+
```js
203+
Object.defineProperty(exports, 'a', {
204+
value: 'no problem'
205+
});
206+
```
207+
197208
To avoid matching getters that have side effects, any getter for an export name that does not support the forms above will
198209
opt-out of the getter matching:
199210

200211
```js
201212
// DETECTS: NO EXPORTS
202213
Object.defineProperty(exports, 'a', {
203-
value: 'no problem'
214+
get () {
215+
return 'nope';
216+
}
204217
});
205218

206219
if (false) {

‎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

+188-64
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,18 @@ function parseSource (cjsSource) {
9797
lastTokenPos = pos;
9898
continue;
9999
case 95/*_*/:
100-
if (source.startsWith('_export', pos + 1) && (keywordStart(pos) || source.charCodeAt(pos - 1) === 46/*.*/)) {
100+
if (source.startsWith('interopRequireWildcard', pos + 1) && (keywordStart(pos) || source.charCodeAt(pos - 1) === 46/*.*/)) {
101+
const startPos = pos;
102+
pos += 23;
103+
if (source.charCodeAt(pos) === 40/*(*/) {
104+
pos++;
105+
openTokenPosStack[openTokenDepth++] = lastTokenPos;
106+
if (tryParseRequire(Import) && keywordStart(startPos)) {
107+
tryBacktrackAddStarExportBinding(startPos - 1);
108+
}
109+
}
110+
}
111+
else if (source.startsWith('_export', pos + 1) && (keywordStart(pos) || source.charCodeAt(pos - 1) === 46/*.*/)) {
101112
pos += 8;
102113
if (source.startsWith('Star', pos))
103114
pos += 4;
@@ -254,6 +265,48 @@ function tryBacktrackAddStarExportBinding (bPos) {
254265
}
255266
}
256267

268+
// `Object.` `prototype.`? hasOwnProperty.call(` IDENTIFIER `, ` IDENTIFIER$2 `)`
269+
function tryParseObjectHasOwnProperty (it_id) {
270+
ch = commentWhitespace();
271+
if (ch !== 79/*O*/ || !source.startsWith('bject', pos + 1)) return false;
272+
pos += 6;
273+
ch = commentWhitespace();
274+
if (ch !== 46/*.*/) return false;
275+
pos++;
276+
ch = commentWhitespace();
277+
if (ch === 112/*p*/) {
278+
if (!source.startsWith('rototype', pos + 1)) return false;
279+
pos += 9;
280+
ch = commentWhitespace();
281+
if (ch !== 46/*.*/) return false;
282+
pos++;
283+
ch = commentWhitespace();
284+
}
285+
if (ch !== 104/*h*/ || !source.startsWith('asOwnProperty', pos + 1)) return false;
286+
pos += 14;
287+
ch = commentWhitespace();
288+
if (ch !== 46/*.*/) return false;
289+
pos++;
290+
ch = commentWhitespace();
291+
if (ch !== 99/*c*/ || !source.startsWith('all', pos + 1)) return false;
292+
pos += 4;
293+
ch = commentWhitespace();
294+
if (ch !== 40/*(*/) return false;
295+
pos++;
296+
ch = commentWhitespace();
297+
if (!identifier()) return false;
298+
ch = commentWhitespace();
299+
if (ch !== 44/*,*/) return false;
300+
pos++;
301+
ch = commentWhitespace();
302+
if (!source.startsWith(it_id, pos)) return false;
303+
pos += it_id.length;
304+
ch = commentWhitespace();
305+
if (ch !== 41/*)*/) return false;
306+
pos++;
307+
return true;
308+
}
309+
257310
function tryParseObjectDefineOrKeys (keys) {
258311
pos += 6;
259312
let revertPos = pos - 1;
@@ -366,6 +419,10 @@ function tryParseObjectDefineOrKeys (keys) {
366419
if (ch !== 125/*}*/) break;
367420
pos++;
368421
ch = commentWhitespace();
422+
if (ch === 44/*,*/) {
423+
pos++;
424+
ch = commentWhitespace();
425+
}
369426
if (ch !== 125/*}*/) break;
370427
pos++;
371428
ch = commentWhitespace();
@@ -469,8 +526,94 @@ function tryParseObjectDefineOrKeys (keys) {
469526
if (ch === 59/*;*/)
470527
pos++;
471528
ch = commentWhitespace();
529+
530+
// `if (`
531+
if (ch === 105/*i*/ && source.charCodeAt(pos + 1) === 102/*f*/) {
532+
let inIf = true;
533+
pos += 2;
534+
ch = commentWhitespace();
535+
if (ch !== 40/*(*/) break;
536+
pos++;
537+
const ifInnerPos = pos;
538+
// `Object.prototype.hasOwnProperty.call(` IDENTIFIER `, ` IDENTIFIER$2 `)) return` `;`?
539+
if (tryParseObjectHasOwnProperty(it_id)) {
540+
ch = commentWhitespace();
541+
if (ch !== 41/*)*/) break;
542+
pos++;
543+
ch = commentWhitespace();
544+
if (ch !== 114/*r*/ || !source.startsWith('eturn', pos + 1)) break;
545+
pos += 6;
546+
ch = commentWhitespace();
547+
if (ch === 59/*;*/)
548+
pos++;
549+
ch = commentWhitespace();
550+
// match next if
551+
if (ch === 105/*i*/ && source.charCodeAt(pos + 1) === 102/*f*/) {
552+
pos += 2;
553+
ch = commentWhitespace();
554+
if (ch !== 40/*(*/) break;
555+
pos++;
556+
}
557+
else {
558+
inIf = false;
559+
}
560+
}
561+
else {
562+
pos = ifInnerPos;
563+
}
564+
565+
// IDENTIFIER$2 `in` EXPORTS_IDENTIFIER `&&` EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] ===` IDENTIFIER$1 `[` IDENTIFIER$2 `]) return` `;`?
566+
if (inIf) {
567+
if (!source.startsWith(it_id, pos)) break;
568+
pos += it_id.length;
569+
ch = commentWhitespace();
570+
if (ch !== 105/*i*/ || !source.startsWith('n ', pos + 1)) break;
571+
pos += 3;
572+
ch = commentWhitespace();
573+
if (!readExportsOrModuleDotExports(ch)) break;
574+
ch = commentWhitespace();
575+
if (ch !== 38/*&*/ || source.charCodeAt(pos + 1) !== 38/*&*/) break;
576+
pos += 2;
577+
ch = commentWhitespace();
578+
if (!readExportsOrModuleDotExports(ch)) break;
579+
ch = commentWhitespace();
580+
if (ch !== 91/*[*/) break;
581+
pos++;
582+
ch = commentWhitespace();
583+
if (!source.startsWith(it_id, pos)) break;
584+
pos += it_id.length;
585+
ch = commentWhitespace();
586+
if (ch !== 93/*]*/) break;
587+
pos++;
588+
ch = commentWhitespace();
589+
if (ch !== 61/*=*/ || !source.startsWith('==', pos + 1)) break;
590+
pos += 3;
591+
ch = commentWhitespace();
592+
if (!source.startsWith(id, pos)) break;
593+
pos += id.length;
594+
ch = commentWhitespace();
595+
if (ch !== 91/*[*/) break;
596+
pos++;
597+
ch = commentWhitespace();
598+
if (!source.startsWith(it_id, pos)) break;
599+
pos += it_id.length;
600+
ch = commentWhitespace();
601+
if (ch !== 93/*]*/) break;
602+
pos++;
603+
ch = commentWhitespace();
604+
if (ch !== 41/*)*/) break;
605+
pos++;
606+
ch = commentWhitespace();
607+
if (ch !== 114/*r*/ || !source.startsWith('eturn', pos + 1)) break;
608+
pos += 6;
609+
ch = commentWhitespace();
610+
if (ch === 59/*;*/)
611+
pos++;
612+
ch = commentWhitespace();
613+
}
614+
}
472615
}
473-
// `if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) `)`
616+
// `if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) (`&& !` IDENTIFIER `.hasOwnProperty(` IDENTIFIER$2 `)` )? `)`
474617
else if (ch === 33/*!*/) {
475618
if (!source.startsWith('==', pos + 1)) break;
476619
pos += 3;
@@ -483,67 +626,40 @@ function tryParseObjectDefineOrKeys (keys) {
483626
if (ch !== quot) break;
484627
pos += 1;
485628
ch = commentWhitespace();
629+
if (ch === 38/*&*/) {
630+
if (source.charCodeAt(pos + 1) !== 38/*&*/) break;
631+
pos += 2;
632+
ch = commentWhitespace();
633+
if (ch !== 33/*!*/) break;
634+
pos += 1;
635+
ch = commentWhitespace();
636+
if (source.startsWith(id, pos)) {
637+
pos += id.length;
638+
ch = commentWhitespace();
639+
if (ch !== 46/*.*/) break;
640+
pos++;
641+
ch = commentWhitespace();
642+
if (ch !== 104/*h*/ || !source.startsWith('asOwnProperty', pos + 1)) break;
643+
pos += 14;
644+
ch = commentWhitespace();
645+
if (ch !== 40/*(*/) break;
646+
pos += 1;
647+
ch = commentWhitespace();
648+
if (!source.startsWith(it_id, pos)) break;
649+
pos += it_id.length;
650+
ch = commentWhitespace();
651+
if (ch !== 41/*)*/) break;
652+
pos += 1;
653+
}
654+
else if (!tryParseObjectHasOwnProperty(it_id)) break;
655+
ch = commentWhitespace();
656+
}
486657
if (ch !== 41/*)*/) break;
487658
pos += 1;
488659
ch = commentWhitespace();
489660
}
490661
else break;
491662

492-
// `if (` IDENTIFIER$2 `in` EXPORTS_IDENTIFIER `&&` EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] ===` IDENTIFIER$1 `[` IDENTIFIER$2 `]) return` `;`?
493-
if (ch === 105/*i*/ && source.charCodeAt(pos + 1) === 102/*f*/) {
494-
pos += 2;
495-
ch = commentWhitespace();
496-
if (ch !== 40/*(*/) break;
497-
pos++;
498-
ch = commentWhitespace();
499-
if (!source.startsWith(it_id, pos)) break;
500-
pos += it_id.length;
501-
ch = commentWhitespace();
502-
if (ch !== 105/*i*/ || !source.startsWith('n ', pos + 1)) break;
503-
pos += 3;
504-
ch = commentWhitespace();
505-
if (!readExportsOrModuleDotExports(ch)) break;
506-
ch = commentWhitespace();
507-
if (ch !== 38/*&*/ || source.charCodeAt(pos + 1) !== 38/*&*/) break;
508-
pos += 2;
509-
ch = commentWhitespace();
510-
if (!readExportsOrModuleDotExports(ch)) break;
511-
ch = commentWhitespace();
512-
if (ch !== 91/*[*/) break;
513-
pos++;
514-
ch = commentWhitespace();
515-
if (!source.startsWith(it_id, pos)) break;
516-
pos += it_id.length;
517-
ch = commentWhitespace();
518-
if (ch !== 93/*]*/) break;
519-
pos++;
520-
ch = commentWhitespace();
521-
if (ch !== 61/*=*/ || !source.startsWith('==', pos + 1)) break;
522-
pos += 3;
523-
ch = commentWhitespace();
524-
if (!source.startsWith(id, pos)) break;
525-
pos += id.length;
526-
ch = commentWhitespace();
527-
if (ch !== 91/*[*/) break;
528-
pos++;
529-
ch = commentWhitespace();
530-
if (!source.startsWith(it_id, pos)) break;
531-
pos += it_id.length;
532-
ch = commentWhitespace();
533-
if (ch !== 93/*]*/) break;
534-
pos++;
535-
ch = commentWhitespace();
536-
if (ch !== 41/*)*/) break;
537-
pos++;
538-
ch = commentWhitespace();
539-
if (ch !== 114/*r*/ || !source.startsWith('eturn', pos + 1)) break;
540-
pos += 6;
541-
ch = commentWhitespace();
542-
if (ch === 59/*;*/)
543-
pos++;
544-
ch = commentWhitespace();
545-
}
546-
547663
// EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] =` IDENTIFIER$1 `[` IDENTIFIER$2 `]`
548664
if (readExportsOrModuleDotExports(ch)) {
549665
ch = commentWhitespace();
@@ -619,12 +735,17 @@ function tryParseObjectDefineOrKeys (keys) {
619735
if (ch !== 103/*g*/ || !source.startsWith('et', pos + 1)) break;
620736
pos += 3;
621737
ch = commentWhitespace();
622-
if (ch !== 58/*:*/) break;
623-
pos++;
624-
ch = commentWhitespace();
625-
if (ch !== 102/*f*/ || !source.startsWith('unction', pos + 1)) break;
626-
pos += 8;
627-
ch = commentWhitespace();
738+
if (ch === 58/*:*/) {
739+
pos++;
740+
ch = commentWhitespace();
741+
if (ch !== 102/*f*/) break;
742+
if (!source.startsWith('unction', pos + 1)) break;
743+
pos += 8;
744+
let lastPos = pos;
745+
ch = commentWhitespace();
746+
if (ch !== 40 && (lastPos === pos || !identifier())) break;
747+
ch = commentWhitespace();
748+
}
628749
if (ch !== 40/*(*/) break;
629750
pos++;
630751
ch = commentWhitespace();
@@ -656,6 +777,10 @@ function tryParseObjectDefineOrKeys (keys) {
656777
if (ch !== 125/*}*/) break;
657778
pos++;
658779
ch = commentWhitespace();
780+
if (ch === 44/*,*/) {
781+
pos++;
782+
ch = commentWhitespace();
783+
}
659784
if (ch !== 125/*}*/) break;
660785
pos++;
661786
ch = commentWhitespace();
@@ -1039,7 +1164,6 @@ function throwIfImportStatement () {
10391164
// import.meta
10401165
case 46/*.*/:
10411166
throw new Error('Unexpected import.meta in CJS module.');
1042-
return;
10431167

10441168
default:
10451169
// no space after "import" -> not an import keyword

‎deps/cjs-module-lexer/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cjs-module-lexer",
3-
"version": "1.0.0",
3+
"version": "1.1.1",
44
"description": "Lexes CommonJS modules, returning their named exports metadata",
55
"main": "lexer.js",
66
"exports": {

‎doc/api/esm.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,7 @@ success!
13261326
[`transformSource` hook]: #esm_transformsource_source_context_defaulttransformsource
13271327
[`string`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
13281328
[`util.TextDecoder`]: util.md#util_class_util_textdecoder
1329-
[cjs-module-lexer]: https://github.com/guybedford/cjs-module-lexer/tree/1.0.0
1329+
[cjs-module-lexer]: https://github.com/guybedford/cjs-module-lexer/tree/1.1.1
13301330
[custom https loader]: #esm_https_loader
13311331
[special scheme]: https://url.spec.whatwg.org/#special-scheme
13321332
[the official standard format]: https://tc39.github.io/ecma262/#sec-modules

0 commit comments

Comments
 (0)
Please sign in to comment.