fix corner case in `collapse_vars` (#4013)
authorAlex Lam S.L <alexlamsl@gmail.com>
Mon, 20 Jul 2020 15:28:13 +0000 (16:28 +0100)
committerGitHub <noreply@github.com>
Mon, 20 Jul 2020 15:28:13 +0000 (23:28 +0800)
fixes #4012

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

index 2c8c776..a464b66 100644 (file)
@@ -1197,7 +1197,9 @@ merge(Compressor.prototype, {
         function find_loop_scope_try() {
             var node = compressor.self(), level = 0;
             do {
-                if (node instanceof AST_Catch || node instanceof AST_Finally) {
+                if (node instanceof AST_Catch) {
+                    if (!compressor.parent(level).bfinally) level++;
+                } else if (node instanceof AST_Finally) {
                     level++;
                 } else if (node instanceof AST_IterationStatement) {
                     in_loop = true;
index dcc95b2..109bbde 100644 (file)
@@ -8280,3 +8280,40 @@ issue_3976: {
     }
     expect_stdout: "PASS"
 }
+
+issue_4012: {
+    options = {
+        collapse_vars: true,
+        dead_code: true,
+        evaluate: true,
+    }
+    input: {
+        (function(a) {
+            try {
+                throw 2;
+            } catch (b) {
+                a = "PASS";
+                if (--b)
+                    return;
+                if (3);
+            } finally {
+                console.log(a);
+            }
+        })();
+    }
+    expect: {
+        (function(a) {
+            try {
+                throw 2;
+            } catch (b) {
+                a = "PASS";
+                if (--b)
+                    return;
+                if (3);
+            } finally {
+                console.log(a);
+            }
+        })();
+    }
+    expect_stdout: "PASS"
+}