make AST_Lambda.contains_this() less magical (#2505)

This commit is contained in:
Alex Lam S.L
2017-11-24 07:03:37 +08:00
committed by GitHub
parent 8987780db6
commit aa9bdf416e

View File

@@ -610,7 +610,8 @@ merge(Compressor.prototype, {
|| !immutable || !immutable
&& parent instanceof AST_Call && parent instanceof AST_Call
&& parent.expression === node && parent.expression === node
&& (!(value instanceof AST_Function) || value.contains_this(parent))) { && (!(value instanceof AST_Function)
|| !(parent instanceof AST_New) && value.contains_this())) {
return true; return true;
} else if (parent instanceof AST_Array) { } else if (parent instanceof AST_Array) {
return is_modified(parent, parent, level + 1); return is_modified(parent, parent, level + 1);
@@ -4764,8 +4765,7 @@ merge(Compressor.prototype, {
return self; return self;
}); });
AST_Lambda.DEFMETHOD("contains_this", function(grandparent) { AST_Lambda.DEFMETHOD("contains_this", function() {
if (grandparent instanceof AST_New) return false;
var result; var result;
var self = this; var self = this;
self.walk(new TreeWalker(function(node) { self.walk(new TreeWalker(function(node) {
@@ -4789,7 +4789,8 @@ merge(Compressor.prototype, {
})) break; })) break;
var value = prop.value; var value = prop.value;
if (value instanceof AST_Function if (value instanceof AST_Function
&& value.contains_this(compressor.parent())) break; && !(compressor.parent() instanceof AST_New)
&& value.contains_this()) break;
return make_node(AST_Sub, this, { return make_node(AST_Sub, this, {
expression: make_node(AST_Array, expr, { expression: make_node(AST_Array, expr, {
elements: props.map(function(prop) { elements: props.map(function(prop) {