Skip to content

Commit

Permalink
fix corner case in evaluate (#5559)
Browse files Browse the repository at this point in the history
fixes #5558
  • Loading branch information
alexlamsl committed Jul 15, 2022
1 parent 24443b6 commit 5792f30
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 26 additions & 0 deletions test/compress/evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 5792f30

Please sign in to comment.