fix corner case in `collapse_vars` (#3701)
authorAlex Lam S.L <alexlamsl@gmail.com>
Thu, 30 Jan 2020 01:04:44 +0000 (09:04 +0800)
committerGitHub <noreply@github.com>
Thu, 30 Jan 2020 01:04:44 +0000 (09:04 +0800)
fixes #3700

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

index e6a064d..5d14963 100644 (file)
@@ -1395,7 +1395,7 @@ merge(Compressor.prototype, {
                     var rhs_fn = scan_rhs;
                     for (var i = 0; !abort && i < fn.body.length; i++) {
                         var stat = fn.body[i];
-                        if (stat instanceof AST_Exit) {
+                        if (stat instanceof AST_Return) {
                             if (stat.value) stat.value.transform(scanner);
                             break;
                         }
index f109e93..58ae5c6 100644 (file)
@@ -7734,3 +7734,34 @@ issue_3698_3: {
     }
     expect_stdout: "2"
 }
+
+issue_3700: {
+    options = {
+        collapse_vars: true,
+    }
+    input: {
+        var a = "FAIL";
+        try {
+            a = "PASS";
+            (function() {
+                throw 0;
+            })();
+            a = 1 + a;
+        } catch (e) {
+        }
+        console.log(a);
+    }
+    expect: {
+        var a = "FAIL";
+        try {
+            a = "PASS";
+            (function() {
+                throw 0;
+            })();
+            a = 1 + a;
+        } catch (e) {
+        }
+        console.log(a);
+    }
+    expect_stdout: "PASS"
+}