aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-09-29 00:01:38 +0100
committerGitHub <noreply@github.com>2020-09-29 07:01:38 +0800
commit1d835ac17de613093a538a4ab72160508197e08c (patch)
tree3ecfd2753bc60da4f484b333a2c0a5e0541e9dc0
parent9e07ac410261dcbc074a29598a974b5de7cbe1da (diff)
downloadtracifyjs-1d835ac17de613093a538a4ab72160508197e08c.tar.gz
tracifyjs-1d835ac17de613093a538a4ab72160508197e08c.zip
fix corner case in `inline` (#4160)
fixes #4159
-rw-r--r--lib/compress.js18
-rw-r--r--test/compress/functions.js21
2 files changed, 33 insertions, 6 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 360bbe7a..69394a3d 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -4793,15 +4793,15 @@ merge(Compressor.prototype, {
for (var a = node.argnames, i = a.length; --i >= 0;) {
var sym = a[i];
var def = sym.definition();
- if (!(def.id in in_use_ids)) {
+ if (def.id in in_use_ids) {
+ trim = false;
+ if (indexOf_assign(def, sym) < 0) sym.__unused = null;
+ } else {
sym.__unused = true;
if (trim) {
log(sym, "Dropping unused function argument {name}");
a.pop();
}
- } else {
- trim = false;
- if (indexOf_assign(def, sym) < 0) sym.__unused = null;
}
}
fns_with_marked_args.push(node);
@@ -7047,9 +7047,10 @@ merge(Compressor.prototype, {
value: null
}));
}
+ if (!value) return;
var sym = make_node(AST_SymbolRef, name, name);
def.references.push(sym);
- if (value) expressions.push(make_node(AST_Assign, self, {
+ expressions.push(make_node(AST_Assign, self, {
operator: "=",
left: sym,
right: value
@@ -7070,7 +7071,12 @@ merge(Compressor.prototype, {
var symbol = make_node(AST_SymbolVar, name, name);
name.definition().orig.push(symbol);
if (!value && in_loop) value = make_node(AST_Undefined, self);
- append_var(decls, expressions, symbol, value);
+ if ("__unused" in name) {
+ append_var(decls, expressions, symbol);
+ if (value) expressions.push(value);
+ } else {
+ append_var(decls, expressions, symbol, value);
+ }
}
}
decls.reverse();
diff --git a/test/compress/functions.js b/test/compress/functions.js
index 1be01167..4d753469 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -4808,3 +4808,24 @@ issue_4155: {
"function",
]
}
+
+issue_4159: {
+ options = {
+ collapse_vars: true,
+ inline: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var a = 42, c = function(b) {
+ (b = a) && console.log(a++, b);
+ }(c = a);
+ }
+ expect: {
+ var a = 42;
+ (b = a) && console.log(a++, b);
+ var b;
+ }
+ expect_stdout: "42 42"
+}