fix corner case in reduce_vars & unused (#4465)

fixes #4464
This commit is contained in:
Alex Lam S.L
2020-12-26 08:52:16 +00:00
committed by GitHub
parent be1f5199f4
commit 94f3819dc6
3 changed files with 87 additions and 6 deletions

View File

@@ -363,6 +363,10 @@ merge(Compressor.prototype, {
return orig.length == 1 && orig[0] instanceof AST_SymbolFunarg;
}
function is_funarg(def) {
return def.orig[0] instanceof AST_SymbolFunarg || def.orig[1] instanceof AST_SymbolFunarg;
}
function cross_scope(def, sym) {
do {
if (def === sym) return false;
@@ -371,9 +375,9 @@ merge(Compressor.prototype, {
}
function can_drop_symbol(ref, keep_lambda) {
var orig = ref.definition().orig;
if (ref.in_arg && (orig[0] instanceof AST_SymbolFunarg || orig[1] instanceof AST_SymbolFunarg)) return false;
return all(orig, function(sym) {
var def = ref.definition();
if (ref.in_arg && is_funarg(def)) return false;
return all(def.orig, function(sym) {
return !(sym instanceof AST_SymbolConst || sym instanceof AST_SymbolLet
|| keep_lambda && sym instanceof AST_SymbolLambda);
});
@@ -541,7 +545,8 @@ merge(Compressor.prototype, {
return compressor.option("unused")
&& !def.scope.pinned()
&& def.single_use !== false
&& def.references.length - def.recursive_refs == 1;
&& def.references.length - def.recursive_refs == 1
&& !(is_funarg(def) && def.scope.uses_arguments);
}
function is_immutable(value) {
@@ -9331,7 +9336,7 @@ merge(Compressor.prototype, {
single_use = false;
} else if (fixed.name && fixed.name.definition() !== def) {
single_use = false;
} else if (fixed.parent_scope !== self.scope.resolve() || def.orig[0] instanceof AST_SymbolFunarg) {
} else if (fixed.parent_scope !== self.scope.resolve() || is_funarg(def)) {
single_use = fixed.is_constant_expression(self.scope);
if (single_use == "f") {
var scope = self.scope;
@@ -9414,7 +9419,7 @@ merge(Compressor.prototype, {
if (fixed && (local || def.should_replace !== false)) {
var init;
if (fixed instanceof AST_This) {
if (!(def.orig[0] instanceof AST_SymbolFunarg) && same_scope(def)) {
if (!is_funarg(def) && same_scope(def)) {
init = fixed;
}
} else {