fix corner case in functions (#5035)

fixes #5034
This commit is contained in:
Alex Lam S.L
2021-06-24 12:43:46 +01:00
committed by GitHub
parent 82772ccb12
commit 1a064b6e74
3 changed files with 82 additions and 3 deletions

View File

@@ -6562,10 +6562,25 @@ merge(Compressor.prototype, {
if (def.orig.length > 1) return null;
if (def.assignments > 0) return false;
if (def.name == name) return def;
if (name == "await" && is_async(fn)) return false;
if (name == "yield" && is_generator(fn)) return false;
var forbidden;
switch (name) {
case "await":
forbidden = is_async;
break;
case "yield":
forbidden = is_generator;
break;
}
return all(def.references, function(ref) {
return ref.scope.find_variable(name) === sym;
var scope = ref.scope;
if (scope.find_variable(name) !== sym) return false;
if (forbidden) {
scope = scope.resolve();
do {
if (forbidden(scope)) return false;
} while ((scope = scope.parent_scope.resolve()) && scope !== fn);
}
return true;
}) && def;
}