@@ -70,31 +70,35 @@ STRING_LITERAL: A `"` or `'` bounded ECMA-262 string literal.
70
70
71
71
IDENTIFIER_STRING: ( `"` IDENTIFIER `"` | `'` IDENTIFIER `'` )
72
72
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`
76
74
77
75
EXPORTS_IDENTIFIER: MODULE_EXPORTS_IDENTIFIER | `exports`
78
76
79
- EXPORTS_DOT_ASSIGN: EXPORTS_IDENTIFIER COMMENT_SPACE `.` COMMENT_SPACE IDENTIFIER COMMENT_SPACE `=`
77
+ EXPORTS_DOT_ASSIGN: EXPORTS_IDENTIFIER `.` IDENTIFIER `=`
80
78
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 `]` `=`
82
80
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)
84
82
85
- EXPORTS_SPREAD: `...` COMMENT_SPACE (IDENTIFIER | REQUIRE)
83
+ EXPORTS_SPREAD: `...` (IDENTIFIER | REQUIRE)
86
84
87
85
EXPORTS_MEMBER: EXPORTS_DOT_ASSIGN | EXPORTS_LITERAL_COMPUTED_ASSIGN
88
86
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
+ `})`
90
94
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) `,`)+ `}`
92
96
93
- REQUIRE: `require` COMMENT_SPACE `(` COMMENT_SPACE STRING_LITERAL COMMENT_SPACE `)`
97
+ REQUIRE: `require` `(` STRING_LITERAL `)`
94
98
95
99
EXPORTS_ASSIGN: (`var` | `const` | `let`) IDENTIFIER `=` REQUIRE
96
100
97
- MODULE_EXPORTS_ASSIGN: MODULE_EXPORTS COMMENT_SPACE `=` COMMENT_SPACE REQUIRE
101
+ MODULE_EXPORTS_ASSIGN: MODULE_EXPORTS `=` REQUIRE
98
102
99
103
EXPORT_STAR: (`__export` | `__exportStar`) `(` REQUIRE
100
104
@@ -113,9 +117,9 @@ EXPORT_STAR_LIB: `Object.keys(` IDENTIFIER$1 `).forEach(function (` IDENTIFIER$2
113
117
`})`
114
118
```
115
119
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 .
119
123
* The reexport specifiers are taken to be the the combination of:
120
124
1 . The ` REQUIRE ` matches of the last matched of either ` MODULE_EXPORTS_ASSIGN ` or ` EXPORTS_LITERAL ` .
121
125
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:
156
160
})(exports );
157
161
```
158
162
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:
162
164
163
165
``` 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' });
166
186
Object .defineProperty (exports , ' __esModule' , { value: true });
167
187
```
168
188
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.
170
223
171
224
#### Exports Object Assignment
172
225
@@ -281,65 +334,64 @@ Current results:
281
334
JS Build:
282
335
283
336
```
284
- --- JS Build ---
285
337
Module load time
286
- > 2ms
338
+ > 5ms
287
339
Cold Run, All Samples
288
340
test/samples/*.js (3635 KiB)
289
- > 311ms
341
+ > 323ms
290
342
291
343
Warm Runs (average of 25 runs)
292
344
test/samples/angular.js (1410 KiB)
293
- > 14.76ms
345
+ > 14.84ms
294
346
test/samples/angular.min.js (303 KiB)
295
- > 5.04ms
347
+ > 4.8ms
296
348
test/samples/d3.js (553 KiB)
297
- > 7.12ms
349
+ > 7.84ms
298
350
test/samples/d3.min.js (250 KiB)
299
351
> 4ms
300
352
test/samples/magic-string.js (34 KiB)
301
- > 0.84ms
353
+ > 0.72ms
302
354
test/samples/magic-string.min.js (20 KiB)
303
- > 0.08ms
355
+ > 0.4ms
304
356
test/samples/rollup.js (698 KiB)
305
- > 9.08ms
357
+ > 9.32ms
306
358
test/samples/rollup.min.js (367 KiB)
307
- > 6ms
359
+ > 6.52ms
308
360
309
361
Warm Runs, All Samples (average of 25 runs)
310
362
test/samples/*.js (3635 KiB)
311
- > 41.32ms
363
+ > 44ms
312
364
```
313
365
314
366
Wasm Build:
315
367
```
316
368
Module load time
317
- > 10ms
369
+ > 11ms
318
370
Cold Run, All Samples
319
371
test/samples/*.js (3635 KiB)
320
- > 47ms
372
+ > 42ms
321
373
322
374
Warm Runs (average of 25 runs)
323
375
test/samples/angular.js (1410 KiB)
324
- > 12.96ms
376
+ > 9.92ms
325
377
test/samples/angular.min.js (303 KiB)
326
- > 4ms
378
+ > 3.2ms
327
379
test/samples/d3.js (553 KiB)
328
- > 6.12ms
380
+ > 5.2ms
329
381
test/samples/d3.min.js (250 KiB)
330
- > 3.08ms
382
+ > 2.52ms
331
383
test/samples/magic-string.js (34 KiB)
332
- > 0.32ms
384
+ > 0.16ms
333
385
test/samples/magic-string.min.js (20 KiB)
334
- > 0ms
386
+ > 0.04ms
335
387
test/samples/rollup.js (698 KiB)
336
- > 7.8ms
388
+ > 6.44ms
337
389
test/samples/rollup.min.js (367 KiB)
338
- > 4.64ms
390
+ > 3.96ms
339
391
340
392
Warm Runs, All Samples (average of 25 runs)
341
393
test/samples/*.js (3635 KiB)
342
- > 35.64ms
394
+ > 30.48ms
343
395
```
344
396
345
397
### Wasm Build Steps
0 commit comments