clean up lazy operator detection (#2373)
This commit is contained in:
@@ -404,8 +404,7 @@ merge(Compressor.prototype, {
|
|||||||
pop();
|
pop();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Binary
|
if (node instanceof AST_Binary && lazy_op(node.operator)) {
|
||||||
&& (node.operator == "&&" || node.operator == "||")) {
|
|
||||||
node.left.walk(tw);
|
node.left.walk(tw);
|
||||||
push();
|
push();
|
||||||
node.right.walk(tw);
|
node.right.walk(tw);
|
||||||
@@ -844,8 +843,7 @@ merge(Compressor.prototype, {
|
|||||||
&& (lvalues[node.name]
|
&& (lvalues[node.name]
|
||||||
|| side_effects && !references_in_scope(node.definition()))
|
|| side_effects && !references_in_scope(node.definition()))
|
||||||
|| (sym = lhs_or_def(node)) && get_symbol(sym).name in lvalues
|
|| (sym = lhs_or_def(node)) && get_symbol(sym).name in lvalues
|
||||||
|| parent instanceof AST_Binary
|
|| parent instanceof AST_Binary && lazy_op(parent.operator)
|
||||||
&& (parent.operator == "&&" || parent.operator == "||")
|
|
||||||
|| parent instanceof AST_Case
|
|| parent instanceof AST_Case
|
||||||
|| parent instanceof AST_Conditional
|
|| parent instanceof AST_Conditional
|
||||||
|| parent instanceof AST_For
|
|| parent instanceof AST_For
|
||||||
@@ -1434,9 +1432,10 @@ merge(Compressor.prototype, {
|
|||||||
return member(this.operator, unary_bool);
|
return member(this.operator, unary_bool);
|
||||||
});
|
});
|
||||||
def(AST_Binary, function(){
|
def(AST_Binary, function(){
|
||||||
return member(this.operator, binary_bool) ||
|
return member(this.operator, binary_bool)
|
||||||
( (this.operator == "&&" || this.operator == "||") &&
|
|| lazy_op(this.operator)
|
||||||
this.left.is_boolean() && this.right.is_boolean() );
|
&& this.left.is_boolean()
|
||||||
|
&& this.right.is_boolean();
|
||||||
});
|
});
|
||||||
def(AST_Conditional, function(){
|
def(AST_Conditional, function(){
|
||||||
return this.consequent.is_boolean() && this.alternative.is_boolean();
|
return this.consequent.is_boolean() && this.alternative.is_boolean();
|
||||||
@@ -1505,6 +1504,7 @@ merge(Compressor.prototype, {
|
|||||||
node.DEFMETHOD("is_string", func);
|
node.DEFMETHOD("is_string", func);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var lazy_op = makePredicate("&& ||");
|
||||||
var unary_side_effects = makePredicate("delete ++ --");
|
var unary_side_effects = makePredicate("delete ++ --");
|
||||||
|
|
||||||
function is_lhs(node, parent) {
|
function is_lhs(node, parent) {
|
||||||
@@ -2701,14 +2701,12 @@ merge(Compressor.prototype, {
|
|||||||
def(AST_Binary, function(compressor, first_in_statement){
|
def(AST_Binary, function(compressor, first_in_statement){
|
||||||
var right = this.right.drop_side_effect_free(compressor);
|
var right = this.right.drop_side_effect_free(compressor);
|
||||||
if (!right) return this.left.drop_side_effect_free(compressor, first_in_statement);
|
if (!right) return this.left.drop_side_effect_free(compressor, first_in_statement);
|
||||||
switch (this.operator) {
|
if (lazy_op(this.operator)) {
|
||||||
case "&&":
|
|
||||||
case "||":
|
|
||||||
if (right === this.right) return this;
|
if (right === this.right) return this;
|
||||||
var node = this.clone();
|
var node = this.clone();
|
||||||
node.right = right;
|
node.right = right;
|
||||||
return node;
|
return node;
|
||||||
default:
|
} else {
|
||||||
var left = this.left.drop_side_effect_free(compressor, first_in_statement);
|
var left = this.left.drop_side_effect_free(compressor, first_in_statement);
|
||||||
if (!left) return this.right.drop_side_effect_free(compressor, first_in_statement);
|
if (!left) return this.right.drop_side_effect_free(compressor, first_in_statement);
|
||||||
return make_sequence(this, [ left, right ]);
|
return make_sequence(this, [ left, right ]);
|
||||||
@@ -3574,7 +3572,7 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
if (cdr instanceof AST_Binary && !(cdr instanceof AST_Assign)) {
|
if (cdr instanceof AST_Binary && !(cdr instanceof AST_Assign)) {
|
||||||
if (cdr.left.is_constant()) {
|
if (cdr.left.is_constant()) {
|
||||||
if (cdr.operator == "||" || cdr.operator == "&&") {
|
if (lazy_op(cdr.operator)) {
|
||||||
expressions[++i] = expressions[j];
|
expressions[++i] = expressions[j];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -4074,8 +4072,7 @@ merge(Compressor.prototype, {
|
|||||||
// "x" + (y + "z")==> "x" + y + "z"
|
// "x" + (y + "z")==> "x" + y + "z"
|
||||||
if (self.right instanceof AST_Binary
|
if (self.right instanceof AST_Binary
|
||||||
&& self.right.operator == self.operator
|
&& self.right.operator == self.operator
|
||||||
&& (self.operator == "&&"
|
&& (lazy_op(self.operator)
|
||||||
|| self.operator == "||"
|
|
||||||
|| (self.operator == "+"
|
|| (self.operator == "+"
|
||||||
&& (self.right.left.is_string(compressor)
|
&& (self.right.left.is_string(compressor)
|
||||||
|| (self.left.is_string(compressor)
|
|| (self.left.is_string(compressor)
|
||||||
|
|||||||
Reference in New Issue
Block a user