Skip to content

Commit 20accb0

Browse files
guybedfordtargos
authored andcommitted
deps: upgrade to [email protected]
PR-URL: #35871 Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Jan Krems <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Bradley Farias <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent 8958af4 commit 20accb0

File tree

8 files changed

+86
-48
lines changed

8 files changed

+86
-48
lines changed

deps/cjs-module-lexer/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
0.5.0
2+
- Breaking Change: No longer emit Object.defineProperty exports (https://github.com/guybedford/cjs-module-lexer/pull/24)
3+
- Doc: Update link to WASI SDK (https://github.com/guybedford/cjs-module-lexer/pull/19)
4+
15
0.4.3
26
- Support for Babel 7.12 reexports (https://github.com/guybedford/cjs-module-lexer/pull/16)
37
- Support module.exports = { ...require('x') } reexports (https://github.com/guybedford/cjs-module-lexer/pull/18)

deps/cjs-module-lexer/README.md

+71-38
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,13 @@ EXPORTS_LITERAL_COMPUTED_ASSIGN: EXPORTS_IDENTIFIER COMMENT_SPACE `[` COMMENT_SP
8282
8383
EXPORTS_LITERAL_PROP: (IDENTIFIER (COMMENT_SPACE `:` COMMENT_SPACE IDENTIFIER)?) | (IDENTIFIER_STRING COMMENT_SPACE `:` COMMENT_SPACE IDENTIFIER)
8484
85+
EXPORTS_SPREAD: `...` COMMENT_SPACE (IDENTIFIER | REQUIRE)
86+
8587
EXPORTS_MEMBER: EXPORTS_DOT_ASSIGN | EXPORTS_LITERAL_COMPUTED_ASSIGN
8688
87-
EXPORTS_DEFINE: `Object` COMMENT_SPACE `.` COMMENT_SPACE `defineProperty COMMENT_SPACE `(` EXPORTS_IDENTIFIER COMMENT_SPACE `,` COMMENT_SPACE IDENTIFIER_STRING
89+
ES_MODULE_DEFINE: `Object` COMMENT_SPACE `.` COMMENT_SPACE `defineProperty COMMENT_SPACE `(` COMMENT_SPACE `__esModule` COMMENT_SPACE `,` COMMENT_SPACE IDENTIFIER_STRING
8890
89-
EXPORTS_LITERAL: MODULE_EXPORTS COMMENT_SPACE `=` COMMENT_SPACE `{` COMMENT_SPACE (EXPORTS_LITERAL_PROP COMMENT_SPACE `,` COMMENT_SPACE)+ `}`
91+
EXPORTS_LITERAL: MODULE_EXPORTS COMMENT_SPACE `=` COMMENT_SPACE `{` COMMENT_SPACE (EXPORTS_LITERAL_PROP | EXPORTS_SPREAD) COMMENT_SPACE `,` COMMENT_SPACE)+ `}`
9092
9193
REQUIRE: `require` COMMENT_SPACE `(` COMMENT_SPACE STRING_LITERAL COMMENT_SPACE `)`
9294
@@ -101,15 +103,22 @@ EXPORT_STAR_LIB: `Object.keys(` IDENTIFIER$1 `).forEach(function (` IDENTIFIER$2
101103
`if (` IDENTIFIER$2 `===` ( `'default'` | `"default"` ) `||` IDENTIFIER$2 `===` ( '__esModule' | `"__esModule"` ) `) return` `;`? |
102104
`if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) `)`
103105
)
106+
(
107+
`if (` IDENTIFIER$2 `in` EXPORTS_IDENTIFIER `&&` EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] ===` IDENTIFIER$1 `[` IDENTIFIER$2 `]) return` `;`?
108+
)?
104109
(
105110
EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] =` IDENTIFIER$1 `[` IDENTIFIER$2 `]` `;`? |
106111
`Object.defineProperty(` EXPORTS_IDENTIFIER `, ` IDENTIFIER$2 `, { enumerable: true, get: function () { return ` IDENTIFIER$1 `[` IDENTIFIER$2 `]` `;`? } })` `;`?
107112
)
108113
`})`
109114
```
110115

111-
* The returned export names are the matched `IDENTIFIER` and `IDENTIFIER_STRING` slots for all `EXPORTS_MEMBER`, `EXPORTS_DEFINE` and `EXPORTS_LITERAL` matches.
112-
* The reexport specifiers are taken to be the `STRING_LITERAL` slots of all `MODULE_EXPORTS_ASSIGN` as well as all _top-level_ `EXPORT_STAR` `REQUIRE` matches and `EXPORTS_ASSIGN` matches whose `IDENTIFIER` also matches the first `IDENTIFIER` in `EXPORT_STAR_LIB`.
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.
119+
* The reexport specifiers are taken to be the the combination of:
120+
1. The `REQUIRE` matches of the last matched of either `MODULE_EXPORTS_ASSIGN` or `EXPORTS_LITERAL`.
121+
2. All _top-level_ `EXPORT_STAR` `REQUIRE` matches and `EXPORTS_ASSIGN` matches whose `IDENTIFIER` also matches the first `IDENTIFIER` in `EXPORT_STAR_LIB`.
113122

114123
### Parsing Examples
115124

@@ -118,11 +127,10 @@ EXPORT_STAR_LIB: `Object.keys(` IDENTIFIER$1 `).forEach(function (` IDENTIFIER$2
118127
The basic matching rules for named exports are `exports.name`, `exports['name']` or `Object.defineProperty(exports, 'name', ...)`. This matching is done without scope analysis and regardless of the expression position:
119128

120129
```js
121-
// DETECTS EXPORTS: a, b, c
130+
// DETECTS EXPORTS: a, b
122131
(function (exports) {
123132
exports.a = 'a';
124133
exports['b'] = 'b';
125-
Object.defineProperty(exports, 'c', { value: 'c' });
126134
})(exports);
127135
```
128136

@@ -134,21 +142,32 @@ Because there is no scope analysis, the above detection may overclassify:
134142
exports.a = 'a';
135143
exports['b'] = 'b';
136144
if (false)
137-
Object.defineProperty(exports, 'c', { value: 'c' });
145+
exports.c = 'c';
138146
})(NOT_EXPORTS, NOT_OBJECT);
139147
```
140148

141149
It will in turn underclassify in cases where the identifiers are renamed:
142150

143151
```js
144152
// DETECTS: NO EXPORTS
145-
(function (e, defineProperty) {
153+
(function (e) {
146154
e.a = 'a';
147155
e['b'] = 'b';
148-
defineProperty(e, 'c', { value: 'c' });
149-
})(exports, defineProperty);
156+
})(exports);
157+
```
158+
159+
#### __esModule Detection
160+
161+
In addition, `__esModule` is detected as an export when set by `Object.defineProperty`:
162+
163+
```js
164+
// DETECTS: __esModule
165+
Object.defineProperty(exports, 'a', { value: 'a' });
166+
Object.defineProperty(exports, '__esModule', { value: true });
150167
```
151168

169+
No other named exports are detected for `defineProperty` calls in order not to trigger getters or non-enumerable properties unnecessarily.
170+
152171
#### Exports Object Assignment
153172

154173
A best-effort is made to detect `module.exports` object assignments, but because this is not a full parser, arbitrary expressions are not handled in the
@@ -160,17 +179,19 @@ Simple object definitions are supported:
160179
// DETECTS EXPORTS: a, b, c
161180
module.exports = {
162181
a,
163-
b: 'c',
164-
c: c
182+
'b': b,
183+
c: c,
184+
...d
165185
};
166186
```
167187

168-
Object properties that are not identifiers or string expressions will bail out of the object detection:
188+
Object properties that are not identifiers or string expressions will bail out of the object detection, while spreads are ignored:
169189

170190
```js
171191
// DETECTS EXPORTS: a, b
172192
module.exports = {
173193
a,
194+
...d,
174195
b: require('c'),
175196
c: "not detected since require('c') above bails the object detection"
176197
}
@@ -180,16 +201,27 @@ module.exports = {
180201

181202
#### module.exports reexport assignment
182203

183-
Any `module.exports = require('mod')` assignment is detected as a reexport:
204+
Any `module.exports = require('mod')` assignment is detected as a reexport, but only the last one is returned:
184205

185206
```js
186-
// DETECTS REEXPORTS: a, b, c
207+
// DETECTS REEXPORTS: c
187208
module.exports = require('a');
188209
(module => module.exports = require('b'))(NOT_MODULE);
189210
if (false) module.exports = require('c');
190211
```
191212

192-
As a result, the total list of exports would be inferred as the union of all of these reexported modules, which can lead to possible over-classification.
213+
This is to avoid over-classification in Webpack bundles with externals which include `module.exports = require('external')` in their source for every external dependency.
214+
215+
In exports object assignment, any spread of `require()` are detected as multiple separate reexports:
216+
217+
```js
218+
// DETECTS REEXPORTS: a, b
219+
module.exports = require('ignored');
220+
module.exports = {
221+
...require('a'),
222+
...require('b')
223+
};
224+
```
193225

194226
#### Transpiler Re-exports
195227

@@ -249,71 +281,72 @@ Current results:
249281
JS Build:
250282

251283
```
284+
--- JS Build ---
252285
Module load time
253286
> 2ms
254287
Cold Run, All Samples
255288
test/samples/*.js (3635 KiB)
256-
> 333ms
289+
> 311ms
257290
258291
Warm Runs (average of 25 runs)
259292
test/samples/angular.js (1410 KiB)
260-
> 16.48ms
293+
> 14.76ms
261294
test/samples/angular.min.js (303 KiB)
262-
> 5.36ms
295+
> 5.04ms
263296
test/samples/d3.js (553 KiB)
264-
> 8.32ms
297+
> 7.12ms
265298
test/samples/d3.min.js (250 KiB)
266-
> 4.28ms
299+
> 4ms
267300
test/samples/magic-string.js (34 KiB)
268-
> 1ms
301+
> 0.84ms
269302
test/samples/magic-string.min.js (20 KiB)
270-
> 0.36ms
303+
> 0.08ms
271304
test/samples/rollup.js (698 KiB)
272-
> 10.48ms
305+
> 9.08ms
273306
test/samples/rollup.min.js (367 KiB)
274-
> 6.64ms
307+
> 6ms
275308
276309
Warm Runs, All Samples (average of 25 runs)
277310
test/samples/*.js (3635 KiB)
278-
> 49.28ms
311+
> 41.32ms
279312
```
280313

281314
Wasm Build:
282315
```
283316
Module load time
284-
> 11ms
317+
> 10ms
285318
Cold Run, All Samples
286319
test/samples/*.js (3635 KiB)
287-
> 48ms
320+
> 47ms
288321
289322
Warm Runs (average of 25 runs)
290323
test/samples/angular.js (1410 KiB)
291-
> 12.32ms
324+
> 12.96ms
292325
test/samples/angular.min.js (303 KiB)
293-
> 3.76ms
326+
> 4ms
294327
test/samples/d3.js (553 KiB)
295-
> 6.08ms
328+
> 6.12ms
296329
test/samples/d3.min.js (250 KiB)
297-
> 3ms
330+
> 3.08ms
298331
test/samples/magic-string.js (34 KiB)
299-
> 0.24ms
332+
> 0.32ms
300333
test/samples/magic-string.min.js (20 KiB)
301334
> 0ms
302335
test/samples/rollup.js (698 KiB)
303-
> 7.2ms
336+
> 7.8ms
304337
test/samples/rollup.min.js (367 KiB)
305-
> 4.2ms
338+
> 4.64ms
306339
307340
Warm Runs, All Samples (average of 25 runs)
308341
test/samples/*.js (3635 KiB)
309-
> 33.6ms
342+
> 35.64ms
310343
```
311344

312345
### Wasm Build Steps
313346

314-
To build download the WASI SDK from https://github.com/CraneStation/wasi-sdk/releases.
347+
To build download the WASI SDK from https://github.com/WebAssembly/wasi-sdk/releases.
315348

316-
The Makefile assumes the existence of "wasi-sdk-10.0", "binaryen" and "wabt" (both optional) as sibling folders to this project.
349+
The Makefile assumes the existence of "wasi-sdk-11.0" and "wabt" (optional) as sibling folders to this project.
317350

318351
The build through the Makefile is then run via `make lib/lexer.wasm`, which can also be triggered via `npm run build-wasm` to create `dist/lexer.js`.
319352

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,9 @@ function tryParseObjectDefineOrKeys (keys) {
278278
const exportPos = ++pos;
279279
if (identifier() && source.charCodeAt(pos) === ch) {
280280
// revert for "("
281-
addExport(source.slice(exportPos, pos));
281+
const expt = source.slice(exportPos, pos);
282+
if (expt === '__esModule')
283+
addExport(expt);
282284
}
283285
}
284286
}

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": "0.4.3",
3+
"version": "0.5.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
@@ -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.3
1290+
[cjs-module-lexer]: https://github.com/guybedford/cjs-module-lexer/tree/0.5.0
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

test/fixtures/es-modules/cjs-exports.mjs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { strictEqual, deepEqual } from 'assert';
22

3-
import m, { π, z } from './exports-cases.js';
3+
import m, { π } from './exports-cases.js';
44
import * as ns from './exports-cases.js';
55

6-
deepEqual(Object.keys(ns), ['default', 'isObject', 'z', 'π']);
6+
deepEqual(Object.keys(ns), ['default', 'isObject', 'π']);
77
strictEqual(π, 'yes');
8-
strictEqual(z, 'yes');
98
strictEqual(typeof m.isObject, 'undefined');
109
strictEqual(m.π, 'yes');
1110
strictEqual(m.z, 'yes');
@@ -19,7 +18,7 @@ strictEqual(typeof m2, 'object');
1918
strictEqual(m2.default, 'the default');
2019
strictEqual(ns2.__esModule, true);
2120
strictEqual(ns2.name, 'name');
22-
deepEqual(Object.keys(ns2), ['__esModule', 'case2', 'default', 'name', 'pi']);
21+
deepEqual(Object.keys(ns2), ['__esModule', 'case2', 'default', 'name']);
2322

2423
import m3, { __esModule as __esModule3, name as name3 } from './exports-cases3.js';
2524
import * as ns3 from './exports-cases3.js';

0 commit comments

Comments
 (0)