aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2012-09-17 11:16:44 +0300
committerMihai Bazon <mihai@bazon.net>2012-09-17 11:16:44 +0300
commit5e60a60b3b9ddea872187cf6568ebbcad58c1a60 (patch)
treee8877a502a56224d8ffb438a919acfdaa51e3e05
parent5d781ec6f8689f102db1c0666c725bd64b463df2 (diff)
downloadtracifyjs-5e60a60b3b9ddea872187cf6568ebbcad58c1a60.tar.gz
tracifyjs-5e60a60b3b9ddea872187cf6568ebbcad58c1a60.zip
try negating AST_Binary
-rw-r--r--lib/compress.js31
1 files changed, 14 insertions, 17 deletions
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;
});