diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-02-10 10:09:54 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-10 18:09:54 +0800 |
commit | a98ec7e4df148fd8fb745e25ac3e1da4bf87159b (patch) | |
tree | 58fff10414d9de54d1e95e2728e283574b21d064 /lib/compress.js | |
parent | 5ec82e58011cd07e668b37a40dc545c2431e3d48 (diff) | |
download | tracifyjs-a98ec7e4df148fd8fb745e25ac3e1da4bf87159b.tar.gz tracifyjs-a98ec7e4df148fd8fb745e25ac3e1da4bf87159b.zip |
enhance `side_effects` (#4638)
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js index a0e018e3..5a2a0543 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -6922,9 +6922,29 @@ merge(Compressor.prototype, { exprs = trim(exprs, compressor, first_in_statement, array_spread); return exprs && make_sequence(self, exprs.map(convert_spread)); } - var def; - if ((is_arrow(exp) && !exp.value || exp instanceof AST_AsyncFunction || exp instanceof AST_Function) - && !(exp.name && (def = exp.name.definition()).references.length > def.replaced)) { + if (compressor.option("yields") && is_generator(exp)) { + var call = self.clone(); + call.expression = make_node(AST_Function, exp, exp); + call.expression.body = []; + var opt = call.transform(compressor); + if (opt !== call) return opt.drop_side_effect_free(compressor, first_in_statement); + } + var drop_body = false; + if (compressor.option("arrows") && is_arrow(exp)) { + if (exp.value) { + exp.value = exp.value.drop_side_effect_free(compressor); + } else { + drop_body = true; + } + } else if (exp instanceof AST_AsyncFunction || exp instanceof AST_Function) { + if (exp.name) { + var def = exp.name.definition(); + drop_body = def.references.length == def.replaced; + } else { + drop_body = true; + } + } + if (drop_body) { 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, { |