enhance side_effects & unused (#5181)

This commit is contained in:
Alex Lam S.L
2021-11-22 03:14:28 +00:00
committed by GitHub
parent 839f4361f4
commit 1e3ca4c6f7
4 changed files with 101 additions and 16 deletions

View File

@@ -7208,7 +7208,7 @@ merge(Compressor.prototype, {
case 1:
if (!drop) break;
var sym = elements[0];
if (!(sym instanceof AST_Symbol)) break;
if (sym.has_side_effects(compressor)) break;
value = make_node(AST_Sub, node, {
expression: value,
property: make_node(AST_Number, node, { value: 0 }),
@@ -7334,7 +7334,7 @@ merge(Compressor.prototype, {
if (!drop) break;
var prop = properties[0];
if (prop.key instanceof AST_Node) break;
if (!(prop.value instanceof AST_Symbol)) break;
if (prop.value.has_side_effects(compressor)) break;
value = make_node(AST_Sub, node, {
expression: value,
property: make_node_from_constant(prop.key, prop),
@@ -7809,14 +7809,10 @@ merge(Compressor.prototype, {
if (compressor.has_directive("use strict") && expr.is_constant()) return this;
}
if (left.has_side_effects(compressor)) return this;
var right = this.right;
if (!lazy_op[this.operator.slice(0, -1)]) {
this.write_only = true;
if (root_expr(left).is_constant_expression(compressor.find_parent(AST_Scope))) {
return right.drop_side_effect_free(compressor);
}
}
return this;
if (lazy_op[this.operator.slice(0, -1)]) return this;
this.write_only = true;
if (!root_expr(left).is_constant_expression(compressor.find_parent(AST_Scope))) return this;
return this.right.drop_side_effect_free(compressor);
});
def(AST_Await, function(compressor) {
if (!compressor.option("awaits")) return this;