fix corner case in `collapse_vars` (#3928)
authorAlex Lam S.L <alexlamsl@gmail.com>
Wed, 27 May 2020 13:02:48 +0000 (14:02 +0100)
committerGitHub <noreply@github.com>
Wed, 27 May 2020 13:02:48 +0000 (21:02 +0800)
fixes #3927

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

index 644746e..cc2d1ec 100644 (file)
@@ -1172,7 +1172,7 @@ merge(Compressor.prototype, {
                     scope = node;
                     break;
                 } else if (node instanceof AST_Try) {
-                    in_try = node;
+                    if (!in_try) in_try = node;
                 }
             } while (node = compressor.parent(level++));
         }
index 446377a..737697a 100644 (file)
@@ -8108,3 +8108,37 @@ issue_3908: {
     }
     expect_stdout: "PASS"
 }
+
+issue_3927: {
+    options = {
+        collapse_vars: true,
+    }
+    input: {
+        var a = 0;
+        console.log(function(b) {
+            try {
+                try {
+                    if (a + (b = "PASS", true)) return;
+                    b.p;
+                } finally {
+                    return b;
+                }
+            } catch (e) {
+            }
+        }());
+    }
+    expect: {
+        var a = 0;
+        console.log(function(b) {
+            try {
+                try {
+                    if (a + (b = "PASS", true)) return;
+                    b.p;
+                } finally {
+                    return b;
+                }
+            } catch (e) {}
+        }());
+    }
+    expect_stdout: "PASS"
+}