Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore default export when reexporting a dynamic module #11244

Merged
merged 1 commit into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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");
});