@@ -70,31 +70,35 @@ STRING_LITERAL: A `"` or `'` bounded ECMA-262 string literal.
7070
7171IDENTIFIER_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
7775EXPORTS_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
8785EXPORTS_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
9599EXPORTS_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
99103EXPORT_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' });
166186Object .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:
281334JS Build:
282335
283336```
284- --- JS Build ---
285337Module load time
286- > 2ms
338+ > 5ms
287339Cold Run, All Samples
288340test/samples/*.js (3635 KiB)
289- > 311ms
341+ > 323ms
290342
291343Warm Runs (average of 25 runs)
292344test/samples/angular.js (1410 KiB)
293- > 14.76ms
345+ > 14.84ms
294346test/samples/angular.min.js (303 KiB)
295- > 5.04ms
347+ > 4.8ms
296348test/samples/d3.js (553 KiB)
297- > 7.12ms
349+ > 7.84ms
298350test/samples/d3.min.js (250 KiB)
299351> 4ms
300352test/samples/magic-string.js (34 KiB)
301- > 0.84ms
353+ > 0.72ms
302354test/samples/magic-string.min.js (20 KiB)
303- > 0.08ms
355+ > 0.4ms
304356test/samples/rollup.js (698 KiB)
305- > 9.08ms
357+ > 9.32ms
306358test/samples/rollup.min.js (367 KiB)
307- > 6ms
359+ > 6.52ms
308360
309361Warm Runs, All Samples (average of 25 runs)
310362test/samples/*.js (3635 KiB)
311- > 41.32ms
363+ > 44ms
312364```
313365
314366Wasm Build:
315367```
316368Module load time
317- > 10ms
369+ > 11ms
318370Cold Run, All Samples
319371test/samples/*.js (3635 KiB)
320- > 47ms
372+ > 42ms
321373
322374Warm Runs (average of 25 runs)
323375test/samples/angular.js (1410 KiB)
324- > 12.96ms
376+ > 9.92ms
325377test/samples/angular.min.js (303 KiB)
326- > 4ms
378+ > 3.2ms
327379test/samples/d3.js (553 KiB)
328- > 6.12ms
380+ > 5.2ms
329381test/samples/d3.min.js (250 KiB)
330- > 3.08ms
382+ > 2.52ms
331383test/samples/magic-string.js (34 KiB)
332- > 0.32ms
384+ > 0.16ms
333385test/samples/magic-string.min.js (20 KiB)
334- > 0ms
386+ > 0.04ms
335387test/samples/rollup.js (698 KiB)
336- > 7.8ms
388+ > 6.44ms
337389test/samples/rollup.min.js (367 KiB)
338- > 4.64ms
390+ > 3.96ms
339391
340392Warm Runs, All Samples (average of 25 runs)
341393test/samples/*.js (3635 KiB)
342- > 35.64ms
394+ > 30.48ms
343395```
344396
345397### Wasm Build Steps
0 commit comments