fix corner case in merge_vars (#5715)

fixes #5714
This commit is contained in:
Alex Lam S.L
2022-10-17 04:19:43 +01:00
committed by GitHub
parent 5a5200d657
commit 8319badea8
2 changed files with 53 additions and 7 deletions

View File

@@ -6662,15 +6662,15 @@ Compressor.prototype.compress = function(node) {
do {
var head = first.shift();
if (tail.index > head.index) continue;
var id = head.definition.id;
if (!(id in prev)) continue;
var head_refs = references[id];
var prev_def = head.definition;
if (!(prev_def.id in prev)) continue;
var head_refs = references[prev_def.id];
if (!head_refs) continue;
if (head_refs.start.block !== tail_refs.start.block
|| !mergeable(head_refs, tail_refs)
|| (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
|| compressor.option("webkit") && is_funarg(def) !== is_funarg(prev_def)
|| prev_def.const_redefs
|| !all(head_refs.scopes, function(scope) {
return scope.find_variable(def.name) === def;
})) {
@@ -6682,12 +6682,14 @@ Compressor.prototype.compress = function(node) {
sym.name = def.name;
if (sym instanceof AST_SymbolRef) {
def.references.push(sym);
prev_def.replaced++;
} else {
def.orig.push(sym);
prev_def.eliminated++;
}
});
if (!head.definition.fixed) def.fixed = false;
merged[id] = def;
if (!prev_def.fixed) def.fixed = false;
merged[prev_def.id] = def;
changed = true;
break;
} while (first.length);