fix corner case in `collapse_vars` (#4853)
authorAlex Lam S.L <alexlamsl@gmail.com>
Thu, 8 Apr 2021 09:50:40 +0000 (10:50 +0100)
committerGitHub <noreply@github.com>
Thu, 8 Apr 2021 09:50:40 +0000 (17:50 +0800)
fixes #4852

lib/compress.js
test/compress/collapse_vars.js

index 21eec7c..911cf55 100644 (file)
@@ -1866,7 +1866,7 @@ merge(Compressor.prototype, {
                             return null;
                         }
                       default:
-                        return;
+                        return handle_custom_scan_order(node, multi_replacer);
                     }
                 }
                 // Replace variable when found
index eaff012..fcc4739 100644 (file)
@@ -8897,3 +8897,38 @@ issue_4806: {
     }
     expect_stdout: "PASS"
 }
+
+issue_4852: {
+    options = {
+        collapse_vars: true,
+    }
+    input: {
+        var a = "PASS";
+        (function(b) {
+            switch (b = a) {
+              case 42:
+                try {
+                    console;
+                } catch (b) {
+                    b.p;
+                }
+              case console.log(b):
+            }
+        })("FAIL");
+    }
+    expect: {
+        var a = "PASS";
+        (function(b) {
+            switch (a) {
+              case 42:
+                try {
+                    console;
+                } catch (b) {
+                    b.p;
+                }
+              case console.log(a):
+            }
+        })("FAIL");
+    }
+    expect_stdout: "PASS"
+}