Skip to content

Commit

Permalink
make AST_Lambda.contains_this() less magical (#2505)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed Nov 23, 2017
1 parent 8987780 commit aa9bdf4
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/compress.js
Expand Up @@ -610,7 +610,8 @@ merge(Compressor.prototype, {
|| !immutable
&& parent instanceof AST_Call
&& parent.expression === node
&& (!(value instanceof AST_Function) || value.contains_this(parent))) {
&& (!(value instanceof AST_Function)
|| !(parent instanceof AST_New) && value.contains_this())) {
return true;
} else if (parent instanceof AST_Array) {
return is_modified(parent, parent, level + 1);
Expand Down Expand Up @@ -4764,8 +4765,7 @@ merge(Compressor.prototype, {
return self;
});

AST_Lambda.DEFMETHOD("contains_this", function(grandparent) {
if (grandparent instanceof AST_New) return false;
AST_Lambda.DEFMETHOD("contains_this", function() {
var result;
var self = this;
self.walk(new TreeWalker(function(node) {
Expand All @@ -4789,7 +4789,8 @@ merge(Compressor.prototype, {
})) break;
var value = prop.value;
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, {
expression: make_node(AST_Array, expr, {
elements: props.map(function(prop) {
Expand Down

0 comments on commit aa9bdf4

Please sign in to comment.