try negating AST_Binary
This commit is contained in:
@@ -187,12 +187,12 @@ function Compressor(options, false_by_default) {
|
|||||||
if (compressor.option("dead_code")) {
|
if (compressor.option("dead_code")) {
|
||||||
statements = eliminate_dead_code(statements, compressor);
|
statements = eliminate_dead_code(statements, compressor);
|
||||||
}
|
}
|
||||||
if (compressor.option("sequences")) {
|
|
||||||
statements = sequencesize(statements, compressor);
|
|
||||||
}
|
|
||||||
if (compressor.option("if_return")) {
|
if (compressor.option("if_return")) {
|
||||||
statements = handle_if_return(statements, compressor);
|
statements = handle_if_return(statements, compressor);
|
||||||
}
|
}
|
||||||
|
if (compressor.option("sequences")) {
|
||||||
|
statements = sequencesize(statements, compressor);
|
||||||
|
}
|
||||||
if (compressor.option("join_vars")) {
|
if (compressor.option("join_vars")) {
|
||||||
statements = join_consecutive_vars(statements, compressor);
|
statements = join_consecutive_vars(statements, compressor);
|
||||||
}
|
}
|
||||||
@@ -620,6 +620,9 @@ function Compressor(options, false_by_default) {
|
|||||||
def(AST_Statement, function(){
|
def(AST_Statement, function(){
|
||||||
throw new Error("Cannot negate a statement");
|
throw new Error("Cannot negate a statement");
|
||||||
});
|
});
|
||||||
|
def(AST_Function, function(){
|
||||||
|
return basic_negation(this);
|
||||||
|
});
|
||||||
def(AST_UnaryPrefix, function(){
|
def(AST_UnaryPrefix, function(){
|
||||||
if (this.operator == "!")
|
if (this.operator == "!")
|
||||||
return this.expression;
|
return this.expression;
|
||||||
@@ -664,7 +667,7 @@ function Compressor(options, false_by_default) {
|
|||||||
});
|
});
|
||||||
})(function(node, func){
|
})(function(node, func){
|
||||||
node.DEFMETHOD("negate", function(compressor){
|
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 += "=";
|
if (this.operator.length == 2) this.operator += "=";
|
||||||
}
|
}
|
||||||
break;
|
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) {
|
if (compressor.option("booleans") && compressor.in_boolean_context()) switch (this.operator) {
|
||||||
case "&&":
|
case "&&":
|
||||||
@@ -1469,6 +1459,13 @@ function Compressor(options, false_by_default) {
|
|||||||
case "<": reverse(">"); break;
|
case "<": reverse(">"); break;
|
||||||
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;
|
return self;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user