diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-03-05 17:15:37 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-05 17:15:37 +0800 |
commit | 067e5a5762cb5da8948ccb9bde4d020decb8d55b (patch) | |
tree | 0f8b2ed3af9083cd1ba6cac123ff9f8e94f3c670 /lib/compress.js | |
parent | 33b5f3198469f53641172c0702a7f40566325fb0 (diff) | |
download | tracifyjs-067e5a5762cb5da8948ccb9bde4d020decb8d55b.tar.gz tracifyjs-067e5a5762cb5da8948ccb9bde4d020decb8d55b.zip |
fixup for #1553 (#1555)
- `++a` is the one that is foldable
- transform `a++` into `++a` for better optimisation
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js index f1409d90..d9a67c16 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -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"; |