handle `case` correctly under `reduce_vars` (#2993)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sun, 11 Mar 2018 07:54:43 +0000 (15:54 +0800)
committerGitHub <noreply@github.com>
Sun, 11 Mar 2018 07:54:43 +0000 (15:54 +0800)
fixes #2992

lib/compress.js
test/compress/reduce_vars.js

index 2f109a1..1b52f83 100644 (file)
@@ -517,6 +517,15 @@ merge(Compressor.prototype, {
             pop(tw);
             return true;
         });
+        def(AST_Case, function(tw) {
+            push(tw);
+            this.expression.walk(tw);
+            pop(tw);
+            push(tw);
+            walk_body(this, tw);
+            pop(tw);
+            return true;
+        });
         def(AST_Conditional, function(tw) {
             this.condition.walk(tw);
             push(tw);
@@ -527,6 +536,12 @@ merge(Compressor.prototype, {
             pop(tw);
             return true;
         });
+        def(AST_Default, function(tw, descend) {
+            push(tw);
+            descend();
+            pop(tw);
+            return true;
+        });
         def(AST_Defun, function(tw, descend, compressor) {
             this.inlined = false;
             var save_ids = tw.safe_ids;
@@ -624,12 +639,6 @@ merge(Compressor.prototype, {
             pop(tw);
             return true;
         });
-        def(AST_SwitchBranch, function(tw, descend) {
-            push(tw);
-            descend();
-            pop(tw);
-            return true;
-        });
         def(AST_SymbolCatch, function() {
             this.definition().fixed = false;
         });
index 836d7fe..815dff3 100644 (file)
@@ -5545,3 +5545,33 @@ issue_2919: {
     }
     expect_stdout: "function"
 }
+
+issue_2992: {
+    options = {
+        evaluate: true,
+        reduce_vars: true,
+    }
+    input: {
+        var c = "PASS";
+        (function f(b) {
+            switch (0) {
+            case 0:
+            case b = 1:
+                b && (c = "FAIL");
+            }
+        })();
+        console.log(c);
+    }
+    expect: {
+        var c = "PASS";
+        (function f(b) {
+            switch (0) {
+            case 0:
+            case b = 1:
+                b && (c = "FAIL");
+            }
+        })();
+        console.log(c);
+    }
+    expect_stdout: "PASS"
+}