aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js18
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 99e67b91..ed048593 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -7226,30 +7226,36 @@ merge(Compressor.prototype, {
}
var rhs = right.drop_side_effect_free(compressor, first_in_statement);
if (!rhs) return left.drop_side_effect_free(compressor, first_in_statement);
- if (lazy_op[op] && !(rhs instanceof AST_Function)) {
+ if (lazy_op[op] && rhs.has_side_effects(compressor)) {
var node = this;
if (op == "&&"
&& rhs instanceof AST_PropAccess
&& left.equivalent_to(rhs.expression)
&& !left.has_side_effects(compressor)) {
- var prop = rhs instanceof AST_Sub && rhs.property.drop_side_effect_free(compressor);
+ var prop = rhs instanceof AST_Sub
+ && rhs.property.drop_side_effect_free(compressor, first_in_statement);
if (!prop) return left.drop_side_effect_free(compressor, first_in_statement);
node = node.clone();
node.right = prop;
- } else if (rhs !== right) {
+ return node.drop_side_effect_free(compressor, first_in_statement);
+ }
+ if (rhs !== right) {
node = node.clone();
node.right = rhs.drop_side_effect_free(compressor);
}
if (op == "??") return node;
- return (first_in_statement ? best_of_statement : best_of_expression)(node, make_node(AST_Binary, this, {
+ var negated = make_node(AST_Binary, this, {
operator: op == "&&" ? "||" : "&&",
left: left.negate(compressor, first_in_statement),
right: node.right,
- }));
+ });
+ return first_in_statement ? best_of_statement(node, negated) : best_of_expression(node, negated);
} else {
var lhs = left.drop_side_effect_free(compressor, first_in_statement);
if (!lhs) return rhs;
- return make_sequence(this, [ lhs, rhs.drop_side_effect_free(compressor) ]);
+ rhs = rhs.drop_side_effect_free(compressor);
+ if (!rhs) return lhs;
+ return make_sequence(this, [ lhs, rhs ]);
}
});
def(AST_Call, function(compressor, first_in_statement) {