OPT(AST_UnaryPrefix, function(self, compressor) {
var e = self.expression;
- if (self.operator == "delete"
+ if (compressor.option("evaluate")
+ && self.operator == "delete"
&& !(e instanceof AST_SymbolRef
|| e instanceof AST_PropAccess
|| is_identifier_atom(e))) {
if (compressor.option("dead_code")
&& self.left instanceof AST_SymbolRef
&& (def = self.left.definition()).scope === compressor.find_parent(AST_Lambda)) {
+ if (self.left.is_immutable()) return strip_assignment();
var level = 0, node, parent = self;
do {
node = parent;
if (parent instanceof AST_Exit) {
if (in_try(level, parent)) break;
if (is_reachable(def.scope, [ def ])) break;
- if (self.operator == "=") return self.right.optimize(compressor);
def.fixed = false;
- return make_node(AST_Binary, self, {
- operator: self.operator.slice(0, -1),
- left: self.left,
- right: self.right
- }).optimize(compressor);
+ return strip_assignment();
}
} while (parent instanceof AST_Binary && parent.right === node
- || parent instanceof AST_Sequence && parent.tail_node() === node);
+ || parent instanceof AST_Sequence && parent.tail_node() === node
+ || parent instanceof AST_UnaryPrefix);
}
self = self.lift_sequences(compressor);
if (!compressor.option("assignments")) return self;
expression: self.left
});
}
- if (!compressor.option("ie8") && self.left instanceof AST_Symbol && self.left.is_immutable()) {
- return (self.operator == "=" ? self.right : make_node(AST_Binary, self, {
- operator: self.operator.slice(0, -1),
- left: self.left,
- right: self.right
- })).optimize(compressor);
- }
return self;
function in_try(level, node) {
}
}
}
+
+ function strip_assignment() {
+ return (self.operator != "=" ? make_node(AST_Binary, self, {
+ operator: self.operator.slice(0, -1),
+ left: self.left,
+ right: self.right
+ }) : maintain_this_binding(compressor, compressor.parent(), self, self.right)).optimize(compressor);
+ }
});
OPT(AST_Conditional, function(self, compressor) {
delete_assign_1: {
options = {
booleans: true,
- side_effects: true,
+ evaluate: true,
toplevel: true,
unused: true,
}
console.log((1 / 0, !0));
console.log((1 / 0, !0));
console.log((NaN, !0));
- console.log((0 / 0, !0));
+ console.log((NaN, !0));
}
expect_stdout: true
}
delete_assign_2: {
options = {
booleans: true,
+ evaluate: true,
keep_infinity: true,
- side_effects: true,
toplevel: true,
unused: true,
}
console.log((Infinity, !0));
console.log((1 / 0, !0));
console.log((NaN, !0));
- console.log((0 / 0, !0));
+ console.log((NaN, !0));
}
expect_stdout: true
}