diff options
author | Mihai Bazon <mihai.bazon@gmail.com> | 2013-10-24 02:39:07 -0700 |
---|---|---|
committer | Mihai Bazon <mihai.bazon@gmail.com> | 2013-10-24 02:39:07 -0700 |
commit | cfd5c6155c4774b4def6711c5159d9080148a7ae (patch) | |
tree | 2ba5995f6e369d336bae43b243055dd5a7f88ece /lib/compress.js | |
parent | 63e1a8e1fd17958557f41a55ea08d678b7995f9b (diff) | |
parent | 1a5a4bd63185e38eb550a9b0ca85890002d5243a (diff) | |
download | tracifyjs-cfd5c6155c4774b4def6711c5159d9080148a7ae.tar.gz tracifyjs-cfd5c6155c4774b4def6711c5159d9080148a7ae.zip |
Merge pull request #325 from rvanvelzen/fix-269
Fix #269
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js index 083b5d29..121e312a 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1620,7 +1620,7 @@ merge(Compressor.prototype, { if (self.args.length != 1) { return make_node(AST_Array, self, { elements: self.args - }); + }).transform(compressor); } break; case "Object": @@ -1634,11 +1634,30 @@ merge(Compressor.prototype, { if (self.args.length == 0) return make_node(AST_String, self, { value: "" }); - return make_node(AST_Binary, self, { + if (self.args.length <= 1) return make_node(AST_Binary, self, { left: self.args[0], operator: "+", right: make_node(AST_String, self, { value: "" }) + }).transform(compressor); + break; + case "Number": + if (self.args.length == 0) return make_node(AST_Number, self, { + value: 0 }); + if (self.args.length == 1) return make_node(AST_UnaryPrefix, self, { + expression: self.args[0], + operator: "+" + }).transform(compressor); + case "Boolean": + if (self.args.length == 0) return make_node(AST_False, self); + if (self.args.length == 1) return make_node(AST_UnaryPrefix, self, { + expression: make_node(AST_UnaryPrefix, null, { + expression: self.args[0], + operator: "!" + }), + operator: "!" + }).transform(compressor); + break; case "Function": if (all(self.args, function(x){ return x instanceof AST_String })) { // quite a corner-case, but we can handle it: @@ -1999,6 +2018,16 @@ merge(Compressor.prototype, { && self.right.getValue() === "" && self.left instanceof AST_Binary && self.left.operator == "+" && self.left.is_string(compressor)) { return self.left; + } else if (self.operator == "+" && self.right instanceof AST_String + && self.right.getValue() === "" && self.left instanceof AST_Binary + && self.left.operator == "+" && self.left.right instanceof AST_Number) { + return make_node(AST_Binary, self, { + left: self.left.left, + operator: "+", + right: make_node(AST_String, self.right, { + value: String(self.left.right.value) + }) + }); } if (compressor.option("evaluate")) { if (self.operator == "+") { |