fix corner cases in inline & unused (#5534)

fixes #5533
This commit is contained in:
Alex Lam S.L
2022-06-30 08:34:45 +01:00
committed by GitHub
parent 2426657daa
commit 4c227cc6bd
7 changed files with 694 additions and 12 deletions

View File

@@ -6948,7 +6948,7 @@ Compressor.prototype.compress = function(node) {
node.properties = properties;
return node;
}
if (node instanceof AST_SymbolDeclaration) return node.definition().id in in_use_ids ? node : null;
if (node instanceof AST_SymbolDeclaration) return trim_decl(node);
});
var tt = new TreeTransformer(function(node, descend, in_list) {
var parent = tt.parent();
@@ -7063,9 +7063,7 @@ Compressor.prototype.compress = function(node) {
} else {
var trimmed = trim_destructured(rest, make_node(AST_Array, parent, {
elements: args.slice(argnames.length),
}), function(node) {
return node.definition().id in in_use_ids ? node : null;
}, !node.uses_arguments, rest);
}), trim_decl, !node.uses_arguments, rest);
rest = trimmed.name;
args.length = argnames.length;
if (trimmed.value.elements.length) [].push.apply(args, trimmed.value.elements);
@@ -7095,6 +7093,8 @@ Compressor.prototype.compress = function(node) {
} else if (trim) {
log(sym, "Dropping unused function argument {name}");
argnames.pop();
def.eliminated++;
sym.unused = true;
} else {
sym.unused = true;
}
@@ -7104,9 +7104,7 @@ Compressor.prototype.compress = function(node) {
if (!args || spread < i) {
funarg = sym.transform(trimmer);
} else {
var trimmed = trim_destructured(sym, args[i], function(node) {
return node.definition().id in in_use_ids ? node : null;
}, trim_value, sym);
var trimmed = trim_destructured(sym, args[i], trim_decl, trim_value, sym);
funarg = trimmed.name;
if (trimmed.value) args[i] = trimmed.value;
}
@@ -7706,6 +7704,12 @@ Compressor.prototype.compress = function(node) {
return (node instanceof AST_DefaultValue ? node.name : node) instanceof AST_SymbolDeclaration;
}
function trim_decl(node) {
if (node.definition().id in in_use_ids) return node;
if (node instanceof AST_SymbolFunarg) node.unused = true;
return null;
}
function trim_default(trimmer, node) {
node.value = node.value.transform(tt);
var name = node.name.transform(trimmer);
@@ -13660,7 +13664,7 @@ Compressor.prototype.compress = function(node) {
if (def.orig.length == 1 && fn.functions.has(name)) return;
if (!all(def.orig, function(sym) {
if (sym instanceof AST_SymbolConst) return false;
if (sym instanceof AST_SymbolFunarg) return def.scope.resolve() !== fn;
if (sym instanceof AST_SymbolFunarg) return !sym.unused && def.scope.resolve() !== fn;
if (sym instanceof AST_SymbolLet) return false;
return true;
})) return;