fix `is_number()` on `+=` (#1714)
authorAlex Lam S.L <alexlamsl@gmail.com>
Tue, 28 Mar 2017 09:08:16 +0000 (17:08 +0800)
committerGitHub <noreply@github.com>
Tue, 28 Mar 2017 09:08:16 +0000 (17:08 +0800)
fixes #1710

lib/compress.js
test/compress/numbers.js

index e4863d9..c60f863 100644 (file)
@@ -1167,9 +1167,9 @@ merge(Compressor.prototype, {
                 && this.left.is_number(compressor)
                 && this.right.is_number(compressor);
         });
-        var assign = makePredicate("-= *= /= %= &= |= ^= <<= >>= >>>=");
         def(AST_Assign, function(compressor){
-            return assign(this.operator) || this.right.is_number(compressor);
+            return binary(this.operator.slice(0, -1))
+                || this.operator == "=" && this.right.is_number(compressor);
         });
         def(AST_Seq, function(compressor){
             return this.cdr.is_number(compressor);
index 0b40bb9..ea439ec 100644 (file)
@@ -153,3 +153,18 @@ evaluate_4: {
         );
     }
 }
+
+issue_1710: {
+    options = {
+        evaluate: true,
+    }
+    input: {
+        var x = {};
+        console.log((x += 1) + -x);
+    }
+    expect: {
+        var x = {};
+        console.log((x += 1) + -x);
+    }
+    expect_stdout: true
+}