Skip to content

Commit dfca2fa

Browse files
guybedforddanielleadams
authored andcommitted
deps: update to cjs-module-lexer@1.1.0
PR-URL: #37712 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent 72af5d9 commit dfca2fa

File tree

7 files changed

+197
-71
lines changed

7 files changed

+197
-71
lines changed

deps/cjs-module-lexer/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
1.1.0
2+
- Support for Babel reexport conflict filter (https://github.com/guybedford/cjs-module-lexer/issues/36, @nicolo-ribaudo)
3+
- Support trailing commas in getter patterns (https://github.com/guybedford/cjs-module-lexer/issues/31)
4+
- Support for RollupJS reexports property checks (https://github.com/guybedford/cjs-module-lexer/issues/38)
5+
16
1.0.0
27
- Unsafe getter tracking (https://github.com/guybedford/cjs-module-lexer/pull/29)
38

deps/cjs-module-lexer/README.md

+22-9
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,7 +92,7 @@ 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
@@ -108,15 +108,18 @@ 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 () { return ` IDENTIFIER$1 `[` IDENTIFIER$2 `]` `;`? `}` `,`? `})` `;`?
120123
)
121124
`})`
122125
```
@@ -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

+165-57
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,48 @@ function tryBacktrackAddStarExportBinding (bPos) {
254254
}
255255
}
256256

