Skip to content

Commit

Permalink
handle reexporting json default export correctly
Browse files Browse the repository at this point in the history
fixes #6700
  • Loading branch information
sokra committed Mar 20, 2018
1 parent f82beb3 commit cda226a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 11 deletions.
42 changes: 31 additions & 11 deletions lib/dependencies/HarmonyExportImportedSpecifierDependency.js
Expand Up @@ -53,25 +53,33 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
};
}

const isNotAHarmonyModule =
importedModule.buildMeta && !importedModule.buildMeta.exportsType;
const strictHarmonyModule = this.originModule.buildMeta.strictHarmonyModule;
if (name && id === "default" && isNotAHarmonyModule) {
if (strictHarmonyModule) {
return {
type: "reexport-non-harmony-default-strict",
module: importedModule,
name
};
} else {
if (name && id === "default" && importedModule.buildMeta) {
if (!importedModule.buildMeta.exportsType) {
if (strictHarmonyModule) {
return {
type: "reexport-non-harmony-default-strict",
module: importedModule,
name
};
} else {
return {
type: "reexport-non-harmony-default",
module: importedModule,
name
};
}
} else if (importedModule.buildMeta.exportsType === "named") {
return {
type: "reexport-non-harmony-default",
type: "reexport-named-default",
module: importedModule,
name
};
}
}

const isNotAHarmonyModule =
importedModule.buildMeta && !importedModule.buildMeta.exportsType;
if (name) {
// export { name as name }
if (id) {
Expand Down Expand Up @@ -209,6 +217,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
return null;

case "reexport-non-harmony-default":
case "reexport-named-default":
return {
module: mode.module,
importedNames: ["default"]
Expand Down Expand Up @@ -459,6 +468,17 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
)
);

case "reexport-named-default":
return (
"/* harmony reexport (default from named exports) */ " +
this.getReexportStatement(
module,
module.isUsed(mode.name),
importVar,
""
)
);

case "reexport-fake-namespace-object":
return (
"/* harmony reexport (fake namespace object from non-harmony) */ " +
Expand Down
3 changes: 3 additions & 0 deletions test/cases/scope-hoisting/json-reexport-6700/a.json
@@ -0,0 +1,3 @@
{
"a": "A"
}
3 changes: 3 additions & 0 deletions test/cases/scope-hoisting/json-reexport-6700/b.json
@@ -0,0 +1,3 @@
{
"b": "B"
}
9 changes: 9 additions & 0 deletions test/cases/scope-hoisting/json-reexport-6700/index.js
@@ -0,0 +1,9 @@
import { a, b, aa, bb } from './json.js'

it("should reexport json data correctly", () => {
aa.should.be.eql({ a: "A" });
bb.should.be.eql({ b: "B" });
a.should.be.eql("A");
b.should.be.eql("B");
});

11 changes: 11 additions & 0 deletions test/cases/scope-hoisting/json-reexport-6700/json.js
@@ -0,0 +1,11 @@
import aa from './a.json';

export { aa };

export { default as bb } from './b.json';

import { a } from './a.json';

export { a };

export { b } from './b.json';

0 comments on commit cda226a

Please sign in to comment.