aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js33
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 == "+") {