fix corner case in merge_vars (#5661)

fixes #5660
This commit is contained in:
Alex Lam S.L
2022-09-14 16:36:54 +01:00
committed by GitHub
parent fa2511f71c
commit e0b302d651
2 changed files with 58 additions and 14 deletions

View File

@@ -6560,16 +6560,19 @@ Compressor.prototype.compress = function(node) {
if (node instanceof AST_SymbolVar) {
mark(node);
} else {
references[node.definition().id] = false;
node.walk(tw);
}
} : function(node) {
var id = node.definition().id;
if (!(node instanceof AST_SymbolVar)) {
references[id] = false;
} else if (!(id in references)) {
declarations.add(id, node);
} else if (references[id]) {
references[id].push(node);
if (node instanceof AST_SymbolVar) {
var id = node.definition().id;
var refs = references[id];
if (refs) {
refs.push(node);
} else if (!(id in references)) {
declarations.add(id, node);
}
} else {
node.walk(tw);
}
}, node.name);
return true;
@@ -6650,8 +6653,8 @@ Compressor.prototype.compress = function(node) {
|| (head_refs.start.loop || !same_scope(def)) && !mergeable(tail_refs, head_refs)
|| compressor.option("webkit") && is_funarg(def) !== is_funarg(head.definition)
|| head.definition.const_redefs
|| !all(head_refs, function(sym) {
return sym.scope.find_variable(def.name) === def;
|| !all(head_refs.scopes, function(scope) {
return scope.find_variable(def.name) === def;
})) {
skipped.push(head);
continue;
@@ -6733,8 +6736,7 @@ Compressor.prototype.compress = function(node) {
var refs = references[def.id];
if (!refs) return;
if (refs.start.block !== seg.block) return references[def.id] = false;
sym.scope = find_scope(tw);
refs.push(sym);
push_ref(sym);
refs.end = seg;
if (def.id in prev) {
last[prev[def.id]] = null;
@@ -6748,8 +6750,8 @@ Compressor.prototype.compress = function(node) {
return references[def.id] = false;
} else {
var refs = declarations.get(def.id) || [];
sym.scope = find_scope(tw);
refs.push(sym);
refs.scopes = [];
push_ref(sym);
references[def.id] = refs;
if (!read) {
refs.start = seg;
@@ -6766,6 +6768,13 @@ Compressor.prototype.compress = function(node) {
index: index++,
definition: def,
});
function push_ref(sym) {
refs.push(sym);
push_uniq(refs.scopes, sym.scope);
var scope = find_scope(tw);
if (scope !== sym.scope) push_uniq(refs.scopes, scope);
}
}
function insert(target) {