Skip to content

Commit 1d42e9a

Browse files
authored
fix corner case in collapse_vars (#5644)
fixes #5643
1 parent 78f354b commit 1d42e9a

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

lib/compress.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3416,13 +3416,17 @@ Compressor.prototype.compress = function(node) {
34163416
if (def.references.length - def.replaced == referenced) return true;
34173417
if (!def.fixed) return false;
34183418
if (!lhs.fixed) return false;
3419+
var assigns = lhs.fixed.assigns;
34193420
var matched = 0;
34203421
if (!all(def.references, function(ref, index) {
34213422
var fixed = ref.fixed;
34223423
if (!fixed) return false;
34233424
if (fixed.to_binary || fixed.to_prefix) return false;
3424-
if (fixed === lhs.fixed) matched++;
3425-
return true;
3425+
if (fixed === lhs.fixed) {
3426+
matched++;
3427+
return true;
3428+
}
3429+
return assigns && fixed.assigns && assigns[0] !== fixed.assigns[0];
34263430
})) return false;
34273431
if (matched != referenced) return false;
34283432
verify_ref = true;

test/compress/collapse_vars.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10098,3 +10098,26 @@ issue_5638_4: {
1009810098
}
1009910099
expect_stdout: "foo 42"
1010010100
}
10101+
10102+
issue_5643: {
10103+
options = {
10104+
collapse_vars: true,
10105+
reduce_vars: true,
10106+
toplevel: true,
10107+
}
10108+
input: {
10109+
var a = 3, b;
10110+
a *= 7;
10111+
b = !!this;
10112+
console || console.log(b);
10113+
console.log(a * ++b);
10114+
}
10115+
expect: {
10116+
var a = 3, b;
10117+
a *= 7;
10118+
b = !!this;
10119+
console || console.log(b);
10120+
console.log(a * ++b);
10121+
}
10122+
expect_stdout: "42"
10123+
}

0 commit comments

Comments
 (0)