Skip to content

Commit

Permalink
unused values should be null to support super classes
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Oct 27, 2020
1 parent f2ed7ca commit f07f64b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
12 changes: 8 additions & 4 deletions lib/dependencies/PureExpressionDependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ PureExpressionDependency.Template = class PureExpressionDependencyTemplate exten
) {
const dep = /** @type {PureExpressionDependency} */ (dependency);

let condition = "null";

const usedByExports = dep.usedByExports;
if (usedByExports !== false) {
const selfModule = moduleGraph.getParentModule(dep);
Expand All @@ -98,18 +96,24 @@ PureExpressionDependency.Template = class PureExpressionDependencyTemplate exten
});
if (runtimeCondition === true) return;
if (runtimeCondition !== false) {
condition = runtimeTemplate.runtimeConditionExpression({
const condition = runtimeTemplate.runtimeConditionExpression({
chunkGraph,
runtime,
runtimeCondition,
runtimeRequirements
});
source.insert(
dep.range[0],
`(/* runtime-dependent pure expression or super */ ${condition} ? (`
);
source.insert(dep.range[1], ") : null)");
return;
}
}

source.insert(
dep.range[0],
`(/* unused pure expression or super */ ${condition} && (`
`(/* unused pure expression or super */ null && (`
);
source.insert(dep.range[1], "))");
}
Expand Down
4 changes: 3 additions & 1 deletion test/configCases/graph/issue-11770/b.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { other, val2c } from "./shared";
import { other, val2c, Test } from "./shared";

it("should have the correct value", () => {
expect(other).toBe("other");
expect(val2c).toBe(42);
expect(Test).toBeTypeOf("function");
expect(new Test()).toBeInstanceOf(Test);
});
3 changes: 3 additions & 0 deletions test/configCases/graph/issue-11770/shared.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import value from "./dep";
import value2 from "./dep2";
import Super from "./super";

const derived = value;

Expand All @@ -10,3 +11,5 @@ export const val2b = value2;
export const val2c = value2;

export const other = "other";

export class Test extends Super {}
1 change: 1 addition & 0 deletions test/configCases/graph/issue-11770/super.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default class Super {}

0 comments on commit f07f64b

Please sign in to comment.