From afdaeba37d2d7541529addaefe85ed09515863af Mon Sep 17 00:00:00 2001 From: Mihai Bazon Date: Sun, 22 Sep 2013 15:26:10 +0300 Subject: More attempts to determine when addition is associative Somebody hit me with bug reports on this. :) Refs #300 --- lib/compress.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/compress.js b/lib/compress.js index dafed5db..37aba41e 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1965,7 +1965,7 @@ merge(Compressor.prototype, { self = make_node(AST_Binary, self, { operator: "+", left: make_node(AST_String, null, { - value: self.left.getValue() + self.right.left.getValue(), + value: "" + self.left.getValue() + self.right.left.getValue(), start: self.left.start, end: self.right.left.end }), @@ -1981,12 +1981,33 @@ merge(Compressor.prototype, { operator: "+", left: self.left.left, right: make_node(AST_String, null, { - value: self.left.right.getValue() + self.right.getValue(), + value: "" + self.left.right.getValue() + self.right.getValue(), start: self.left.right.start, end: self.right.end }) }); } + if (self.left instanceof AST_Binary + && self.left.operator == "+" + && self.left.is_string(compressor) + && self.left.right instanceof AST_Constant + && self.right instanceof AST_Binary + && self.right.operator == "+" + && self.right.left instanceof AST_Constant) { + self = make_node(AST_Binary, self, { + operator: "+", + left: make_node(AST_Binary, self.left, { + operator: "+", + left: self.left.left, + right: make_node(AST_String, null, { + value: "" + self.left.right.getValue() + self.right.left.getValue(), + start: self.left.right.start, + end: self.right.left.end + }) + }), + right: self.right.right + }); + } } } return self.evaluate(compressor)[0]; -- cgit v1.2.3