optimize conditional when condition symbol matches consequent (#1684)

This commit is contained in:
kzc
2017-03-26 04:36:33 -04:00
committed by Alex Lam S.L
parent 94f84727ce
commit 5509e51098
2 changed files with 40 additions and 0 deletions

View File

@@ -3565,8 +3565,19 @@ merge(Compressor.prototype, {
alternative: self.consequent
});
}
var condition = self.condition;
var consequent = self.consequent;
var alternative = self.alternative;
// x?x:y --> x||y
if (condition instanceof AST_SymbolRef
&& consequent instanceof AST_SymbolRef
&& condition.definition() === consequent.definition()) {
return make_node(AST_Binary, self, {
operator: "||",
left: condition,
right: alternative
});
}
// if (foo) exp = something; else exp = something_else;
// |
// v