From 32283a0def807e0a382d4a6a23cc42e99084e1dd Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Fri, 24 Mar 2017 22:09:19 +0800 Subject: [PATCH] fix cascade of `evaluate` optimisation (#1654) Operator has changed, so break out from rest of the rules. fixes #1649 --- lib/compress.js | 2 ++ test/compress/evaluate.js | 13 +++++++++++++ 2 files changed, 15 insertions(+) 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"; +} -- 2.34.1