Skip to content

Commit

Permalink
fix corner cases with yield (#4771)
Browse files Browse the repository at this point in the history
fixes #4769
  • Loading branch information
alexlamsl committed Mar 13, 2021
1 parent 2411132 commit 73e6b25
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/compress.js
Expand Up @@ -8735,7 +8735,7 @@ merge(Compressor.prototype, {
var can_inline = can_drop && compressor.option("inline") && !self.is_expr_pure(compressor);
if (can_inline && stat instanceof AST_Return) {
var value = stat.value;
if (exp === fn && (!value || value.is_constant_expression() && safe_from_await_yield(value))) {
if (exp === fn && (!value || value.is_constant_expression()) && safe_from_await_yield(fn)) {
return make_sequence(self, convert_args(value)).optimize(compressor);
}
}
Expand Down Expand Up @@ -8803,7 +8803,8 @@ merge(Compressor.prototype, {
&& can_drop
&& all(fn.body, is_empty)
&& (fn === exp ? fn_name_unused(fn, compressor) : !has_default && !has_destructured && !fn.rest)
&& !(is_arrow(fn) && fn.value)) {
&& !(is_arrow(fn) && fn.value)
&& safe_from_await_yield(fn)) {
return make_sequence(self, convert_args()).optimize(compressor);
}
}
Expand Down
40 changes: 40 additions & 0 deletions test/compress/yields.js
Expand Up @@ -950,3 +950,43 @@ issue_4641_2: {
]
node_version: ">=10"
}

issue_4769_1: {
options = {
side_effects: true,
}
input: {
console.log(function*() {
(function({} = yield => {}) {})();
}().next().done);
}
expect: {
console.log(function*() {
(function({} = yield => {}) {})();
}().next().done);
}
expect_stdout: "true"
node_version: ">=6"
}

issue_4769_2: {
options = {
inline: true,
}
input: {
console.log(function*() {
return function({} = yield => {}) {
return "PASS";
}();
}().next().value);
}
expect: {
console.log(function*() {
return function({} = yield => {}) {
return "PASS";
}();
}().next().value);
}
expect_stdout: "PASS"
node_version: ">=6"
}

0 comments on commit 73e6b25

Please sign in to comment.