[Pkg-javascript-commits] [uglifyjs] 171/491: drop argument value after `collapse_vars` (#2190)
Jonas Smedegaard
dr at jones.dk
Wed Feb 14 19:51:32 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 8b69a3d18e38a63565dce1758dba79615b54cc79
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Sun Jul 2 04:28:11 2017 +0800
drop argument value after `collapse_vars` (#2190)
---
lib/compress.js | 14 +++++++++++---
test/compress/collapse_vars.js | 41 ++++++++++++++++++++++++++++++++++++++++-
test/compress/drop-unused.js | 2 +-
3 files changed, 52 insertions(+), 5 deletions(-)
diff --git a/lib/compress.js b/lib/compress.js
index dffdd6e..eb3ba75 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -902,6 +902,14 @@ merge(Compressor.prototype, {
}
function remove_candidate(expr) {
+ if (expr.name instanceof AST_SymbolFunarg) {
+ var index = compressor.self().argnames.indexOf(expr.name);
+ var args = compressor.parent().args;
+ if (args[index]) args[index] = make_node(AST_Number, args[index], {
+ value: 0
+ });
+ return true;
+ }
var found = false;
return statements[stat_index].transform(new TreeTransformer(function(node, descend, in_list) {
if (found) return node;
@@ -3205,7 +3213,7 @@ merge(Compressor.prototype, {
var value = stat.value;
if (!value || value.is_constant_expression()) {
var args = self.args.concat(value || make_node(AST_Undefined, self));
- return make_sequence(self, args).transform(compressor);
+ return make_sequence(self, args).optimize(compressor);
}
}
if (exp instanceof AST_Function) {
@@ -3246,12 +3254,12 @@ merge(Compressor.prototype, {
}
if (value) {
var args = self.args.concat(value);
- return make_sequence(self, args).transform(compressor);
+ return make_sequence(self, args).optimize(compressor);
}
}
if (compressor.option("side_effects") && all(exp.body, is_empty)) {
var args = self.args.concat(make_node(AST_Undefined, self));
- return make_sequence(self, args).transform(compressor);
+ return make_sequence(self, args).optimize(compressor);
}
}
if (compressor.option("drop_console")) {
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index f3eb781..24f8ffa 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -2187,7 +2187,7 @@ compound_assignment: {
expect_stdout: "4"
}
-issue_2187: {
+issue_2187_1: {
options = {
collapse_vars: true,
unused: true,
@@ -2217,3 +2217,42 @@ issue_2187: {
"2",
]
}
+
+issue_2187_2: {
+ options = {
+ collapse_vars: true,
+ unused: true,
+ }
+ input: {
+ var b = 1;
+ console.log(function(a) {
+ return a && ++b;
+ }(b--));
+ }
+ expect: {
+ var b = 1;
+ console.log(function(a) {
+ return b-- && ++b;
+ }());
+ }
+ expect_stdout: "1"
+}
+
+issue_2187_3: {
+ options = {
+ collapse_vars: true,
+ inline: true,
+ unused: true,
+ }
+ input: {
+ var b = 1;
+ console.log(function(a) {
+ return a && ++b;
+ }(b--));
+ }
+ expect: {
+ var b = 1;
+ console.log(b-- && ++b);
+ }
+ expect_stdout: "1"
+}
diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js
index e1acdc1..a44107a 100644
--- a/test/compress/drop-unused.js
+++ b/test/compress/drop-unused.js
@@ -1113,7 +1113,7 @@ issue_2105: {
options = {
collapse_vars: true,
inline: true,
- passes: 2,
+ passes: 3,
reduce_vars: true,
side_effects: true,
unused: true,
--
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