TreeTransformer.call(this, this.before, this.after);
this.options = defaults(options, {
arguments : !false_by_default,
+ assignments : !false_by_default,
booleans : !false_by_default,
collapse_vars : !false_by_default,
comparisons : !false_by_default,
def(AST_Sequence, function(compressor) {
return this.tail_node().is_number(compressor);
});
+ def(AST_SymbolRef, function(compressor) {
+ var fixed = this.fixed_value();
+ return fixed && fixed.is_number(compressor);
+ });
var unary = makePredicate("+ - ~ ++ --");
def(AST_Unary, function() {
return unary[this.operator];
// methods to determine if an expression has a string result type
(function(def) {
def(AST_Node, return_false);
- def(AST_String, return_true);
- def(AST_UnaryPrefix, function() {
- return this.operator == "typeof";
+ def(AST_Assign, function(compressor) {
+ return (this.operator == "=" || this.operator == "+=") && this.right.is_string(compressor);
});
def(AST_Binary, function(compressor) {
return this.operator == "+" &&
(this.left.is_string(compressor) || this.right.is_string(compressor));
});
- def(AST_Assign, function(compressor) {
- return (this.operator == "=" || this.operator == "+=") && this.right.is_string(compressor);
+ def(AST_Conditional, function(compressor) {
+ return this.consequent.is_string(compressor) && this.alternative.is_string(compressor);
});
def(AST_Sequence, function(compressor) {
return this.tail_node().is_string(compressor);
});
- def(AST_Conditional, function(compressor) {
- return this.consequent.is_string(compressor) && this.alternative.is_string(compressor);
+ def(AST_String, return_true);
+ def(AST_SymbolRef, function(compressor) {
+ var fixed = this.fixed_value();
+ return fixed && fixed.is_string(compressor);
+ });
+ def(AST_UnaryPrefix, function() {
+ return this.operator == "typeof";
});
})(function(node, func) {
node.DEFMETHOD("is_string", func);
|| parent instanceof AST_Sequence && parent.tail_node() === node);
}
self = self.lift_sequences(compressor);
+ if (!compressor.option("assignments")) return self;
if (self.operator == "=" && self.left instanceof AST_SymbolRef && self.right instanceof AST_Binary) {
// x = expr1 OP expr2
if (self.right.left instanceof AST_SymbolRef
self.right = self.right.left;
}
}
+ if ((self.operator == "+=" || self.operator == "-=")
+ && self.left.is_number(compressor)
+ && self.right instanceof AST_Number
+ && self.right.getValue() === 1) {
+ var op = self.operator.slice(0, -1);
+ return make_node(AST_UnaryPrefix, self, {
+ operator: op + op,
+ expression: self.left
+ });
+ }
return self;
function in_try(level, node) {