fix corner case in `collapse_vars` (#4634)
authorAlex Lam S.L <alexlamsl@gmail.com>
Wed, 10 Feb 2021 00:45:36 +0000 (00:45 +0000)
committerGitHub <noreply@github.com>
Wed, 10 Feb 2021 00:45:36 +0000 (08:45 +0800)
fixes #4633

lib/compress.js
test/compress/yields.js

index c822a8e..3fcfe2d 100644 (file)
@@ -2009,7 +2009,7 @@ merge(Compressor.prototype, {
                     };
                     var tw = new TreeWalker(function(node) {
                         if (!arg) return true;
-                        if (has_await(node)) {
+                        if (has_await(node) || node instanceof AST_Yield) {
                             arg = null;
                             return true;
                         }
index d799c19..7f85059 100644 (file)
@@ -644,3 +644,33 @@ issue_4623: {
     expect_stdout: "PASS"
     node_version: ">=4"
 }
+
+issue_4633: {
+    options = {
+        collapse_vars: true,
+        unused: true,
+    }
+    input: {
+        var a = function*() {
+            (function(log) {
+                log(typeof this);
+            })(yield "PASS");
+        }();
+        console.log(a.next().value);
+        a.next(console.log);
+    }
+    expect: {
+        var a = function*() {
+            (function(log) {
+                log(typeof this);
+            })(yield "PASS");
+        }();
+        console.log(a.next().value);
+        a.next(console.log);
+    }
+    expect_stdout: [
+        "PASS",
+        "object",
+    ]
+    node_version: ">=4"
+}