side effect fixes and small optimization for gzip
prefer to always use > and >= operators (idea from Closure)
This commit is contained in:
@@ -478,6 +478,7 @@ function Compressor(options, false_by_default) {
|
|||||||
return this.left.has_side_effects()
|
return this.left.has_side_effects()
|
||||||
|| this.right.has_side_effects ();
|
|| this.right.has_side_effects ();
|
||||||
});
|
});
|
||||||
|
def(AST_Assign, function(){ return true });
|
||||||
def(AST_Conditional, function(){
|
def(AST_Conditional, function(){
|
||||||
return this.condition.has_side_effects()
|
return this.condition.has_side_effects()
|
||||||
|| this.consequent.has_side_effects()
|
|| this.consequent.has_side_effects()
|
||||||
@@ -488,6 +489,7 @@ function Compressor(options, false_by_default) {
|
|||||||
|| this.operator == "++"
|
|| this.operator == "++"
|
||||||
|| this.operator == "--";
|
|| this.operator == "--";
|
||||||
});
|
});
|
||||||
|
def(AST_SymbolRef, function(){ return false });
|
||||||
})(function(node, func){
|
})(function(node, func){
|
||||||
node.DEFMETHOD("has_side_effects", func);
|
node.DEFMETHOD("has_side_effects", func);
|
||||||
});
|
});
|
||||||
@@ -1100,7 +1102,25 @@ function Compressor(options, false_by_default) {
|
|||||||
}
|
}
|
||||||
break;
|
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){
|
SQUEEZE(AST_Assign, function(self, compressor){
|
||||||
|
|||||||
Reference in New Issue
Block a user