fix corner case in merge_vars (#4127)

fixes #4126
This commit is contained in:
Alex Lam S.L
2020-09-19 12:56:21 +01:00
committed by GitHub
parent 3ac533e644
commit 31c6b45036
2 changed files with 78 additions and 9 deletions

View File

@@ -4436,14 +4436,15 @@ merge(Compressor.prototype, {
}
if (node instanceof AST_Try) {
push();
segment.block = node;
walk_body(node, tw);
pop();
if (node.bcatch) {
references[node.bcatch.argname.definition().id] = false;
pop();
push();
walk_body(node.bcatch, tw);
pop();
}
pop();
if (node.bfinally) node.bfinally.walk(tw);
return true;
}
@@ -4475,7 +4476,8 @@ merge(Compressor.prototype, {
var head = first.pop();
var def = head.definition;
if (!(def.id in prev)) continue;
if (!references[def.id]) continue;
var head_refs = references[def.id];
if (!head_refs) continue;
while (def.id in merged) def = merged[def.id];
var skipped = [];
do {
@@ -4483,13 +4485,14 @@ merge(Compressor.prototype, {
if (!tail) continue;
if (tail.index > head.index) continue;
var id = tail.definition.id;
if (!references[id]) continue;
if (!mergeable()) {
var tail_refs = references[id];
if (!tail_refs) continue;
if (!mergeable(head_refs, tail_refs)) {
skipped.unshift(tail);
continue;
}
var orig = [], refs = [];
references[id].forEach(function(sym) {
tail_refs.forEach(function(sym) {
sym.thedef = def;
sym.name = def.name;
if (sym instanceof AST_SymbolRef) {
@@ -4556,9 +4559,7 @@ merge(Compressor.prototype, {
return base === segment || base.isPrototypeOf(segment);
}
function mergeable() {
var head = references[def.id];
var tail = references[id];
function mergeable(head, tail) {
if (head.start.block !== tail.start.block) return false;
return must_visit(head.start, head.end) || must_visit(head.start, tail.start);
}