Optimize conditionals where the consequent and alternative are both booleans and not equivalent

This commit is contained in:
Tal Ater
2014-09-13 18:59:19 +03:00
committed by Richard van Velzen
parent 189dbf02b6
commit a1a4c2ada7
2 changed files with 68 additions and 0 deletions

View File

@@ -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;
});