diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-03-12 18:40:28 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-13 02:40:28 +0800 |
commit | c36c3cb47053fc83b984d3a37eb3036d6df26cbe (patch) | |
tree | bd8ff33b0199c5924aaf4778127cce3560474587 /lib | |
parent | 24b73a95fad4dd6c4a89fc9062014b9e83886128 (diff) | |
download | tracifyjs-c36c3cb47053fc83b984d3a37eb3036d6df26cbe.tar.gz tracifyjs-c36c3cb47053fc83b984d3a37eb3036d6df26cbe.zip |
fix corner case in `side_effects` (#4765)
fixes #4764
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/lib/compress.js b/lib/compress.js index 807872f4..09ae2fff 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -7266,10 +7266,10 @@ merge(Compressor.prototype, { } var drop_body = false; if (compressor.option("arrows") && is_arrow(exp)) { - if (exp.value) { - exp.value = exp.value.drop_side_effect_free(compressor); - } else { + if (!exp.value) { drop_body = true; + } else if (!is_async(exp) || is_primitive(compressor, exp.value)) { + exp.value = exp.value.drop_side_effect_free(compressor); } } else if (exp instanceof AST_AsyncFunction || exp instanceof AST_Function) { if (exp.name) { @@ -7280,14 +7280,22 @@ merge(Compressor.prototype, { } } if (drop_body) { + var async = is_async(exp); exp.process_expression(false, function(node) { - var value = node.value && node.value.drop_side_effect_free(compressor, true); - return value ? make_node(AST_SimpleStatement, node, { - body: value - }) : make_node(AST_EmptyStatement, node); + var value = node.value; + if (value) { + if (async && !is_primitive(compressor, value)) return node; + value = value.drop_side_effect_free(compressor, true); + } + if (!value) return make_node(AST_EmptyStatement, node); + return make_node(AST_SimpleStatement, node, { body: value }); }); scan_local_returns(exp, function(node) { - if (node.value) node.value = node.value.drop_side_effect_free(compressor); + var value = node.value; + if (value) { + if (async && !is_primitive(compressor, value)) return; + node.value = value.drop_side_effect_free(compressor); + } }); // always shallow clone to ensure stripping of negated IIFEs self = self.clone(); |