aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js30
1 files changed, 18 insertions, 12 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 30a82e35..767d5f9c 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3106,7 +3106,12 @@ merge(Compressor.prototype, {
(function(def) {
def(AST_Node, return_false);
def(AST_Assign, function(compressor) {
- return (this.operator == "=" || this.operator == "+=") && this.right.is_string(compressor);
+ switch (this.operator) {
+ case "+=":
+ if (this.left.is_string(compressor)) return true;
+ case "=":
+ return this.right.is_string(compressor);
+ }
});
def(AST_Binary, function(compressor) {
return this.operator == "+" &&
@@ -7363,10 +7368,9 @@ merge(Compressor.prototype, {
var indexFns = makePredicate("indexOf lastIndexOf");
var commutativeOperators = makePredicate("== === != !== * & | ^");
function is_object(node) {
- while ((node = node.tail_node()) instanceof AST_SymbolRef) {
- node = node.fixed_value();
- if (!node) return false;
- }
+ if (node instanceof AST_Assign) return node.operator == "=" && is_object(node.right);
+ if (node instanceof AST_Sequence) return is_object(node.tail_node());
+ if (node instanceof AST_SymbolRef) return is_object(node.fixed_value());
return node instanceof AST_Array
|| node instanceof AST_Lambda
|| node instanceof AST_New
@@ -7758,14 +7762,16 @@ merge(Compressor.prototype, {
associative = compressor.option("unsafe_math");
// +a - b => a - b
// a - +b => a - b
- if (self.operator != "+") {
- if (self.left instanceof AST_UnaryPrefix && self.left.operator == "+") {
- self.left = self.left.expression;
- }
- if (self.right instanceof AST_UnaryPrefix && self.right.operator == "+") {
- self.right = self.right.expression;
+ [ "left", "right" ].forEach(function(operand) {
+ var node = self[operand];
+ if (node instanceof AST_UnaryPrefix && node.operator == "+") {
+ var exp = node.expression;
+ if (exp.is_boolean(compressor) || exp.is_number(compressor)
+ || self.operator != "+" && exp.is_string(compressor)) {
+ self[operand] = exp;
+ }
}
- }
+ });
case "&":
case "|":
case "^":