File tree Expand file tree Collapse file tree 5 files changed +46
-1
lines changed
test/configCases/defer-import/import-attributes Expand file tree Collapse file tree 5 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -949,7 +949,16 @@ class RuntimeTemplate {
949
949
// when the defaultInterop is used (when a ESM imports a CJS module),
950
950
if ( exportName . length > 0 && exportName [ 0 ] === "default" ) {
951
951
if ( isDeferred && exportsType !== "namespace" ) {
952
- const access = `${ importVar } .a${ propertyAccess ( exportName , 1 ) } ` ;
952
+ const exportsInfo = moduleGraph . getExportsInfo ( module ) ;
953
+ const name = exportName . slice ( 1 ) ;
954
+ const used = exportsInfo . getUsedName ( name , runtime ) ;
955
+ if ( ! used ) {
956
+ const comment = Template . toNormalComment (
957
+ `unused export ${ propertyAccess ( exportName ) } `
958
+ ) ;
959
+ return `${ comment } undefined` ;
960
+ }
961
+ const access = `${ importVar } .a${ propertyAccess ( used ) } ` ;
953
962
if ( isCall || asiSafe === undefined ) {
954
963
return access ;
955
964
}
Original file line number Diff line number Diff line change
1
+ {
2
+ "foo": "bar",
3
+ "nested": { "foo": "bar" }
4
+ }
Original file line number Diff line number Diff line change
1
+ import defer * as mod1 from "./file.ext" with { type : "bytes" } ;
2
+ import defer * as mod2 from "./file.ext" with { type : "json" } ;
3
+ import * as mod3 from "./file.ext" with { type : "bytes" } ;
4
+ import * as mod4 from "./file.ext" with { type : "json" } ;
5
+
6
+ it ( "should work with defer and import attributes" , ( ) => {
7
+ const decoder = new TextDecoder ( 'utf-8' ) ;
8
+ const mod1Decoded = JSON . parse ( decoder . decode ( mod1 . default ) ) ;
9
+ expect ( mod1Decoded . foo ) . toBe ( "bar" ) ;
10
+ expect ( mod1Decoded . nested . foo ) . toBe ( "bar" ) ;
11
+ expect ( mod2 . default . foo ) . toBe ( "bar" ) ;
12
+ expect ( mod2 . default . nested . foo ) . toBe ( "bar" ) ;
13
+ const mod2Decoded = JSON . parse ( decoder . decode ( mod3 . default ) ) ;
14
+ expect ( mod2Decoded . foo ) . toBe ( "bar" ) ;
15
+ expect ( mod2Decoded . nested . foo ) . toBe ( "bar" ) ;
16
+ expect ( mod4 . default . foo ) . toBe ( "bar" ) ;
17
+ expect ( mod4 . default . nested . foo ) . toBe ( "bar" ) ;
18
+ } ) ;
Original file line number Diff line number Diff line change
1
+ "use strict" ;
2
+
3
+ const supportsTextDecoder = require ( "../../../helpers/supportsTextDecoder" ) ;
4
+
5
+ module . exports = ( ) => supportsTextDecoder ( ) ;
Original file line number Diff line number Diff line change
1
+ "use strict" ;
2
+
3
+ /** @type {import("../../../../").Configuration } */
4
+ module . exports = {
5
+ target : [ `async-node${ process . versions . node . split ( "." ) . map ( Number ) [ 0 ] } ` ] ,
6
+ experiments : {
7
+ deferImport : true
8
+ }
9
+ } ;
You can’t perform that action at this time.
0 commit comments