fix `reduce_vars` on conditionals (#1822)
authorAlex Lam S.L <alexlamsl@gmail.com>
Mon, 17 Apr 2017 17:44:23 +0000 (01:44 +0800)
committerGitHub <noreply@github.com>
Mon, 17 Apr 2017 17:44:23 +0000 (01:44 +0800)
lib/compress.js
test/compress/reduce_vars.js

index f49dd60..0dfe2a3 100644 (file)
@@ -348,6 +348,16 @@ merge(Compressor.prototype, {
                     pop();
                     return true;
                 }
+                if (node instanceof AST_Conditional) {
+                    node.condition.walk(tw);
+                    push();
+                    node.consequent.walk(tw);
+                    pop();
+                    push();
+                    node.alternative.walk(tw);
+                    pop();
+                    return true;
+                }
                 if (node instanceof AST_If) {
                     node.condition.walk(tw);
                     push();
index 94d37cb..ad2c90b 100644 (file)
@@ -2240,3 +2240,26 @@ boolean_binary_assign: {
     }
     expect_stdout: "undefined"
 }
+
+cond_assign: {
+    options = {
+        evaluate: true,
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        !function() {
+            var a;
+            void 0 ? (a = 1) : 0;
+            console.log(a);
+        }();
+    }
+    expect: {
+        !function() {
+            var a;
+            void 0 ? (a = 1) : 0;
+            console.log(a);
+        }();
+    }
+    expect_stdout: "undefined"
+}