fix corner case in collapse_vars (#4875)

fixes #4874
This commit is contained in:
Alex Lam S.L
2021-04-27 01:54:02 +01:00
committed by GitHub
parent 97bd56b7e8
commit 4cccc01f3e
2 changed files with 28 additions and 0 deletions

View File

@@ -1963,6 +1963,7 @@ merge(Compressor.prototype, {
} else if (candidate instanceof AST_VarDef) {
replaced = !compressor.exposed(def) && def.references.length == def.replaced;
}
value_def.last_ref = false;
value_def.single_use = false;
}
if (replaced && !remove_candidate(candidate)) statements.splice(stat_index, 1);

View File

@@ -9030,3 +9030,30 @@ issue_4868: {
}
expect_stdout: "PASS"
}
issue_4874: {
options = {
collapse_vars: true,
evaluate: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
var a;
a = null;
(function(b) {
for (var c in b = b && b[console.log("PASS")])
console;
})(a = 42);
}
expect: {
var a;
null;
(function(b) {
for (var c in a && a[console.log("PASS")])
console;
})(a = 42);
}
expect_stdout: "PASS"
}