avoid `evaluate` of compound assignment after `dead_code` transform (#2861)
authorAlex Lam S.L <alexlamsl@gmail.com>
Thu, 1 Feb 2018 08:18:29 +0000 (16:18 +0800)
committerGitHub <noreply@github.com>
Thu, 1 Feb 2018 08:18:29 +0000 (16:18 +0800)
fixes #2860

lib/compress.js
test/compress/dead-code.js
test/compress/reduce_vars.js

index 9a3446c..b4d13ec 100644 (file)
@@ -5358,6 +5358,7 @@ merge(Compressor.prototype, {
                     if (in_try(level, parent instanceof AST_Throw)) break;
                     if (is_reachable(def.scope, [ def ])) break;
                     if (self.operator == "=") return self.right;
+                    def.fixed = false;
                     return make_node(AST_Binary, self, {
                         operator: self.operator.slice(0, -1),
                         left: self.left,
index b66d5ac..9b45fe8 100644 (file)
@@ -879,3 +879,41 @@ unsafe_builtin: {
         z;
     }
 }
+
+issue_2860_1: {
+    options = {
+        dead_code: true,
+        evaluate: true,
+        reduce_vars: true,
+    }
+    input: {
+        console.log(function(a) {
+            return a ^= 1;
+        }());
+    }
+    expect: {
+        console.log(function(a) {
+            return 1 ^ a;
+        }());
+    }
+    expect_stdout: "1"
+}
+
+issue_2860_2: {
+    options = {
+        dead_code: true,
+        evaluate: true,
+        inline: true,
+        passes: 2,
+        reduce_vars: true,
+    }
+    input: {
+        console.log(function(a) {
+            return a ^= 1;
+        }());
+    }
+    expect: {
+        console.log(1);
+    }
+    expect_stdout: "1"
+}
index 2e562f9..761af9e 100644 (file)
@@ -5467,3 +5467,43 @@ chained_assignments: {
     }
     expect_stdout: "5eadbeef"
 }
+
+issue_2860_1: {
+    options = {
+        dead_code: true,
+        evaluate: true,
+        reduce_vars: true,
+    }
+    input: {
+        console.log(function(a) {
+            return a ^= 1;
+            a ^= 2;
+        }());
+    }
+    expect: {
+        console.log(function(a) {
+            return 1 ^ a;
+        }());
+    }
+    expect_stdout: "1"
+}
+
+issue_2860_2: {
+    options = {
+        dead_code: true,
+        evaluate: true,
+        inline: true,
+        passes: 2,
+        reduce_vars: true,
+    }
+    input: {
+        console.log(function(a) {
+            return a ^= 1;
+            a ^= 2;
+        }());
+    }
+    expect: {
+        console.log(1);
+    }
+    expect_stdout: "1"
+}