Take operator || precendence into account for AST_If optimization.
Fixes #979.
This commit is contained in:
@@ -1688,9 +1688,13 @@ merge(Compressor.prototype, {
|
||||
}
|
||||
if (is_empty(self.alternative)) self.alternative = null;
|
||||
var negated = self.condition.negate(compressor);
|
||||
var negated_is_best = best_of(self.condition, negated) === negated;
|
||||
var self_condition_length = self.condition.print_to_string().length;
|
||||
var negated_length = negated.print_to_string().length;
|
||||
var negated_is_best = negated_length < self_condition_length;
|
||||
if (self.alternative && negated_is_best) {
|
||||
negated_is_best = false; // because we already do the switch here.
|
||||
// no need to swap values of self_condition_length and negated_length
|
||||
// here because they are only used in an equality comparison later on.
|
||||
self.condition = negated;
|
||||
var tmp = self.body;
|
||||
self.body = self.alternative || make_node(AST_EmptyStatement);
|
||||
@@ -1712,6 +1716,13 @@ merge(Compressor.prototype, {
|
||||
}).transform(compressor);
|
||||
}
|
||||
if (is_empty(self.alternative) && self.body instanceof AST_SimpleStatement) {
|
||||
if (self_condition_length === negated_length && !negated_is_best
|
||||
&& self.condition instanceof AST_Binary && self.condition.operator == "||") {
|
||||
// although the code length of self.condition and negated are the same,
|
||||
// negated does not require additional surrounding parentheses.
|
||||
// see https://github.com/mishoo/UglifyJS2/issues/979
|
||||
negated_is_best = true;
|
||||
}
|
||||
if (negated_is_best) return make_node(AST_SimpleStatement, self, {
|
||||
body: make_node(AST_Binary, self, {
|
||||
operator : "||",
|
||||
|
||||
Reference in New Issue
Block a user