aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralexlamsl <alexlamsl@gmail.com>2020-09-22 07:48:55 +0800
committeralexlamsl <alexlamsl@gmail.com>2020-09-22 07:48:55 +0800
commit8c670cae93c1fda0e893ef27cccfb515b836c30d (patch)
tree507835024944f45fe3b82fd5cec44ea4a7af49b9
parent0e3da27727194f6aaab5a08913008b0fc4153501 (diff)
downloadtracifyjs-8c670cae93c1fda0e893ef27cccfb515b836c30d.tar.gz
tracifyjs-8c670cae93c1fda0e893ef27cccfb515b836c30d.zip
enhance `unused`
-rw-r--r--lib/compress.js15
-rw-r--r--test/compress/functions.js2
-rw-r--r--test/compress/reduce_vars.js2
3 files changed, 12 insertions, 7 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 767d5f9c..cf46e47f 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -771,6 +771,7 @@ merge(Compressor.prototype, {
var j = fn.argnames.indexOf(arg);
return (j < 0 ? value : iife.args[j]) || make_node(AST_Undefined, iife);
};
+ d.fixed.assigns = [ arg ];
} else {
d.fixed = false;
}
@@ -4649,7 +4650,9 @@ merge(Compressor.prototype, {
return true; // don't go in nested scopes
}
if (node instanceof AST_SymbolFunarg && scope === self) {
- var_defs_by_id.add(node.definition().id, node);
+ var node_def = node.definition();
+ var_defs_by_id.add(node_def.id, node);
+ assignments.add(node_def.id, node);
}
if (node instanceof AST_Definitions && scope === self) {
node.definitions.forEach(function(def) {
@@ -4790,7 +4793,8 @@ merge(Compressor.prototype, {
var trim = compressor.drop_fargs(node, parent);
for (var a = node.argnames, i = a.length; --i >= 0;) {
var sym = a[i];
- if (!(sym.definition().id in in_use_ids)) {
+ var def = sym.definition();
+ if (!(def.id in in_use_ids)) {
sym.__unused = true;
if (trim) {
log(sym, "Dropping unused function argument {name}");
@@ -4798,6 +4802,7 @@ merge(Compressor.prototype, {
}
} else {
trim = false;
+ if (indexOf_assign(def, sym) < 0) sym.__unused = null;
}
}
fns_with_marked_args.push(node);
@@ -6457,10 +6462,10 @@ merge(Compressor.prototype, {
var side_effects = [];
for (var i = 0; i < args.length; i++) {
var trim = i >= fn.argnames.length;
- if (trim || fn.argnames[i].__unused) {
+ if (trim || "__unused" in fn.argnames[i]) {
var node = args[i].drop_side_effect_free(compressor);
- if (drop_fargs) {
- fn.argnames.splice(i, 1);
+ if (drop_fargs && (trim || fn.argnames[i].__unused)) {
+ if (!trim) fn.argnames.splice(i, 1);
args.splice(i, 1);
if (node) side_effects.push(node);
i--;
diff --git a/test/compress/functions.js b/test/compress/functions.js
index 8bfb2eaf..3027d59e 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -2676,7 +2676,7 @@ cross_references_3: {
};
return Math.square(n) + Math.cube(n);
};
- }(Math)(2));
+ }()(2));
console.log(Math.square(3), Math.cube(3));
}
expect_stdout: [
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index 153ac5d4..a79dd068 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -2415,7 +2415,7 @@ redefine_farg_2: {
console.log(typeof [], "number",function(a, b) {
a = b;
return typeof a;
- }([]));
+ }());
}
expect_stdout: "object number undefined"
}