diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-03-24 22:09:19 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-24 22:09:19 +0800 |
commit | 32283a0def807e0a382d4a6a23cc42e99084e1dd (patch) | |
tree | 9f5663a80419d4438b2474a2e5af48fc86d4b550 | |
parent | ac51d4c5a079dccbc9a6cf69d06f757432c69694 (diff) | |
download | tracifyjs-32283a0def807e0a382d4a6a23cc42e99084e1dd.tar.gz tracifyjs-32283a0def807e0a382d4a6a23cc42e99084e1dd.zip |
fix cascade of `evaluate` optimisation (#1654)
Operator has changed, so break out from rest of the rules.
fixes #1649
-rw-r--r-- | lib/compress.js | 2 | ||||
-rw-r--r-- | test/compress/evaluate.js | 13 |
2 files changed, 15 insertions, 0 deletions
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"; +} |