fix corner case in `merge_vars` (#4102)
authorAlex Lam S.L <alexlamsl@gmail.com>
Tue, 15 Sep 2020 11:18:12 +0000 (12:18 +0100)
committerGitHub <noreply@github.com>
Tue, 15 Sep 2020 11:18:12 +0000 (19:18 +0800)
fixes #4101

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

index c39c0da..171746a 100644 (file)
@@ -4403,6 +4403,17 @@ merge(Compressor.prototype, {
                 mark(node);
                 return true;
             }
+            if (node instanceof AST_Try) {
+                var save = segment;
+                segment = node;
+                node.body.forEach(function(branch) {
+                    branch.walk(tw);
+                });
+                if (node.bcatch) node.bcatch.walk(tw);
+                segment = save;
+                if (node.bfinally) node.bfinally.walk(tw);
+                return true;
+            }
             if (node instanceof AST_Unary) {
                 if (!unary_arithmetic[node.operator]) return;
                 var sym = node.expression;
index 8ef186c..076668e 100644 (file)
@@ -182,6 +182,35 @@ switch_branch: {
     expect_stdout: "PASS"
 }
 
+try_branch: {
+    options = {
+        merge_vars: true,
+    }
+    input: {
+        console.log(function(a) {
+            var b = "FAIL", c;
+            try {
+                a && F();
+            } catch (e) {
+                c = b;
+            }
+            return c || "PASS";
+        }());
+    }
+    expect: {
+        console.log(function(a) {
+            var b = "FAIL", c;
+            try {
+                a && F();
+            } catch (e) {
+                c = b;
+            }
+            return c || "PASS";
+        }());
+    }
+    expect_stdout: "PASS"
+}
+
 read_before_assign_1: {
     options = {
         inline: true,