Skip to content

Commit c6b9b9e

Browse files
authored
Merge pull request webpack#6806 from webpack/bugfix/json-reexport
handle reexporting json default export correctly
2 parents f82beb3 + cda226a commit c6b9b9e

File tree

5 files changed

+57
-11
lines changed

5 files changed

+57
-11
lines changed

lib/dependencies/HarmonyExportImportedSpecifierDependency.js

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,33 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
5353
};
5454
}
5555

56-
const isNotAHarmonyModule =
57-
importedModule.buildMeta && !importedModule.buildMeta.exportsType;
5856
const strictHarmonyModule = this.originModule.buildMeta.strictHarmonyModule;
59-
if (name && id === "default" && isNotAHarmonyModule) {
60-
if (strictHarmonyModule) {
61-
return {
62-
type: "reexport-non-harmony-default-strict",
63-
module: importedModule,
64-
name
65-
};
66-
} else {
57+
if (name && id === "default" && importedModule.buildMeta) {
58+
if (!importedModule.buildMeta.exportsType) {
59+
if (strictHarmonyModule) {
60+
return {
61+
type: "reexport-non-harmony-default-strict",
62+
module: importedModule,
63+
name
64+
};
65+
} else {
66+
return {
67+
type: "reexport-non-harmony-default",
68+
module: importedModule,
69+
name
70+
};
71+
}
72+
} else if (importedModule.buildMeta.exportsType === "named") {
6773
return {
68-
type: "reexport-non-harmony-default",
74+
type: "reexport-named-default",
6975
module: importedModule,
7076
name
7177
};
7278
}
7379
}
7480

81+
const isNotAHarmonyModule =
82+
importedModule.buildMeta && !importedModule.buildMeta.exportsType;
7583
if (name) {
7684
// export { name as name }
7785
if (id) {
@@ -209,6 +217,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
209217
return null;
210218

211219
case "reexport-non-harmony-default":
220+
case "reexport-named-default":
212221
return {
213222
module: mode.module,
214223
importedNames: ["default"]
@@ -459,6 +468,17 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
459468
)
460469
);
461470

471+
case "reexport-named-default":
472+
return (
473+
"/* harmony reexport (default from named exports) */ " +
474+
this.getReexportStatement(
475+
module,
476+
module.isUsed(mode.name),
477+
importVar,
478+
""
479+
)
480+
);
481+
462482
case "reexport-fake-namespace-object":
463483
return (
464484
"/* harmony reexport (fake namespace object from non-harmony) */ " +
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"a": "A"
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"b": "B"
3+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { a, b, aa, bb } from './json.js'
2+
3+
it("should reexport json data correctly", () => {
4+
aa.should.be.eql({ a: "A" });
5+
bb.should.be.eql({ b: "B" });
6+
a.should.be.eql("A");
7+
b.should.be.eql("B");
8+
});
9+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import aa from './a.json';
2+
3+
export { aa };
4+
5+
export { default as bb } from './b.json';
6+
7+
import { a } from './a.json';
8+
9+
export { a };
10+
11+
export { b } from './b.json';

0 commit comments

Comments
 (0)