def(AST_UnaryPrefix, function(){
return this.operator == "typeof";
});
- def(AST_Binary, function(){
+ def(AST_Binary, function(compressor){
return this.operator == "+" &&
- (this.left.is_string() || this.right.is_string());
+ (this.left.is_string(compressor) || this.right.is_string(compressor));
});
- def(AST_Assign, function(){
- return this.operator == "=" && this.right.is_string();
+ def(AST_Assign, function(compressor){
+ return (this.operator == "=" || this.operator == "+=") && this.right.is_string(compressor);
+ });
+ def(AST_Seq, function(compressor){
+ return this.cdr.is_string(compressor);
+ });
+ def(AST_Conditional, function(compressor){
+ return this.consequent.is_string(compressor) && this.alternative.is_string(compressor);
+ });
+ def(AST_Call, function(compressor){
+ return compressor.option("unsafe")
+ && this.expression instanceof AST_SymbolRef
+ && this.expression.name == "String"
+ && this.expression.undeclared();
});
})(function(node, func){
node.DEFMETHOD("is_string", func);
OPT(AST_Binary, function(self, compressor){
function reverse(op) {
- if (op) self.operator = op;
- var tmp = self.left;
- self.left = self.right;
- self.right = tmp;
+ if (!(self.left.has_side_effects() && self.right.has_side_effects())) {
+ if (op) self.operator = op;
+ var tmp = self.left;
+ self.left = self.right;
+ self.right = tmp;
+ }
};
if (commutativeOperators(self.operator)) {
if (self.right instanceof AST_Constant
if (compressor.option("comparisons")) switch (self.operator) {
case "===":
case "!==":
- if ((self.left.is_string() && self.right.is_string()) ||
+ if ((self.left.is_string(compressor) && self.right.is_string(compressor)) ||
(self.left.is_boolean() && self.right.is_boolean())) {
self.operator = self.operator.substr(0, 2);
}