fix corner case in collapse_vars (#5644)

fixes #5643
This commit is contained in:
Alex Lam S.L
2022-09-04 03:10:31 +01:00
committed by GitHub
parent 78f354beb8
commit 1d42e9ad55
2 changed files with 29 additions and 2 deletions

View File

@@ -3416,13 +3416,17 @@ Compressor.prototype.compress = function(node) {
if (def.references.length - def.replaced == referenced) return true;
if (!def.fixed) return false;
if (!lhs.fixed) return false;
var assigns = lhs.fixed.assigns;
var matched = 0;
if (!all(def.references, function(ref, index) {
var fixed = ref.fixed;
if (!fixed) return false;
if (fixed.to_binary || fixed.to_prefix) return false;
if (fixed === lhs.fixed) matched++;
if (fixed === lhs.fixed) {
matched++;
return true;
}
return assigns && fixed.assigns && assigns[0] !== fixed.assigns[0];
})) return false;
if (matched != referenced) return false;
verify_ref = true;

View File

@@ -10098,3 +10098,26 @@ issue_5638_4: {
}
expect_stdout: "foo 42"
}
issue_5643: {
options = {
collapse_vars: true,
reduce_vars: true,
toplevel: true,
}
input: {
var a = 3, b;
a *= 7;
b = !!this;
console || console.log(b);
console.log(a * ++b);
}
expect: {
var a = 3, b;
a *= 7;
b = !!this;
console || console.log(b);
console.log(a * ++b);
}
expect_stdout: "42"
}