side effect fixes and small optimization for gzip

prefer to always use > and >= operators (idea from Closure)
This commit is contained in:
Mihai Bazon
2012-09-12 13:23:24 +03:00
parent 2b4093ba83
commit 2b1e4628e0

View File

@@ -478,6 +478,7 @@ function Compressor(options, false_by_default) {
return this.left.has_side_effects()
|| this.right.has_side_effects ();
});
def(AST_Assign, function(){ return true });
def(AST_Conditional, function(){
return this.condition.has_side_effects()
|| this.consequent.has_side_effects()
@@ -488,6 +489,7 @@ function Compressor(options, false_by_default) {
|| this.operator == "++"
|| this.operator == "--";
});
def(AST_SymbolRef, function(){ return false });
})(function(node, func){
node.DEFMETHOD("has_side_effects", func);
});
@@ -1100,7 +1102,25 @@ function Compressor(options, false_by_default) {
}
break;
}
return this.evaluate(compressor)[0];
var exp = this.evaluate(compressor);
if (exp.length == 2) {
if (best_of(exp[0], this) !== this)
return exp[0];
}
var self = this;
if (compressor.option("comparations")) {
var reverse = function(op) {
self.operator = op;
var tmp = self.left;
self.left = self.right;
self.right = tmp;
};
if (self instanceof AST_Binary) switch (self.operator) {
case "<": reverse(">"); break;
case "<=": reverse(">="); break;
}
}
return self;
});
SQUEEZE(AST_Assign, function(self, compressor){