From: Mihai Bazon Date: Mon, 17 Sep 2012 08:16:44 +0000 (+0300) Subject: try negating AST_Binary X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=5e60a60b3b9ddea872187cf6568ebbcad58c1a60;p=UglifyJS.git try negating AST_Binary --- diff --git a/lib/compress.js b/lib/compress.js index 67f37269..09dc1802 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -187,12 +187,12 @@ function Compressor(options, false_by_default) { if (compressor.option("dead_code")) { statements = eliminate_dead_code(statements, compressor); } - if (compressor.option("sequences")) { - statements = sequencesize(statements, compressor); - } if (compressor.option("if_return")) { statements = handle_if_return(statements, compressor); } + if (compressor.option("sequences")) { + statements = sequencesize(statements, compressor); + } if (compressor.option("join_vars")) { statements = join_consecutive_vars(statements, compressor); } @@ -620,6 +620,9 @@ function Compressor(options, false_by_default) { def(AST_Statement, function(){ throw new Error("Cannot negate a statement"); }); + def(AST_Function, function(){ + return basic_negation(this); + }); def(AST_UnaryPrefix, function(){ if (this.operator == "!") return this.expression; @@ -664,7 +667,7 @@ function Compressor(options, false_by_default) { }); })(function(node, func){ node.DEFMETHOD("negate", function(compressor){ - return func.call(this, compressor).optimize(compressor); + return func.call(this, compressor); }); }); @@ -1372,19 +1375,6 @@ function Compressor(options, false_by_default) { if (this.operator.length == 2) this.operator += "="; } break; - case "&&": - case "||": - if (this.left instanceof AST_UnaryPrefix && this.left.operator == "!" - && this.right instanceof AST_UnaryPrefix && this.right.operator == "!") { - this.left = this.left.expression; - this.right = this.right.expression; - this.operator = this.operator == "&&" ? "||" : "&&"; - return make_node(AST_UnaryPrefix, this, { - operator: "!", - expression: this - }).optimize(compressor); - } - break; } if (compressor.option("booleans") && compressor.in_boolean_context()) switch (this.operator) { case "&&": @@ -1469,6 +1459,13 @@ function Compressor(options, false_by_default) { case "<": reverse(">"); break; case "<=": reverse(">="); break; } + if (!(compressor.parent() instanceof AST_Binary)) { + var negated = make_node(AST_UnaryPrefix, self, { + operator: "!", + expression: self.negate(compressor) + }); + self = best_of(self, negated); + } } return self; });