Skip to content

Commit 4c227cc

Browse files
authored
fix corner cases in inline & unused (#5534)
fixes #5533
1 parent 2426657 commit 4c227cc

File tree

7 files changed

+694
-12
lines changed

7 files changed

+694
-12
lines changed

lib/compress.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6948,7 +6948,7 @@ Compressor.prototype.compress = function(node) {
69486948
node.properties = properties;
69496949
return node;
69506950
}
6951-
if (node instanceof AST_SymbolDeclaration) return node.definition().id in in_use_ids ? node : null;
6951+
if (node instanceof AST_SymbolDeclaration) return trim_decl(node);
69526952
});
69536953
var tt = new TreeTransformer(function(node, descend, in_list) {
69546954
var parent = tt.parent();
@@ -7063,9 +7063,7 @@ Compressor.prototype.compress = function(node) {
70637063
} else {
70647064
var trimmed = trim_destructured(rest, make_node(AST_Array, parent, {
70657065
elements: args.slice(argnames.length),
7066-
}), function(node) {
7067-
return node.definition().id in in_use_ids ? node : null;
7068-
}, !node.uses_arguments, rest);
7066+
}), trim_decl, !node.uses_arguments, rest);
70697067
rest = trimmed.name;
70707068
args.length = argnames.length;
70717069
if (trimmed.value.elements.length) [].push.apply(args, trimmed.value.elements);
@@ -7095,6 +7093,8 @@ Compressor.prototype.compress = function(node) {
70957093
} else if (trim) {
70967094
log(sym, "Dropping unused function argument {name}");
70977095
argnames.pop();
7096+
def.eliminated++;
7097+
sym.unused = true;
70987098
} else {
70997099
sym.unused = true;
71007100
}
@@ -7104,9 +7104,7 @@ Compressor.prototype.compress = function(node) {
71047104
if (!args || spread < i) {
71057105
funarg = sym.transform(trimmer);
71067106
} else {
7107-
var trimmed = trim_destructured(sym, args[i], function(node) {
7108-
return node.definition().id in in_use_ids ? node : null;
7109-
}, trim_value, sym);
7107+
var trimmed = trim_destructured(sym, args[i], trim_decl, trim_value, sym);
71107108
funarg = trimmed.name;
71117109
if (trimmed.value) args[i] = trimmed.value;
71127110
}
@@ -7706,6 +7704,12 @@ Compressor.prototype.compress = function(node) {
77067704
return (node instanceof AST_DefaultValue ? node.name : node) instanceof AST_SymbolDeclaration;
77077705
}
77087706

7707+
function trim_decl(node) {
7708+
if (node.definition().id in in_use_ids) return node;
7709+
if (node instanceof AST_SymbolFunarg) node.unused = true;
7710+
return null;
7711+
}
7712+
77097713
function trim_default(trimmer, node) {
77107714
node.value = node.value.transform(tt);
77117715
var name = node.name.transform(trimmer);
@@ -13660,7 +13664,7 @@ Compressor.prototype.compress = function(node) {
1366013664
if (def.orig.length == 1 && fn.functions.has(name)) return;
1366113665
if (!all(def.orig, function(sym) {
1366213666
if (sym instanceof AST_SymbolConst) return false;
13663-
if (sym instanceof AST_SymbolFunarg) return def.scope.resolve() !== fn;
13667+
if (sym instanceof AST_SymbolFunarg) return !sym.unused && def.scope.resolve() !== fn;
1366413668
if (sym instanceof AST_SymbolLet) return false;
1366513669
return true;
1366613670
})) return;

0 commit comments

Comments
 (0)