- `++a` is the one that is foldable
- transform `a++` into `++a` for better optimisation
This commit is contained in:
Alex Lam S.L
2017-03-05 17:15:37 +08:00
committed by GitHub
parent 33b5f31984
commit 067e5a5762
2 changed files with 22 additions and 4 deletions

View File

@@ -2833,7 +2833,7 @@ merge(Compressor.prototype, {
if (self.car instanceof AST_Assign
&& !self.car.left.has_side_effects(compressor)) {
left = self.car.left;
} else if (self.car instanceof AST_UnaryPostfix
} else if (self.car instanceof AST_Unary
&& (self.car.operator == "++" || self.car.operator == "--")) {
left = self.car.expression;
}
@@ -2842,11 +2842,15 @@ merge(Compressor.prototype, {
var cdr = self.cdr;
while (true) {
if (cdr.equivalent_to(left)) {
var car = self.car instanceof AST_UnaryPostfix ? make_node(AST_UnaryPrefix, self.car, {
operator: self.car.operator,
expression: left
}) : self.car;
if (parent) {
parent[field] = self.car;
parent[field] = car;
return self.cdr;
}
return self.car;
return car;
}
if (cdr instanceof AST_Binary && !(cdr instanceof AST_Assign)) {
field = cdr.left.is_constant() ? "right" : "left";