fix corner case in `reduce_vars` (#4582)
authorAlex Lam S.L <alexlamsl@gmail.com>
Fri, 22 Jan 2021 18:14:53 +0000 (18:14 +0000)
committerGitHub <noreply@github.com>
Fri, 22 Jan 2021 18:14:53 +0000 (02:14 +0800)
fixes #4581

lib/compress.js
test/compress/awaits.js

index fc1bc11..547ef57 100644 (file)
@@ -719,7 +719,7 @@ merge(Compressor.prototype, {
             var fn = this;
             fn.inlined = false;
             var iife = tw.parent();
-            var hit = fn instanceof AST_AsyncFunction;
+            var hit = is_async(fn);
             var aborts = false;
             fn.walk(new TreeWalker(function(node) {
                 if (hit) return aborts = true;
index 4a90ca5..0ffa1a9 100644 (file)
@@ -1003,3 +1003,24 @@ issue_4534: {
     expect_stdout: "PASS"
     node_version: ">=8"
 }
+
+issue_4581: {
+    options = {
+        evaluate: true,
+        reduce_vars: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        var a = "PASS";
+        (async () => (A, a = "FAIL"))();
+        console.log(a);
+    }
+    expect: {
+        var a = "PASS";
+        (async () => (A, a = "FAIL"))();
+        console.log(a);
+    }
+    expect_stdout: "PASS"
+    node_version: ">=8"
+}