diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-03-13 20:39:30 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-14 04:39:30 +0800 |
commit | 73e6b2550bf0cc08e4bc95ac1e1d3b8b650c5bf8 (patch) | |
tree | 173825195336d5cb90cbf598716a9c9f62a01f7c | |
parent | 241113200e8ad3550efc051b2b7f4d7c9a4573e9 (diff) | |
download | tracifyjs-73e6b2550bf0cc08e4bc95ac1e1d3b8b650c5bf8.tar.gz tracifyjs-73e6b2550bf0cc08e4bc95ac1e1d3b8b650c5bf8.zip |
fix corner cases with `yield` (#4771)
fixes #4769
-rw-r--r-- | lib/compress.js | 5 | ||||
-rw-r--r-- | test/compress/yields.js | 40 |
2 files changed, 43 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js index 31e89ab4..3830f0db 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -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); } } @@ -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); } } diff --git a/test/compress/yields.js b/test/compress/yields.js index dc3dacf5..06f46c9d 100644 --- a/test/compress/yields.js +++ b/test/compress/yields.js @@ -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" +} |