diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-05-28 18:47:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-29 01:47:54 +0800 |
commit | d40631fd44165936158633cc81c4d62cc2a6a5a9 (patch) | |
tree | d4a5970a74a3ee23eab26f052a2d87df4f3bbf0f | |
parent | d320a6cde2ef6436874f4f3790c790d65ed0c966 (diff) | |
download | tracifyjs-d40631fd44165936158633cc81c4d62cc2a6a5a9.tar.gz tracifyjs-d40631fd44165936158633cc81c4d62cc2a6a5a9.zip |
fix corner cases in `awaits` (#4976)
fixes #4974
fixes #4975
-rw-r--r-- | lib/compress.js | 4 | ||||
-rw-r--r-- | test/compress/awaits.js | 44 |
2 files changed, 46 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js index 872cd1cb..838a912e 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -7573,16 +7573,16 @@ merge(Compressor.prototype, { } return node; }); - var abort = arrow && exp.value && !is_primitive(compressor, exp.value); + var abort = !drop_body && exp.name || arrow && exp.value && !is_primitive(compressor, exp.value); var tw = new TreeWalker(function(node) { if (abort) return true; + if (tw.parent() === exp && node.may_throw(compressor)) return abort = true; if (node instanceof AST_Await) return abort = true; if (node instanceof AST_Return) { if (node.value && !is_primitive(compressor, node.value)) return abort = true; return; } if (node instanceof AST_Scope && node !== exp) return true; - if (tw.parent() === exp && node.may_throw(compressor)) return abort = true; }); exp.walk(tw); if (!abort) { diff --git a/test/compress/awaits.js b/test/compress/awaits.js index e1b2805c..612cf8b5 100644 --- a/test/compress/awaits.js +++ b/test/compress/awaits.js @@ -1682,3 +1682,47 @@ issue_4972_3: { ] node_version: ">=8" } + +issue_4974: { + options = { + awaits: true, + side_effects: true, + } + input: { + (async function f() { + return 42 in f(); + })(); + console.log("PASS"); + } + expect: { + (async function f() { + return 42 in f(); + })(); + console.log("PASS"); + } + expect_stdout: true + node_version: ">=8" +} + +issue_4975: { + options = { + awaits: true, + side_effects: true, + } + input: { + (async function f(a) { + try { + if (a) console.log(typeof f()); + } catch (e) {} + })(42); + } + expect: { + (async function f(a) { + try { + if (a) console.log(typeof f()); + } catch (e) {} + })(42); + } + expect_stdout: "object" + node_version: ">=8" +} |