fix corner cases with parameter scope (#5567)

fixes #5566
This commit is contained in:
Alex Lam S.L
2022-07-17 09:03:12 +01:00
committed by GitHub
parent 685ab357cc
commit ec4558be29
3 changed files with 193 additions and 35 deletions

View File

@@ -2647,16 +2647,17 @@ Compressor.prototype.compress = function(node) {
arg = null;
return true;
}
if (node instanceof AST_ObjectIdentity && (fn_strict || !arg_scope)) {
arg = null;
if (node instanceof AST_ObjectIdentity) {
if (fn_strict || !arg_scope) arg = null;
return true;
}
if (node instanceof AST_SymbolRef && fn.variables.has(node.name)) {
var s = node.definition().scope;
if (s !== scope) while (s = s.parent_scope) {
if (s === scope) return true;
if (node instanceof AST_SymbolRef) {
var def;
if (node.in_arg && !is_safe_lexical(node.definition())
|| (def = fn.variables.get(node.name)) && def !== node.definition()) {
arg = null;
}
arg = null;
return true;
}
if (node instanceof AST_Scope && !is_arrow(node)) {
var save_scope = arg_scope;
@@ -5985,7 +5986,7 @@ Compressor.prototype.compress = function(node) {
return true;
}
if (node instanceof AST_SymbolRef) {
if (self.inlined || node.redef) {
if (self.inlined || node.redef || node.in_arg) {
result = false;
return true;
}
@@ -7679,6 +7680,7 @@ Compressor.prototype.compress = function(node) {
var def = node.left.definition();
if (def.scope.resolve() === self) assignments.add(def.id, node);
}
if (node instanceof AST_SymbolRef && node.in_arg) var_defs[node.definition().id] = 0;
if (node instanceof AST_Unary && node.expression instanceof AST_SymbolRef) {
var def = node.expression.definition();
if (def.scope.resolve() === self) assignments.add(def.id, node);
@@ -8172,7 +8174,9 @@ Compressor.prototype.compress = function(node) {
// collect only vars which don't show up in self's arguments list
var defns = [];
if (self instanceof AST_Lambda) self.each_argname(function(argname) {
vars.del(argname.name);
if (all(argname.definition().references, function(ref) {
return !ref.in_arg;
})) vars.del(argname.name);
});
vars.each(function(defn, name) {
defn = defn.clone();