// we shouldn't compress (1,func)(something) to
// func(something) because that changes the meaning of
// the func (becomes lexical instead of global).
- function maintain_this_binding(parent, orig, val) {
- if (parent instanceof AST_Call && parent.expression === orig && val instanceof AST_PropAccess) {
- return make_node(AST_Seq, orig, {
- car: make_node(AST_Number, orig, {
- value: 0
- }),
- cdr: val
- });
+ function maintain_call_binding(parent, orig, val) {
+ if (parent instanceof AST_Call && parent.expression === orig) {
+ if (val instanceof AST_PropAccess || (val instanceof AST_Symbol && val.name === "eval")) {
+ return make_node(AST_Seq, orig, {
+ car: make_node(AST_Number, orig, {
+ value: 0
+ }),
+ cdr: val
+ });
+ }
}
return val;
}
if (is_lvalue(node, parent)) return node;
// Remove var definition and return its value to the TreeTransformer to replace.
- var value = maintain_this_binding(parent, node, var_decl.value);
+ var value = maintain_call_binding(parent, node, var_decl.value);
var_decl.value = null;
var_defs.splice(var_defs_index, 1);
if (!compressor.option("side_effects"))
return self;
if (!self.car.has_side_effects(compressor)) {
- return maintain_this_binding(compressor.parent(), self, self.cdr);
+ return maintain_call_binding(compressor.parent(), self, self.cdr);
}
if (compressor.option("cascade")) {
if (self.car instanceof AST_Assign
if (ll.length > 1) {
if (ll[1]) {
compressor.warn("Condition left of && always true [{file}:{line},{col}]", self.start);
- return maintain_this_binding(compressor.parent(), self, self.right.evaluate(compressor)[0]);
+ return maintain_call_binding(compressor.parent(), self, self.right.evaluate(compressor)[0]);
} else {
compressor.warn("Condition left of && always false [{file}:{line},{col}]", self.start);
- return maintain_this_binding(compressor.parent(), self, ll[0]);
+ return maintain_call_binding(compressor.parent(), self, ll[0]);
}
}
}
if (ll.length > 1) {
if (ll[1]) {
compressor.warn("Condition left of || always true [{file}:{line},{col}]", self.start);
- return maintain_this_binding(compressor.parent(), self, ll[0]);
+ return maintain_call_binding(compressor.parent(), self, ll[0]);
} else {
compressor.warn("Condition left of || always false [{file}:{line},{col}]", self.start);
- return maintain_this_binding(compressor.parent(), self, self.right.evaluate(compressor)[0]);
+ return maintain_call_binding(compressor.parent(), self, self.right.evaluate(compressor)[0]);
}
}
}
if (cond.length > 1) {
if (cond[1]) {
compressor.warn("Condition always true [{file}:{line},{col}]", self.start);
- return maintain_this_binding(compressor.parent(), self, self.consequent);
+ return maintain_call_binding(compressor.parent(), self, self.consequent);
} else {
compressor.warn("Condition always false [{file}:{line},{col}]", self.start);
- return maintain_this_binding(compressor.parent(), self, self.alternative);
+ return maintain_call_binding(compressor.parent(), self, self.alternative);
}
}
var negated = cond[0].negate(compressor);