aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-02-10 00:45:36 +0000
committerGitHub <noreply@github.com>2021-02-10 08:45:36 +0800
commit5e6307974fa2b1e7972ab8c58b636eaed47a54fb (patch)
tree0e1d3f4ac255e46198333c6097884a7159c5dd6f
parent228cdf8e7e1dc472813f7def780b8608a4f5f485 (diff)
downloadtracifyjs-5e6307974fa2b1e7972ab8c58b636eaed47a54fb.tar.gz
tracifyjs-5e6307974fa2b1e7972ab8c58b636eaed47a54fb.zip
fix corner case in `collapse_vars` (#4634)
fixes #4633
-rw-r--r--lib/compress.js2
-rw-r--r--test/compress/yields.js30
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js
index c822a8e7..3fcfe2d2 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -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;
}
diff --git a/test/compress/yields.js b/test/compress/yields.js
index d799c194..7f85059b 100644
--- a/test/compress/yields.js
+++ b/test/compress/yields.js
@@ -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"
+}