fix corner case in join_vars (#5746)

fixes #5745
This commit is contained in:
Alex Lam S.L
2022-11-23 15:49:30 +02:00
committed by GitHub
parent 4e7744af2d
commit 2352909c3d
3 changed files with 76 additions and 3 deletions

View File

@@ -10255,8 +10255,18 @@ Compressor.prototype.compress = function(node) {
return all(this.definitions, function(defn) {
return !defn.name.match_symbol(function(node) {
if (!(node instanceof AST_SymbolDeclaration)) return false;
if (node.definition().first_decl !== node) return true;
return !safe_from_tdz(compressor, node);
var def = node.definition();
if (def.first_decl !== node) return true;
if (!safe_from_tdz(compressor, node)) return true;
var defn_scope = node.scope;
if (defn_scope instanceof AST_Scope) return false;
return !all(def.references, function(ref) {
var scope = ref.scope;
do {
if (scope === defn_scope) return true;
} while (scope = scope.parent_scope);
return false;
});
}, true);
});
});