[Pkg-javascript-commits] [uglifyjs] 80/228: fixup for #1553 (#1555)
Jonas Smedegaard
dr at jones.dk
Sat Apr 15 14:25:19 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository uglifyjs.
commit 067e5a5762cb5da8948ccb9bde4d020decb8d55b
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Sun Mar 5 17:15:37 2017 +0800
fixup for #1553 (#1555)
- `++a` is the one that is foldable
- transform `a++` into `++a` for better optimisation
---
lib/compress.js | 10 +++++++---
test/compress/issue-368.js | 16 +++++++++++++++-
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/lib/compress.js b/lib/compress.js
index f1409d9..d9a67c1 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";
diff --git a/test/compress/issue-368.js b/test/compress/issue-368.js
index 8c41a89..5960aa6 100644
--- a/test/compress/issue-368.js
+++ b/test/compress/issue-368.js
@@ -21,6 +21,16 @@ collapse: {
var a;
a = b(a / 2);
if (a < 0) {
+ a++;
+ ++c;
+ return c / 2;
+ }
+ }
+ function f4(c) {
+ var a;
+ a = b(a / 2);
+ if (a < 0) {
+ a++;
c++;
return c / 2;
}
@@ -35,7 +45,11 @@ collapse: {
}
function f3(c) {
var a;
- if ((a = b(a / 2)) < 0) return c++ / 2;
+ if ((a = b(a / 2)) < 0) return a++, ++c / 2;
+ }
+ function f4(c) {
+ var a;
+ if ((a = b(a / 2)) < 0) return a++, ++c / 2;
}
}
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git
More information about the Pkg-javascript-commits
mailing list