Skip to content

Commit

Permalink
fix corner case in evaluate (#3559)
Browse files Browse the repository at this point in the history
fixes #3558
  • Loading branch information
alexlamsl committed Oct 31, 2019
1 parent 3797458 commit 1e9b576
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/compress.js
Expand Up @@ -2862,10 +2862,10 @@ merge(Compressor.prototype, {
case "+": return +v;
case "++":
case "--":
if (e instanceof AST_SymbolRef) {
var refs = e.definition().references;
if (refs[refs.length - 1] === e) return v;
}
if (!(e instanceof AST_SymbolRef)) return this;
var refs = e.definition().references;
if (refs[refs.length - 1] !== e) return this;
return HOP(e, "_eval") ? +(this.operator[0] + 1) + +v : v;
}
return this;
});
Expand Down
21 changes: 21 additions & 0 deletions test/compress/evaluate.js
Expand Up @@ -1838,3 +1838,24 @@ recursive_function_2: {
}
expect_stdout: "120"
}

issue_3558: {
options = {
evaluate: true,
reduce_vars: true,
toplevel: true,
}
input: {
function f(a) {
return 1 + --a;
}
console.log(f(true), f(false));
}
expect: {
function f(a) {
return 1 + --a;
}
console.log(1, 0);
}
expect_stdout: "1 0"
}

0 comments on commit 1e9b576

Please sign in to comment.