Optimize conditionals where the consequent and alternative are both booleans and not equivalent
This commit is contained in:
committed by
Richard van Velzen
parent
189dbf02b6
commit
a1a4c2ada7
@@ -2386,6 +2386,20 @@ merge(Compressor.prototype, {
|
||||
|
||||
}
|
||||
}
|
||||
// x=y?true:false --> x=!!y
|
||||
if (consequent instanceof AST_True
|
||||
&& alternative instanceof AST_False) {
|
||||
self.condition = self.condition.negate(compressor);
|
||||
return make_node(AST_UnaryPrefix, self.condition, {
|
||||
operator: "!",
|
||||
expression: self.condition
|
||||
});
|
||||
}
|
||||
// x=y?false:true --> x=!y
|
||||
if (consequent instanceof AST_False
|
||||
&& alternative instanceof AST_True) {
|
||||
return self.condition.negate(compressor)
|
||||
}
|
||||
return self;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user