Commit 95bb728 1 parent dc6a4d8 commit 95bb728 Copy full SHA for 95bb728
File tree 6 files changed +93
-3
lines changed
module-side-effects-late-entry
module-side-effects-late-entry-strict
6 files changed +93
-3
lines changed Original file line number Diff line number Diff line change
1
+ const path = require ( 'path' ) ;
2
+ const assert = require ( 'assert' ) ;
3
+
4
+ let referenceId ;
5
+ const testEntry = 'generated-foo.js' ;
6
+
7
+ module . exports = {
8
+ description :
9
+ 'use correct side-effects flags for files that become entry points after they are loaded (strictRequires: true)' ,
10
+ testEntry,
11
+ options : {
12
+ treeshake : { moduleSideEffects : false } ,
13
+ plugins : [
14
+ {
15
+ name : 'test' ,
16
+ load ( id ) {
17
+ if ( id . endsWith ( 'foo.js' ) ) {
18
+ referenceId = this . emitFile ( { type : 'chunk' , id : path . join ( __dirname , 'foo.js' ) } ) ;
19
+ }
20
+ } ,
21
+ generateBundle ( ) {
22
+ assert . strictEqual ( this . getFileName ( referenceId ) , testEntry ) ;
23
+ } ,
24
+ moduleParsed ( { id, code } ) {
25
+ console . log ( '\n===' , id ) ;
26
+ console . log ( code ) ;
27
+ }
28
+ }
29
+ ] ,
30
+ output : { chunkFileNames : 'generated-[name].js' }
31
+ } ,
32
+ pluginOptions : {
33
+ strictRequires : true
34
+ } ,
35
+ global : ( global , t ) => {
36
+ t . is ( global . foo , 'foo' ) ;
37
+ }
38
+ } ;
Original file line number Diff line number Diff line change
1
+ // This side-effect will only be respected if this is an entry point
2
+ global . foo = 'foo' ;
Original file line number Diff line number Diff line change
1
+ import './foo.js' ;
2
+
3
+ export default 'main' ;
Original file line number Diff line number Diff line change 1
1
const path = require ( 'path' ) ;
2
+ const assert = require ( 'assert' ) ;
3
+
4
+ let referenceId ;
5
+ const testEntry = 'generated-foo2.js' ;
2
6
3
7
module . exports = {
4
8
description :
5
- 'use correct side-effects flags for files that become entry points after they are loaded (strictRequires: "auto")' ,
9
+ 'use correct side-effects flags for files that become entry points after they are loaded (strictRequires: false)' ,
10
+ testEntry,
6
11
options : {
7
12
treeshake : { moduleSideEffects : false } ,
8
13
plugins : [
9
14
{
15
+ name : 'test' ,
10
16
load ( id ) {
11
17
if ( id . endsWith ( 'foo.js' ) ) {
12
- this . emitFile ( { type : 'chunk' , id : path . join ( __dirname , 'foo.js' ) } ) ;
18
+ referenceId = this . emitFile ( { type : 'chunk' , id : path . join ( __dirname , 'foo.js' ) } ) ;
13
19
}
20
+ } ,
21
+ generateBundle ( ) {
22
+ assert . strictEqual ( this . getFileName ( referenceId ) , testEntry ) ;
14
23
}
15
24
}
16
25
] ,
17
26
output : { chunkFileNames : 'generated-[name].js' }
18
27
} ,
19
28
pluginOptions : {
20
- strictRequires : 'auto'
29
+ strictRequires : false
21
30
} ,
22
31
global : ( global , t ) => {
23
32
t . is ( global . foo , 'foo' ) ;
Original file line number Diff line number Diff line change @@ -6575,6 +6575,44 @@ Generated by [AVA](https://avajs.dev).
6575
6575
`,
6576
6576
}
6577
6577
6578
+ ## module-side-effects-late-entry-strict
6579
+
6580
+ > Snapshot 1
6581
+
6582
+ {
6583
+ 'generated-foo.js': `'use strict';β
6584
+ β
6585
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};β
6586
+ β
6587
+ function getDefaultExportFromCjs (x) {β
6588
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;β
6589
+ }β
6590
+ β
6591
+ var foo$1 = {};β
6592
+ β
6593
+ var hasRequiredFoo;β
6594
+ β
6595
+ function requireFoo () {β
6596
+ if (hasRequiredFoo) return foo$1;β
6597
+ hasRequiredFoo = 1;β
6598
+ // This side-effect will only be respected if this is an entry pointβ
6599
+ commonjsGlobal.foo = 'foo';β
6600
+ return foo$1;β
6601
+ }β
6602
+ β
6603
+ var fooExports = requireFoo();β
6604
+ var foo = /*@__PURE__*/getDefaultExportFromCjs(fooExports);β
6605
+ β
6606
+ module.exports = foo;β
6607
+ `,
6608
+ 'main.js': `'use strict';β
6609
+ β
6610
+ var main = 'main';β
6611
+ β
6612
+ module.exports = main;β
6613
+ `,
6614
+ }
6615
+
6578
6616
## module_require
6579
6617
6580
6618
> Snapshot 1
You canβt perform that action at this time.
0 commit comments