minor optimization
unlikely to help in hand-written code:
(something() ? foo : bar) == foo ==> something()
This commit is contained in:
@@ -1882,6 +1882,32 @@ merge(Compressor.prototype, {
|
||||
// result. hence, force switch.
|
||||
reverse(null, true);
|
||||
}
|
||||
if (/^[!=]==?$/.test(self.operator)) {
|
||||
if (self.left instanceof AST_SymbolRef && self.right instanceof AST_Conditional) {
|
||||
if (self.right.consequent instanceof AST_SymbolRef
|
||||
&& self.right.consequent.definition() === self.left.definition()) {
|
||||
if (/^==/.test(self.operator)) return self.right.condition;
|
||||
if (/^!=/.test(self.operator)) return self.right.condition.negate(compressor);
|
||||
}
|
||||
if (self.right.alternative instanceof AST_SymbolRef
|
||||
&& self.right.alternative.definition() === self.left.definition()) {
|
||||
if (/^==/.test(self.operator)) return self.right.condition.negate(compressor);
|
||||
if (/^!=/.test(self.operator)) return self.right.condition;
|
||||
}
|
||||
}
|
||||
if (self.right instanceof AST_SymbolRef && self.left instanceof AST_Conditional) {
|
||||
if (self.left.consequent instanceof AST_SymbolRef
|
||||
&& self.left.consequent.definition() === self.right.definition()) {
|
||||
if (/^==/.test(self.operator)) return self.left.condition;
|
||||
if (/^!=/.test(self.operator)) return self.left.condition.negate(compressor);
|
||||
}
|
||||
if (self.left.alternative instanceof AST_SymbolRef
|
||||
&& self.left.alternative.definition() === self.right.definition()) {
|
||||
if (/^==/.test(self.operator)) return self.left.condition.negate(compressor);
|
||||
if (/^!=/.test(self.operator)) return self.left.condition;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
self = self.lift_sequences(compressor);
|
||||
if (compressor.option("comparisons")) switch (self.operator) {
|
||||
|
||||
Reference in New Issue
Block a user