|| !immutable
&& parent instanceof AST_Call
&& parent.expression === node
- && (!(value instanceof AST_Function) || value.contains_this())) {
+ && (!(value instanceof AST_Function) || value.contains_this(parent))) {
return true;
} else if (parent instanceof AST_Array || parent instanceof AST_Object) {
return is_modified(parent, parent, level + 1);
}
}
if (is_lhs(self, compressor.parent())) return self;
- if (compressor.option("properties") && key !== prop) {
- var node = self.flatten_object(property);
- if (node) {
- expr = self.expression = node.expression;
- prop = self.property = node.property;
+ if (key !== prop) {
+ var sub = self.flatten_object(property, compressor);
+ if (sub) {
+ expr = self.expression = sub.expression;
+ prop = self.property = sub.property;
}
}
if (compressor.option("properties") && compressor.option("side_effects")
return self;
});
- AST_Lambda.DEFMETHOD("contains_this", function() {
+ AST_Lambda.DEFMETHOD("contains_this", function(grandparent) {
+ if (grandparent instanceof AST_New) return false;
var result;
var self = this;
self.walk(new TreeWalker(function(node) {
return result;
});
- AST_PropAccess.DEFMETHOD("flatten_object", function(key) {
+ AST_PropAccess.DEFMETHOD("flatten_object", function(key, compressor) {
+ if (!compressor.option("properties")) return;
var expr = this.expression;
if (expr instanceof AST_Object) {
var props = expr.properties;
return prop instanceof AST_ObjectKeyVal;
})) break;
var value = prop.value;
- if (value instanceof AST_Function && value.contains_this()) break;
+ if (value instanceof AST_Function
+ && value.contains_this(compressor.parent())) break;
return make_node(AST_Sub, this, {
expression: make_node(AST_Array, expr, {
elements: props.map(function(prop) {
}
}
if (is_lhs(self, compressor.parent())) return self;
- if (compressor.option("properties")) {
- var node = self.flatten_object(self.property);
- if (node) return node.optimize(compressor);
- }
+ var sub = self.flatten_object(self.property, compressor);
+ if (sub) return sub.optimize(compressor);
var ev = self.evaluate(compressor);
if (ev !== self) {
ev = make_node_from_constant(ev, self).optimize(compressor);