Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bdcc77b

Browse filesBrowse files
guybedfordMylesBorins
authored andcommitted
deps: update to cjs-module-lexer@0.5.2
PR-URL: #35901 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 5b8d3c7 commit bdcc77b
Copy full SHA for bdcc77b

File tree

Expand file treeCollapse file tree

8 files changed

+213
-68
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

8 files changed

+213
-68
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: deps/cjs-module-lexer/CHANGELOG.md
+6Lines changed: 6 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
0.5.2
2+
- Support named getter functions (https://github.com/guybedford/cjs-module-lexer/pull/26)
3+
4+
0.5.1:
5+
- Feature: Implement specific reexport getter forms (https://github.com/guybedford/cjs-module-lexer/pull/25)
6+
17
0.5.0
28
- Breaking Change: No longer emit Object.defineProperty exports (https://github.com/guybedford/cjs-module-lexer/pull/24)
39
- Doc: Update link to WASI SDK (https://github.com/guybedford/cjs-module-lexer/pull/19)
Collapse file

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

Copy file name to clipboardExpand all lines: deps/cjs-module-lexer/README.md
+94-42Lines changed: 94 additions & 42 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -70,31 +70,35 @@ STRING_LITERAL: A `"` or `'` bounded ECMA-262 string literal.
7070
7171
IDENTIFIER_STRING: ( `"` IDENTIFIER `"` | `'` IDENTIFIER `'` )
7272
73-
COMMENT_SPACE: Any ECMA-262 whitespace, ECMA-262 block comment or ECMA-262 line comment
74-
75-
MODULE_EXPORTS: `module` COMMENT_SPACE `.` COMMENT_SPACE `exports`
73+
MODULE_EXPORTS: `module` `.` `exports`
7674
7775
EXPORTS_IDENTIFIER: MODULE_EXPORTS_IDENTIFIER | `exports`
7876
79-
EXPORTS_DOT_ASSIGN: EXPORTS_IDENTIFIER COMMENT_SPACE `.` COMMENT_SPACE IDENTIFIER COMMENT_SPACE `=`
77+
EXPORTS_DOT_ASSIGN: EXPORTS_IDENTIFIER `.` IDENTIFIER `=`
8078
81-
EXPORTS_LITERAL_COMPUTED_ASSIGN: EXPORTS_IDENTIFIER COMMENT_SPACE `[` COMMENT_SPACE IDENTIFIER_STRING COMMENT_SPACE `]` COMMENT_SPACE `=`
79+
EXPORTS_LITERAL_COMPUTED_ASSIGN: EXPORTS_IDENTIFIER `[` IDENTIFIER_STRING `]` `=`
8280
83-
EXPORTS_LITERAL_PROP: (IDENTIFIER (COMMENT_SPACE `:` COMMENT_SPACE IDENTIFIER)?) | (IDENTIFIER_STRING COMMENT_SPACE `:` COMMENT_SPACE IDENTIFIER)
81+
EXPORTS_LITERAL_PROP: (IDENTIFIER `:` IDENTIFIER)?) | (IDENTIFIER_STRING `:` IDENTIFIER)
8482
85-
EXPORTS_SPREAD: `...` COMMENT_SPACE (IDENTIFIER | REQUIRE)
83+
EXPORTS_SPREAD: `...` (IDENTIFIER | REQUIRE)
8684
8785
EXPORTS_MEMBER: EXPORTS_DOT_ASSIGN | EXPORTS_LITERAL_COMPUTED_ASSIGN
8886
89-
ES_MODULE_DEFINE: `Object` COMMENT_SPACE `.` COMMENT_SPACE `defineProperty COMMENT_SPACE `(` COMMENT_SPACE `__esModule` COMMENT_SPACE `,` COMMENT_SPACE IDENTIFIER_STRING
87+
EXPORTS_DEFINE: `Object` `.` `defineProperty `(` IDENTIFIER_STRING `, {`
88+
(`enumerable: true,`)?
89+
(
90+
`value:` |
91+
`get` (`: function` IDENTIFIER? )? `()` {` return IDENTIFIER (`.` IDENTIFIER | `[` IDENTIFIER_STRING `]`)? `;`? `}`
92+
)
93+
`})`
9094
91-
EXPORTS_LITERAL: MODULE_EXPORTS COMMENT_SPACE `=` COMMENT_SPACE `{` COMMENT_SPACE (EXPORTS_LITERAL_PROP | EXPORTS_SPREAD) COMMENT_SPACE `,` COMMENT_SPACE)+ `}`
95+
EXPORTS_LITERAL: MODULE_EXPORTS `=` `{` (EXPORTS_LITERAL_PROP | EXPORTS_SPREAD) `,`)+ `}`
9296
93-
REQUIRE: `require` COMMENT_SPACE `(` COMMENT_SPACE STRING_LITERAL COMMENT_SPACE `)`
97+
REQUIRE: `require` `(` STRING_LITERAL `)`
9498
9599
EXPORTS_ASSIGN: (`var` | `const` | `let`) IDENTIFIER `=` REQUIRE
96100
97-
MODULE_EXPORTS_ASSIGN: MODULE_EXPORTS COMMENT_SPACE `=` COMMENT_SPACE REQUIRE
101+
MODULE_EXPORTS_ASSIGN: MODULE_EXPORTS `=` REQUIRE
98102
99103
EXPORT_STAR: (`__export` | `__exportStar`) `(` REQUIRE
100104
@@ -113,9 +117,9 @@ EXPORT_STAR_LIB: `Object.keys(` IDENTIFIER$1 `).forEach(function (` IDENTIFIER$2
113117
`})`
114118
```
115119

116-
* The returned export names are taken to be the combination of:
117-
1. `IDENTIFIER` and `IDENTIFIER_STRING` slots for all `EXPORTS_MEMBER` and `EXPORTS_LITERAL` matches.
118-
2. `__esModule` if there is an `ES_MODULE_DEFINE` match.
120+
Spacing between tokens is taken to be any ECMA-262 whitespace, ECMA-262 block comment or ECMA-262 line comment.
121+
122+
* The returned export names are taken to be the combination of the `IDENTIFIER` and `IDENTIFIER_STRING` slots for all `EXPORTS_MEMBER`, `EXPORTS_LITERAL` and `EXPORTS_DEFINE` matches.
119123
* The reexport specifiers are taken to be the the combination of:
120124
1. The `REQUIRE` matches of the last matched of either `MODULE_EXPORTS_ASSIGN` or `EXPORTS_LITERAL`.
121125
2. All _top-level_ `EXPORT_STAR` `REQUIRE` matches and `EXPORTS_ASSIGN` matches whose `IDENTIFIER` also matches the first `IDENTIFIER` in `EXPORT_STAR_LIB`.
@@ -156,17 +160,66 @@ It will in turn underclassify in cases where the identifiers are renamed:
156160
})(exports);
157161
```
158162

159-
#### __esModule Detection
160-
161-
In addition, `__esModule` is detected as an export when set by `Object.defineProperty`:
163+
`Object.defineProperty` is detected for specifically value and getter forms returning an identifier or member expression:
162164

163165
```js
164-
// DETECTS: __esModule
165-
Object.defineProperty(exports, 'a', { value: 'a' });
166+
// DETECTS: a, b, c, d, __esModule
167+
Object.defineProperty(exports, 'a', {
168+
enumerable: true,
169+
get: function () {
170+
return q.p;
171+
}
172+
});
173+
Object.defineProperty(exports, 'b', {
174+
enumerable: true,
175+
get: function () {
176+
return q['p'];
177+
}
178+
});
179+
Object.defineProperty(exports, 'c', {
180+
enumerable: true,
181+
get () {
182+
return b;
183+
}
184+
});
185+
Object.defineProperty(exports, 'd', { value: 'd' });
166186
Object.defineProperty(exports, '__esModule', { value: true });
167187
```
168188

169-
No other named exports are detected for `defineProperty` calls in order not to trigger getters or non-enumerable properties unnecessarily.
189+
Alternative object definition structures or getter function bodies are not detected:
190+
191+
```js
192+
// DETECTS: NO EXPORTS
193+
Object.defineProperty(exports, 'a', {
194+
enumerable: false,
195+
get () {
196+
return p;
197+
}
198+
});
199+
Object.defineProperty(exports, 'b', {
200+
configurable: true,
201+
get () {
202+
return p;
203+
}
204+
});
205+
Object.defineProperty(exports, 'c', {
206+
get: () => p
207+
});
208+
Object.defineProperty(exports, 'd', {
209+
enumerable: true,
210+
get: function () {
211+
return dynamic();
212+
}
213+
});
214+
Object.defineProperty(exports, 'e', {
215+
enumerable: true,
216+
get () {
217+
return 'str';
218+
}
219+
});
220+
```
221+
222+
`Object.defineProperties` is also not supported.
170223

171224
#### Exports Object Assignment
172225

@@ -281,65 +334,64 @@ Current results:
281334
JS Build:
282335

283336
```
284-
--- JS Build ---
285337
Module load time
286-
> 2ms
338+
> 5ms
287339
Cold Run, All Samples
288340
test/samples/*.js (3635 KiB)
289-
> 311ms
341+
> 323ms
290342
291343
Warm Runs (average of 25 runs)
292344
test/samples/angular.js (1410 KiB)
293-
> 14.76ms
345+
> 14.84ms
294346
test/samples/angular.min.js (303 KiB)
295-
> 5.04ms
347+
> 4.8ms
296348
test/samples/d3.js (553 KiB)
297-
> 7.12ms
349+
> 7.84ms
298350
test/samples/d3.min.js (250 KiB)
299351
> 4ms
300352
test/samples/magic-string.js (34 KiB)
301-
> 0.84ms
353+
> 0.72ms
302354
test/samples/magic-string.min.js (20 KiB)
303-
> 0.08ms
355+
> 0.4ms
304356
test/samples/rollup.js (698 KiB)
305-
> 9.08ms
357+
> 9.32ms
306358
test/samples/rollup.min.js (367 KiB)
307-
> 6ms
359+
> 6.52ms
308360
309361
Warm Runs, All Samples (average of 25 runs)
310362
test/samples/*.js (3635 KiB)
311-
> 41.32ms
363+
> 44ms
312364
```
313365

314366
Wasm Build:
315367
```
316368
Module load time
317-
> 10ms
369+
> 11ms
318370
Cold Run, All Samples
319371
test/samples/*.js (3635 KiB)
320-
> 47ms
372+
> 42ms
321373
322374
Warm Runs (average of 25 runs)
323375
test/samples/angular.js (1410 KiB)
324-
> 12.96ms
376+
> 9.92ms
325377
test/samples/angular.min.js (303 KiB)
326-
> 4ms
378+
> 3.2ms
327379
test/samples/d3.js (553 KiB)
328-
> 6.12ms
380+
> 5.2ms
329381
test/samples/d3.min.js (250 KiB)
330-
> 3.08ms
382+
> 2.52ms
331383
test/samples/magic-string.js (34 KiB)
332-
> 0.32ms
384+
> 0.16ms
333385
test/samples/magic-string.min.js (20 KiB)
334-
> 0ms
386+
> 0.04ms
335387
test/samples/rollup.js (698 KiB)
336-
> 7.8ms
388+
> 6.44ms
337389
test/samples/rollup.min.js (367 KiB)
338-
> 4.64ms
390+
> 3.96ms
339391
340392
Warm Runs, All Samples (average of 25 runs)
341393
test/samples/*.js (3635 KiB)
342-
> 35.64ms
394+
> 30.48ms
343395
```
344396

345397
### Wasm Build Steps
Collapse file

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

Copy file name to clipboardExpand all lines: deps/cjs-module-lexer/dist/lexer.js
+1-1Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

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

Copy file name to clipboardExpand all lines: deps/cjs-module-lexer/dist/lexer.mjs
+2-2Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.
Collapse file

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

Copy file name to clipboardExpand all lines: deps/cjs-module-lexer/lexer.js
+106-19Lines changed: 106 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -260,30 +260,117 @@ function tryParseObjectDefineOrKeys (keys) {
260260
pos++;
261261
ch = commentWhitespace();
262262
if (ch === 100/*d*/ && source.startsWith('efineProperty', pos + 1)) {
263-
pos += 14;
264-
revertPos = pos - 1;
265-
ch = commentWhitespace();
266-
if (ch !== 40/*(*/) {
267-
pos = revertPos;
268-
return;
269-
}
270-
pos++;
271-
ch = commentWhitespace();
272-
if (readExportsOrModuleDotExports(ch)) {
263+
while (true) {
264+
pos += 14;
265+
revertPos = pos - 1;
266+
ch = commentWhitespace();
267+
if (ch !== 40/*(*/) break;
268+
pos++;
269+
ch = commentWhitespace();
270+
if (!readExportsOrModuleDotExports(ch)) break;
271+
ch = commentWhitespace();
272+
if (ch !== 44/*,*/) break;
273+
pos++;
274+
ch = commentWhitespace();
275+
if (ch !== 39/*'*/ && ch !== 34/*"*/) break;
276+
let quot = ch;
277+
const exportPos = ++pos;
278+
if (!identifier() || source.charCodeAt(pos) !== quot) break;
279+
const expt = source.slice(exportPos, pos);
280+
pos++;
281+
ch = commentWhitespace();
282+
if (ch !== 44/*,*/) break;
283+
pos++;
273284
ch = commentWhitespace();
274-
if (ch === 44/*,*/) {
285+
if (ch !== 123/*{*/) break;
286+
pos++;
287+
ch = commentWhitespace();
288+
if (ch === 101/*e*/) {
289+
if (!source.startsWith('numerable', pos + 1)) break;
290+
pos += 10;
291+
ch = commentWhitespace();
292+
if (ch !== 58/*:*/) break;
275293
pos++;
276294
ch = commentWhitespace();
277-
if (ch === 39/*'*/ || ch === 34/*"*/) {
278-
const exportPos = ++pos;
279-
if (identifier() && source.charCodeAt(pos) === ch) {
280-
// revert for "("
281-
const expt = source.slice(exportPos, pos);
282-
if (expt === '__esModule')
283-
addExport(expt);
284-
}
295+
if (ch !== 116/*t*/ || !source.startsWith('rue', pos + 1)) break;
296+
pos += 4;
297+
ch = commentWhitespace();
298+
if (ch !== 44) break;
299+
pos++;
300+
ch = commentWhitespace();
301+
}
302+
if (ch === 118/*v*/) {
303+
if (!source.startsWith('alue', pos + 1)) break;
304+
pos += 5;
305+
ch = commentWhitespace();
306+
if (ch !== 58/*:*/) break;
307+
pos++;
308+
addExport(expt);
309+
break;
310+
}
311+
else if (ch === 103/*g*/) {
312+
if (!source.startsWith('et', pos + 1)) break;
313+
pos += 3;
314+
ch = commentWhitespace();
315+
if (ch === 58/*:*/) {
316+
pos++;
317+
ch = commentWhitespace();
318+
if (ch !== 102/*f*/) break;
319+
if (!source.startsWith('unction', pos + 1)) break;
320+
pos += 8;
321+
let lastPos = pos;
322+
ch = commentWhitespace();
323+
if (ch !== 40 && (lastPos === pos || !identifier())) break;
324+
ch = commentWhitespace();
325+
}
326+
if (ch !== 40/*(*/) break;
327+
pos++;
328+
ch = commentWhitespace();
329+
if (ch !== 41/*)*/) break;
330+
pos++;
331+
ch = commentWhitespace();
332+
if (ch !== 123/*{*/) break;
333+
pos++;
334+
ch = commentWhitespace();
335+
if (ch !== 114/*r*/) break;
336+
if (!source.startsWith('eturn', pos + 1)) break;
337+
pos += 6;
338+
ch = commentWhitespace();
339+
if (!identifier()) break;
340+
ch = commentWhitespace();
341+
if (ch === 46/*.*/) {
342+
pos++;
343+
commentWhitespace();
344+
if (!identifier()) break;
345+
ch = commentWhitespace();
346+
}
347+
else if (ch === 91/*[*/) {
348+
pos++;
349+
ch = commentWhitespace();
350+
if (ch === 39/*'*/) singleQuoteString();
351+
else if (ch === 34/*"*/) doubleQuoteString();
352+
else break;
353+
pos++;
354+
ch = commentWhitespace();
355+
if (ch !== 93/*]*/) break;
356+
pos++;
357+
ch = commentWhitespace();
358+
}
359+
if (ch === 59/*;*/) {
360+
pos++;
361+
ch = commentWhitespace();
285362
}
363+
if (ch !== 125/*}*/) break;
364+
pos++;
365+
ch = commentWhitespace();
366+
if (ch !== 125/*}*/) break;
367+
pos++;
368+
ch = commentWhitespace();
369+
if (ch !== 41/*)*/) break;
370+
addExport(expt);
371+
return;
286372
}
373+
break;
287374
}
288375
}
289376
else if (keys && ch === 107/*k*/ && source.startsWith('eys', pos + 1)) {
Collapse file

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

Copy file name to clipboardExpand all lines: deps/cjs-module-lexer/package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cjs-module-lexer",
3-
"version": "0.5.0",
3+
"version": "0.5.2",
44
"description": "Lexes CommonJS modules, returning their named exports metadata",
55
"main": "lexer.js",
66
"exports": {
Collapse file

‎doc/api/esm.md‎

Copy file name to clipboardExpand all lines: doc/api/esm.md
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ success!
12961296
[`Uint8Array`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
12971297
[dynamic instantiate hook]: #esm_code_dynamicinstantiate_code_hook
12981298
[`util.TextDecoder`]: util.md#util_class_util_textdecoder
1299-
[cjs-module-lexer]: https://github.com/guybedford/cjs-module-lexer/tree/0.5.0
1299+
[cjs-module-lexer]: https://github.com/guybedford/cjs-module-lexer/tree/0.5.2
13001300
[special scheme]: https://url.spec.whatwg.org/#special-scheme
13011301
[the official standard format]: https://tc39.github.io/ecma262/#sec-modules
13021302
[transpiler loader example]: #esm_transpiler_loader

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.