fix corner case in `collapse_vars` (#4002)
authorAlex Lam S.L <alexlamsl@gmail.com>
Fri, 19 Jun 2020 18:19:37 +0000 (19:19 +0100)
committerGitHub <noreply@github.com>
Fri, 19 Jun 2020 18:19:37 +0000 (02:19 +0800)
fixes #4001

lib/compress.js
test/compress/ie8.js

index b312c64..0e11ba9 100644 (file)
@@ -1500,7 +1500,6 @@ merge(Compressor.prototype, {
                     can_replace = false;
                     var after = stop_after;
                     var if_hit = stop_if_hit;
-                    var rhs_fn = scan_rhs;
                     for (var i = 0; !abort && i < fn.body.length; i++) {
                         var stat = fn.body[i];
                         if (stat instanceof AST_Return) {
@@ -1509,7 +1508,6 @@ merge(Compressor.prototype, {
                         }
                         stat.transform(scanner);
                     }
-                    scan_rhs = rhs_fn;
                     stop_if_hit = if_hit;
                     stop_after = after;
                     can_replace = replace;
index c004976..df06c62 100644 (file)
@@ -2559,3 +2559,37 @@ issue_3999: {
         "1",
     ]
 }
+
+issue_4001: {
+    options = {
+        collapse_vars: true,
+        ie8: true,
+        inline: true,
+        reduce_vars: true,
+        sequences: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        console.log(function(a) {
+            function f() {
+                return a;
+                var b;
+            }
+            var c = f();
+            (function g() {
+                c[42];
+                f;
+            })();
+            (function a() {});
+        }(42));
+    }
+    expect: {
+        function f() {
+            return a;
+        }
+        var a;
+        console.log((a = 42, void f()[42], void function a() {}));
+    }
+    expect_stdout: "undefined"
+}