From: Alex Lam S.L Date: Fri, 24 Mar 2017 14:09:19 +0000 (+0800) Subject: fix cascade of `evaluate` optimisation (#1654) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=32283a0def807e0a382d4a6a23cc42e99084e1dd;p=UglifyJS.git fix cascade of `evaluate` optimisation (#1654) Operator has changed, so break out from rest of the rules. fixes #1649 --- diff --git a/lib/compress.js b/lib/compress.js index 3804a932..e13985ee 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3292,6 +3292,7 @@ merge(Compressor.prototype, { left: self.left, right: self.right.expression }); + break; } // -a + b => b - a if (self.left instanceof AST_UnaryPrefix @@ -3303,6 +3304,7 @@ merge(Compressor.prototype, { left: self.right, right: self.left.expression }); + break; } case "*": associative = compressor.option("unsafe_math"); diff --git a/test/compress/evaluate.js b/test/compress/evaluate.js index e7a6c6b7..7a562055 100644 --- a/test/compress/evaluate.js +++ b/test/compress/evaluate.js @@ -789,3 +789,16 @@ unsafe_charAt_noop: { ); } } + +issue_1649: { + options = { + evaluate: true, + } + input: { + console.log(-1 + -1); + } + expect: { + console.log(-2); + } + expect_stdout: "-2"; +}