257+
// `Object.` `prototype.`? hasOwnProperty.call(` IDENTIFIER `, ` IDENTIFIER$2 `)`
258+
function tryParseObjectHasOwnProperty (it_id) {
259+
ch = commentWhitespace();
260+
if (ch !== 79/*O*/ || !source.startsWith('bject', pos + 1)) return false;
261+
pos += 6;
262+
ch = commentWhitespace();
263+
if (ch !== 46/*.*/) return false;
264+
pos++;
265+
ch = commentWhitespace();
266+
if (ch === 112/*p*/) {
267+
if (!source.startsWith('rototype', pos + 1)) return false;
268+
pos += 9;
269+
ch = commentWhitespace();
270+
if (ch !== 46/*.*/) return false;
271+
pos++;
272+
ch = commentWhitespace();
273+
}
274+
if (ch !== 104/*h*/ || !source.startsWith('asOwnProperty', pos + 1)) return false;
275+
pos += 14;
276+
ch = commentWhitespace();
277+
if (ch !== 46/*.*/) return false;
278+
pos++;
279+
ch = commentWhitespace();
280+
if (ch !== 99/*c*/ || !source.startsWith('all', pos + 1)) return false;
281+
pos += 4;
282+
ch = commentWhitespace();
283+
if (ch !== 40/*(*/) return false;
284+
pos++;
285+
ch = commentWhitespace();
286+
if (!identifier()) return false;
287+
ch = commentWhitespace();
288+
if (ch !== 44/*,*/) return false;
289+
pos++;
290+
ch = commentWhitespace();
291+
if (!source.startsWith(it_id, pos)) return false;
292+
pos += it_id.length;
293+
ch = commentWhitespace();
294+
if (ch !== 41/*)*/) return false;
295+
pos++;
296+
return true;
297+
}
298+
257299
function tryParseObjectDefineOrKeys (keys) {
258300
pos += 6;
259301
let revertPos = pos - 1;
@@ -366,6 +408,10 @@ function tryParseObjectDefineOrKeys (keys) {
366408
if (ch !== 125/*}*/) break;
367409
pos++;
368410
ch = commentWhitespace();
411+
if (ch === 44/*,*/) {
412+
pos++;
413+
ch = commentWhitespace();
414+
}
369415
if (ch !== 125/*}*/) break;
370416
pos++;
371417
ch = commentWhitespace();
@@ -469,8 +515,94 @@ function tryParseObjectDefineOrKeys (keys) {
469515
if (ch === 59/*;*/)
470516
pos++;
471517
ch = commentWhitespace();
518+
519+
// `if (`
520+
if (ch === 105/*i*/ && source.charCodeAt(pos + 1) === 102/*f*/) {
521+
let inIf = true;
522+
pos += 2;
523+
ch = commentWhitespace();
524+
if (ch !== 40/*(*/) break;
525+
pos++;
526+
const ifInnerPos = pos;
527+
// `Object.prototype.hasOwnProperty.call(` IDENTIFIER `, ` IDENTIFIER$2 `)) return` `;`?
528+
if (tryParseObjectHasOwnProperty(it_id)) {
529+
ch = commentWhitespace();
530+
if (ch !== 41/*)*/) break;
531+
pos++;
532+
ch = commentWhitespace();
533+
if (ch !== 114/*r*/ || !source.startsWith('eturn', pos + 1)) break;
534+
pos += 6;
535+
ch = commentWhitespace();
536+
if (ch === 59/*;*/)
537+
pos++;
538+
ch = commentWhitespace();
539+
// match next if
540+
if (ch === 105/*i*/ && source.charCodeAt(pos + 1) === 102/*f*/) {
541+
pos += 2;
542+
ch = commentWhitespace();
543+
if (ch !== 40/*(*/) break;
544+
pos++;
545+
}
546+
else {
547+
inIf = false;
548+
}
549+
}
550+
else {
551+
pos = ifInnerPos;
552+
}
553+
554+
// IDENTIFIER$2 `in` EXPORTS_IDENTIFIER `&&` EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] ===` IDENTIFIER$1 `[` IDENTIFIER$2 `]) return` `;`?
555+
if (inIf) {
556+
if (!source.startsWith(it_id, pos)) break;
557+
pos += it_id.length;
558+
ch = commentWhitespace();
559+
if (ch !== 105/*i*/ || !source.startsWith('n ', pos + 1)) break;
560+
pos += 3;
561+
ch = commentWhitespace();
562+
if (!readExportsOrModuleDotExports(ch)) break;
563+
ch = commentWhitespace();
564+
if (ch !== 38/*&*/ || source.charCodeAt(pos + 1) !== 38/*&*/) break;
565+
pos += 2;
566+
ch = commentWhitespace();
567+
if (!readExportsOrModuleDotExports(ch)) break;
568+
ch = commentWhitespace();
569+
if (ch !== 91/*[*/) break;
570+
pos++;
571+
ch = commentWhitespace();
572+
if (!source.startsWith(it_id, pos)) break;
573+
pos += it_id.length;
574+
ch = commentWhitespace();
575+
if (ch !== 93/*]*/) break;
576+
pos++;
577+
ch = commentWhitespace();
578+
if (ch !== 61/*=*/ || !source.startsWith('==', pos + 1)) break;
579+
pos += 3;
580+
ch = commentWhitespace();
581+
if (!source.startsWith(id, pos)) break;
582+
pos += id.length;
583+
ch = commentWhitespace();
584+
if (ch !== 91/*[*/) break;
585+
pos++;
586+
ch = commentWhitespace();
587+
if (!source.startsWith(it_id, pos)) break;
588+
pos += it_id.length;
589+
ch = commentWhitespace();
590+
if (ch !== 93/*]*/) break;
591+
pos++;
592+
ch = commentWhitespace();
593+
if (ch !== 41/*)*/) break;
594+
pos++;
595+
ch = commentWhitespace();
596+
if (ch !== 114/*r*/ || !source.startsWith('eturn', pos + 1)) break;
597+
pos += 6;
598+
ch = commentWhitespace();
599+
if (ch === 59/*;*/)
600+
pos++;
601+
ch = commentWhitespace();
602+
}
603+
}
472604
}
473-
// `if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) `)`
605+
// `if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) (`&& !` IDENTIFIER `.hasOwnProperty(` IDENTIFIER$2 `)` )? `)`
474606
else if (ch === 33/*!*/) {
475607
if (!source.startsWith('==', pos + 1)) break;
476608
pos += 3;
@@ -483,67 +615,40 @@ function tryParseObjectDefineOrKeys (keys) {
483615
if (ch !== quot) break;
484616
pos += 1;
485617
ch = commentWhitespace();
618+
if (ch === 38/*&*/) {
619+
if (source.charCodeAt(pos + 1) !== 38/*&*/) break;
620+
pos += 2;
621+
ch = commentWhitespace();
622+
if (ch !== 33/*!*/) break;
623+
pos += 1;
624+
ch = commentWhitespace();
625+
if (source.startsWith(id, pos)) {
626+
pos += id.length;
627+
ch = commentWhitespace();
628+
if (ch !== 46/*.*/) break;
629+
pos++;
630+
ch = commentWhitespace();
631+
if (ch !== 104/*h*/ || !source.startsWith('asOwnProperty', pos + 1)) break;
632+
pos += 14;
633+
ch = commentWhitespace();
634+
if (ch !== 40/*(*/) break;
635+
pos += 1;
636+
ch = commentWhitespace();
637+
if (!source.startsWith(it_id, pos)) break;
638+
pos += it_id.length;
639+
ch = commentWhitespace();
640+
if (ch !== 41/*)*/) break;
641+
pos += 1;
642+
}
643+
else if (!tryParseObjectHasOwnProperty(it_id)) break;
644+
ch = commentWhitespace();
645+
}
486646
if (ch !== 41/*)*/) break;
487647
pos += 1;
488648
ch = commentWhitespace();
489649
}
490650
else break;
491651

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-
547652
// EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] =` IDENTIFIER$1 `[` IDENTIFIER$2 `]`
548653
if (readExportsOrModuleDotExports(ch)) {
549654
ch = commentWhitespace();
@@ -656,6 +761,10 @@ function tryParseObjectDefineOrKeys (keys) {
656761
if (ch !== 125/*}*/) break;
657762
pos++;
658763
ch = commentWhitespace();
764+
if (ch === 44/*,*/) {
765+
pos++;
766+
ch = commentWhitespace();
767+
}
659768
if (ch !== 125/*}*/) break;
660769
pos++;
661770
ch = commentWhitespace();
@@ -1039,7 +1148,6 @@ function throwIfImportStatement () {
10391148
// import.meta
10401149
case 46/*.*/:
10411150
throw new Error('Unexpected import.meta in CJS module.');
1042-
return;
10431151

10441152
default:
10451153
// 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.0",
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
@@ -1324,7 +1324,7 @@ success!
13241324
[`transformSource` hook]: #esm_transformsource_source_context_defaulttransformsource
13251325
[`string`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
13261326
[`util.TextDecoder`]: util.md#util_class_util_textdecoder
1327-
[cjs-module-lexer]: https://github.com/guybedford/cjs-module-lexer/tree/1.0.0
1327+
[cjs-module-lexer]: https://github.com/guybedford/cjs-module-lexer/tree/1.1.0
13281328
[custom https loader]: #esm_https_loader
13291329
[special scheme]: https://url.spec.whatwg.org/#special-scheme
13301330
[the official standard format]: https://tc39.github.io/ecma262/#sec-modules

0 commit comments

Comments
 (0)