Merge branch 'master' into harmony
This commit is contained in:
@@ -67,6 +67,7 @@ function Compressor(options, false_by_default) {
|
||||
if_return : !false_by_default,
|
||||
join_vars : !false_by_default,
|
||||
collapse_vars : false,
|
||||
reduce_vars : false,
|
||||
cascade : !false_by_default,
|
||||
side_effects : !false_by_default,
|
||||
pure_getters : false,
|
||||
@@ -1138,7 +1139,7 @@ merge(Compressor.prototype, {
|
||||
this._evaluating = true;
|
||||
try {
|
||||
var d = this.definition();
|
||||
if (d && d.constant && d.init) {
|
||||
if (d && (d.constant || compressor.option("reduce_vars") && !d.modified) && d.init) {
|
||||
return ev(d.init, compressor);
|
||||
}
|
||||
} finally {
|
||||
@@ -2400,6 +2401,12 @@ merge(Compressor.prototype, {
|
||||
// typeof always returns a non-empty string, thus it's
|
||||
// always true in booleans
|
||||
compressor.warn("Boolean expression always true [{file}:{line},{col}]", self.start);
|
||||
if (self.expression.has_side_effects(compressor)) {
|
||||
return make_node(AST_Seq, self, {
|
||||
car: self.expression,
|
||||
cdr: make_node(AST_True, self)
|
||||
});
|
||||
}
|
||||
return make_node(AST_True, self);
|
||||
}
|
||||
if (e instanceof AST_Binary && self.operator == "!") {
|
||||
@@ -2586,8 +2593,8 @@ merge(Compressor.prototype, {
|
||||
case "+":
|
||||
var ll = self.left.evaluate(compressor);
|
||||
var rr = self.right.evaluate(compressor);
|
||||
if ((ll.length > 1 && ll[0] instanceof AST_String && ll[1]) ||
|
||||
(rr.length > 1 && rr[0] instanceof AST_String && rr[1])) {
|
||||
if ((ll.length > 1 && ll[0] instanceof AST_String && ll[1] && !self.right.has_side_effects(compressor)) ||
|
||||
(rr.length > 1 && rr[0] instanceof AST_String && rr[1] && !self.left.has_side_effects(compressor))) {
|
||||
compressor.warn("+ in boolean context always true [{file}:{line},{col}]", self.start);
|
||||
return make_node(AST_True, self);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user