Skip to content

Commit

Permalink
Merge pull request #11244 from webpack/bugfix/dynamic-reexport-default
Browse files Browse the repository at this point in the history
ignore default export when reexporting a dynamic module
  • Loading branch information
sokra committed Jul 30, 2020
2 parents 91e81c8 + 46304c8 commit 7895778
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/dependencies/HarmonyExportImportedSpecifierDependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
const mode = new ExportMode("dynamic-reexport");
mode.module = importedModule;
mode.ignored = new Set([
"default",
...this.activeExports,
...activeFromOtherStarExports
]);
Expand Down Expand Up @@ -586,18 +587,18 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
.join("");

case "dynamic-reexport": {
const activeExports = mode.ignored;
const ignoredExports = mode.ignored;
let content =
"/* harmony reexport (unknown) */ for(var __WEBPACK_IMPORT_KEY__ in " +
importVar +
") ";

// Filter out exports which are defined by other exports
// and filter out default export because it cannot be reexported with *
if (activeExports.size > 0) {
if (ignoredExports.size > 0) {
content +=
"if(" +
JSON.stringify(Array.from(activeExports).concat("default")) +
JSON.stringify(Array.from(ignoredExports)) +
".indexOf(__WEBPACK_IMPORT_KEY__) < 0) ";
} else {
content += "if(__WEBPACK_IMPORT_KEY__ !== 'default') ";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Object(exports).default = "dynamic";
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./dynamic";
export default "static";
12 changes: 11 additions & 1 deletion test/cases/side-effects/dynamic-reexports/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { value as valueStatic } from "./dedupe-target-static";
import { value } from "./dedupe-target";
import * as DefaultExport from "./default-export";
import { value as valueDirect, value2 as value2Direct } from "./direct-export";
import {
value as valueDirect,
value2 as value2Direct,
default as Default1
} from "./direct-export";
import {
value as valueChecked,
value2 as value2Checked
} from "./checked-export";
import Default2 from "./dynamic-reexport-default";

it("should dedupe static reexport target", () => {
expect(valueStatic).toBe(42);
Expand Down Expand Up @@ -36,3 +41,8 @@ it("should handle checked dynamic export when reexporting", () => {
expect(valueChecked).toBe(42);
expect(value2Checked).toBe(42);
});

it("should handle default export correctly", () => {
expect(Default1).toBe(undefined);
expect(Default2).toBe("static");
});

0 comments on commit 7895778

Please sign in to comment.