Skip to content

Commit

Permalink
fix corner case in reduce_vars (#4997)
Browse files Browse the repository at this point in the history
fixes #4996
  • Loading branch information
alexlamsl committed Jun 10, 2021
1 parent e70b848 commit ce75477
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,11 @@ merge(Compressor.prototype, {
var safe = tw.safe_ids[def.id];
if (!HOP(tw.safe_ids, def.id)) {
if (!safe) return false;
if (safe.read && def.scope.resolve() !== tw.find_parent(AST_Scope)) return false;
if (safe.read) {
var scope = tw.find_parent(AST_BlockScope);
if (scope instanceof AST_Class) return false;
if (def.scope.resolve() !== scope.resolve()) return false;
}
safe.assign = safe.assign && safe.assign !== tw.safe_ids ? true : tw.safe_ids;
}
if (def.fixed != null && safe.read) {
Expand Down
44 changes: 44 additions & 0 deletions test/compress/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1748,3 +1748,47 @@ issue_4992: {
expect_stdout: "function"
node_version: ">=12"
}

issue_4996_1: {
options = {
evaluate: true,
reduce_vars: true,
toplevel: true,
}
input: {
var a = 1;
console.log(new class A {
p = a-- && new A();
}().p.p);
}
expect: {
var a = 1;
console.log(new class A {
p = a-- && new A();
}().p.p);
}
expect_stdout: "0"
node_version: ">=12"
}

issue_4996_2: {
options = {
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
var a = 1;
console.log(new class A {
p = a-- && new A();
}().p.p);
}
expect: {
var a = 1;
console.log(new class A {
p = a-- && new A();
}().p.p);
}
expect_stdout: "0"
node_version: ">=12"
}

0 comments on commit ce75477

Please sign in to comment.