[Pkg-javascript-commits] [uglifyjs] 332/491: improve `collapse_vars` (#2591)
Jonas Smedegaard
dr at jones.dk
Wed Feb 14 19:51:50 UTC 2018
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag debian/3.3.10-1
in repository uglifyjs.
commit 738fd52bc46c043db4a0cd415671f54b392ee6ac
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Thu Dec 14 15:31:35 2017 +0800
improve `collapse_vars` (#2591)
- handle single-use assignments other than `AST_VarDef`
- scan `AST_Call` for candidates
---
lib/compress.js | 8 +++++++-
test/compress/collapse_vars.js | 22 +++++++++++++++++++---
2 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/lib/compress.js b/lib/compress.js
index e394e8b..05e0e1a 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1014,7 +1014,9 @@ merge(Compressor.prototype, {
var replace_all = value_def;
if (!replace_all && lhs instanceof AST_SymbolRef) {
var def = lhs.definition();
- replace_all = def.references.length - def.replaced == 1;
+ if (def.references.length - def.replaced == (candidate instanceof AST_VarDef ? 1 : 2)) {
+ replace_all = true;
+ }
}
var side_effects = value_has_side_effects(candidate);
var may_throw = candidate.may_throw(compressor);
@@ -1097,6 +1099,9 @@ merge(Compressor.prototype, {
if (expr instanceof AST_Assign && !expr.left.has_side_effects(compressor)
|| expr instanceof AST_Unary && (expr.operator == "++" || expr.operator == "--")) {
candidates.push(expr);
+ } else if (expr instanceof AST_Call) {
+ extract_candidates(expr.expression);
+ expr.args.forEach(extract_candidates);
} else if (expr instanceof AST_Case) {
extract_candidates(expr.expression);
} else if (expr instanceof AST_Conditional) {
@@ -1125,6 +1130,7 @@ merge(Compressor.prototype, {
function find_stop(node, level) {
var parent = scanner.parent(level);
+ if (parent instanceof AST_Call) return node;
if (parent instanceof AST_Case) return node;
if (parent instanceof AST_Conditional) return node;
if (parent instanceof AST_Exit) return node;
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index bd1362b..39d6b64 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -1993,10 +1993,8 @@ undeclared: {
}
expect: {
function f(x, y) {
- var a;
- a = x;
b = y;
- return b + a;
+ return b + x;
}
}
}
@@ -3978,3 +3976,21 @@ cascade_switch: {
}
}
}
+
+cascade_call: {
+ options = {
+ collapse_vars: true,
+ unused: true,
+ }
+ input: {
+ function f(a) {
+ var b;
+ return x((b = a, y(b)));
+ }
+ }
+ expect: {
+ function f(a) {
+ return x(y(a));
+ }
+ }
+}
--
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