Skip to content

Commit

Permalink
fix crash when __esModule is called with defineProperty without value
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Nov 18, 2020
1 parent 3471c77 commit 5c8c0e3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dependencies/CommonJsExportsParserPlugin.js
Expand Up @@ -100,7 +100,7 @@ class CommonJsExportsParserPlugin {
const checkNamespace = (topLevel, members, valueExpr) => {
if (!DynamicExports.isEnabled(parser.state)) return;
if (members.length > 0 && members[0] === "__esModule") {
if (isTruthyLiteral(valueExpr) && topLevel) {
if (valueExpr && isTruthyLiteral(valueExpr) && topLevel) {
DynamicExports.setFlagged(parser.state);
} else {
DynamicExports.setDynamic(parser.state);
Expand Down
15 changes: 15 additions & 0 deletions test/cases/cjs-tree-shaking/esModule-getter/index.js
@@ -0,0 +1,15 @@
import def, { named, __esModule } from "./module";
import * as ns from "./module";

it("should allow to import module with getters", () => {
expect(def).toBe("default");
expect(named).toBe("named");
expect(__esModule).toBe(true);
expect(ns.default).toBe("default");
expect(ns.named).toBe("named");
expect(ns.__esModule).toBe(true);
const indirect = Object(ns);
expect(indirect.default).toBe("default");
expect(indirect.named).toBe("named");
expect(indirect.__esModule).toBe(true);
});
3 changes: 3 additions & 0 deletions test/cases/cjs-tree-shaking/esModule-getter/module.js
@@ -0,0 +1,3 @@
Object.defineProperty(exports, "__esModule", { get: () => true });
Object.defineProperty(exports, "default", { get: () => "default" });
Object.defineProperty(exports, "named", { get: () => "named" });

0 comments on commit 5c8c0e3

Please sign in to comment.