Skip to content

Commit

Permalink
fix corner case in collapse_vars (#5644)
Browse files Browse the repository at this point in the history
fixes #5643
  • Loading branch information
alexlamsl authored Sep 4, 2022
1 parent 78f354b commit 1d42e9a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
return true;
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;
Expand Down
23 changes: 23 additions & 0 deletions test/compress/collapse_vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 1d42e9a

Please sign in to comment.