fix corner case in reduce_vars (#4997)

fixes #4996
This commit is contained in:
Alex Lam S.L
2021-06-10 01:03:17 +01:00
committed by GitHub
parent e70b84895c
commit ce75477670
2 changed files with 49 additions and 1 deletions

View File

@@ -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) {

View File

@@ -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"
}