if (val === null) {
return make_node(AST_Null, orig).optimize(compressor);
}
+ if (val instanceof RegExp) {
+ return make_node(AST_RegExp, orig).optimize(compressor);
+ }
throw new Error(string_template("Can't handle constant of type: {type}", {
type: typeof val
}));
extract_declarations_from_unreachable_code(compressor, self.alternative, a);
}
a.push(self.body);
- return make_node(AST_BlockStatement, self, { body: a });
+ return make_node(AST_BlockStatement, self, { body: a }).transform(compressor);
}
} else {
compressor.warn("Condition always false [{file}:{line},{col}]", self.condition.start);
var a = [];
extract_declarations_from_unreachable_code(compressor, self.body, a);
if (self.alternative) a.push(self.alternative);
- return make_node(AST_BlockStatement, self, { body: a });
+ return make_node(AST_BlockStatement, self, { body: a }).transform(compressor);
}
}
}
if (is_empty(self.body) && is_empty(self.alternative)) {
return make_node(AST_SimpleStatement, self.condition, {
body: self.condition
- });
+ }).transform(compressor);
}
if (self.body instanceof AST_SimpleStatement
&& self.alternative instanceof AST_SimpleStatement) {
consequent : self.body.body,
alternative : self.alternative.body
})
- });
+ }).transform(compressor);
}
if (is_empty(self.alternative) && self.body instanceof AST_SimpleStatement) {
if (negated_is_best) return make_node(AST_SimpleStatement, self, {
left : negated,
right : self.body.body
})
- });
+ }).transform(compressor);
return make_node(AST_SimpleStatement, self, {
body: make_node(AST_Binary, self, {
operator : "&&",
left : self.condition,
right : self.body.body
})
- });
+ }).transform(compressor);
}
if (self.body instanceof AST_EmptyStatement
&& self.alternative
left : self.condition,
right : self.alternative.body
})
- });
+ }).transform(compressor);
}
if (self.body instanceof AST_Exit
&& self.alternative instanceof AST_Exit
consequent : self.body.value,
alternative : self.alternative.value || make_node(AST_Undefined, self).optimize(compressor)
})
- });
+ }).transform(compressor);
}
if (self.body instanceof AST_If
&& !self.body.alternative
self.alternative = null;
return make_node(AST_BlockStatement, self, {
body: [ self, alt ]
- });
+ }).transform(compressor);
}
}
if (aborts(self.alternative)) {
self.alternative = null;
return make_node(AST_BlockStatement, self, {
body: [ self, body ]
- });
+ }).transform(compressor);
}
return self;
});
OPT(AST_Switch, function(self, compressor){
+ if (self.body.length == 0 && compressor.option("conditionals")) {
+ return make_node(AST_SimpleStatement, self, {
+ body: self.expression
+ }).transform(compressor);
+ }
var last_branch = self.body[self.body.length - 1];
if (last_branch) {
var stat = last_branch.body[last_branch.body.length - 1]; // last statement
left: exp.expression,
operator: "+",
right: make_node(AST_String, self, { value: "" })
- });
+ }).transform(compressor);
}
}
if (compressor.option("side_effects")) {
if (self.expression instanceof AST_Function
&& self.args.length == 0
&& !self.expression.has_side_effects()) {
- return make_node(AST_Undefined, self);
+ return make_node(AST_Undefined, self).transform(compressor);
}
}
return self;
return self;
});
+ function literals_in_boolean_context(self, compressor) {
+ if (compressor.option("booleans") && compressor.in_boolean_context()) {
+ return make_node(AST_True, self);
+ }
+ return self;
+ };
+ OPT(AST_Array, literals_in_boolean_context);
+ OPT(AST_Object, literals_in_boolean_context);
+ OPT(AST_RegExp, literals_in_boolean_context);
+
})();