fix corner case in reduce_vars (#4663)

fixes #4662
This commit is contained in:
Alex Lam S.L
2021-02-18 15:24:55 +00:00
committed by GitHub
parent a7bcd4d613
commit 7b4fd858ba
2 changed files with 28 additions and 1 deletions

View File

@@ -864,8 +864,12 @@ merge(Compressor.prototype, {
push_ref(d, lhs);
if (d.fixed) {
lhs.fixed = d.fixed;
if (lhs.fixed.assigns) {
lhs.fixed.assigns.push(node);
} else {
lhs.fixed.assigns = [ node ];
}
}
} else {
lhs.walk(tw);
}

View File

@@ -3251,3 +3251,26 @@ issue_4558_2: {
}
expect_stdout: "PASS"
}
issue_4662: {
options = {
evaluate: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
var a = 0;
function f(b, c) {
console.log(b, c);
}
f(++a, a = a, a);
}
expect: {
var a = 0;
(function(b, c) {
console.log(b, c);
})(++a, a = 1);
}
expect_stdout: "1 1"
}