fix cascade of `evaluate` optimisation (#1654)
authorAlex Lam S.L <alexlamsl@gmail.com>
Fri, 24 Mar 2017 14:09:19 +0000 (22:09 +0800)
committerGitHub <noreply@github.com>
Fri, 24 Mar 2017 14:09:19 +0000 (22:09 +0800)
Operator has changed, so break out from rest of the rules.

fixes #1649

lib/compress.js
test/compress/evaluate.js

index 3804a93..e13985e 100644 (file)
@@ -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");
index e7a6c6b..7a56205 100644 (file)
@@ -789,3 +789,16 @@ unsafe_charAt_noop: {
         );
     }
 }
+
+issue_1649: {
+    options = {
+        evaluate: true,
+    }
+    input: {
+        console.log(-1 + -1);
+    }
+    expect: {
+        console.log(-2);
+    }
+    expect_stdout: "-2";
+}