fix corner case in `merge_vars` (#4116)
authorAlex Lam S.L <alexlamsl@gmail.com>
Wed, 16 Sep 2020 19:11:57 +0000 (20:11 +0100)
committerGitHub <noreply@github.com>
Wed, 16 Sep 2020 19:11:57 +0000 (03:11 +0800)
fixes #4115

lib/compress.js
test/compress/merge_vars.js

index a79b909..e313905 100644 (file)
@@ -4376,6 +4376,12 @@ merge(Compressor.prototype, {
                 pop();
                 return true;
             }
+            if (node instanceof AST_LabeledStatement) {
+                push();
+                node.body.walk(tw);
+                pop();
+                return true;
+            }
             if (node instanceof AST_Scope) {
                 if (node instanceof AST_Lambda) {
                     references[node.variables.get("arguments").id] = false;
index fd650f9..c63f33d 100644 (file)
@@ -486,3 +486,29 @@ issue_4112: {
     }
     expect_stdout: "function"
 }
+
+issue_4115: {
+    options = {
+        merge_vars: true,
+        toplevel: true,
+    }
+    input: {
+        L: {
+            var o = typeof console;
+            for (var k in o)
+                break L;
+            var a = 0;
+        }
+        console.log(typeof a);
+    }
+    expect: {
+        L: {
+            var o = typeof console;
+            for (var k in o)
+                break L;
+            var a = 0;
+        }
+        console.log(typeof a);
+    }
+    expect_stdout: "undefined"
+}