fix corner case in evaluate (#5559)

fixes #5558
This commit is contained in:
Alex Lam S.L
2022-07-15 13:36:52 +01:00
committed by GitHub
parent 24443b6764
commit 5792f30175
2 changed files with 27 additions and 0 deletions

View File

@@ -5030,6 +5030,7 @@ Compressor.prototype.compress = function(node) {
if (def.undeclared) return this;
if (def.last_ref !== lhs) return this;
if (def.single_use == "m") return this;
if (this.right.has_side_effects(compressor)) return this;
}
}
var op = this.operator;

View File

@@ -3390,3 +3390,29 @@ issue_5380: {
}
expect_stdout: "PASS"
}
issue_5558: {
options = {
collapse_vars: true,
evaluate: true,
reduce_vars: true,
sequences: true,
toplevel: true,
}
input: {
var a = 99, b = 0;
a++;
b++;
b += a;
b *= a;
b += a;
console.log(a);
}
expect: {
var a = 99, b = 0;
b++,
b = (b += ++a) * a + a,
console.log(a);
}
expect_stdout: "100"
}