fix corner case in collapse_vars (#4911)

fixes #4910
This commit is contained in:
Alex Lam S.L
2021-05-04 17:03:43 +01:00
committed by GitHub
parent 3094eaaa89
commit d464be3f3f
3 changed files with 39 additions and 10 deletions

View File

@@ -1777,6 +1777,7 @@ merge(Compressor.prototype, {
}
return node;
} else if (value_def) {
if (stop_if_hit && assign_pos == 0) assign_pos = remaining - replaced;
if (!hit_rhs) replaced++;
return node;
} else {
@@ -1904,14 +1905,14 @@ merge(Compressor.prototype, {
if (is_lhs(node, multi_replacer.parent())) return node;
var ref = rvalue.clone();
value_def.references.push(ref);
if (abort && candidate instanceof AST_Assign && remaining_refs(def) > 1) {
if (replaced == assign_pos) {
abort = true;
return make_node(AST_Assign, candidate, {
operator: "=",
left: node,
right: ref,
});
}
ref.fixed = false;
def.replaced++;
return ref;
}
@@ -1931,6 +1932,8 @@ merge(Compressor.prototype, {
hit_stack = candidates.pop();
var hit_index = 0;
var candidate = hit_stack[hit_stack.length - 1];
var assign_pos = -1;
var assign_used = false;
var remaining;
var value_def = null;
var stop_after = null;
@@ -1962,7 +1965,6 @@ merge(Compressor.prototype, {
var hit = funarg;
var abort = false;
var replaced = 0;
var assign_used = false;
var can_replace = !args || !hit;
if (!can_replace) {
for (var j = candidate.arg_index + 1; !abort && j < args.length; j++) {
@@ -2621,9 +2623,15 @@ merge(Compressor.prototype, {
if (scope.uses_arguments && is_funarg(def)) return lhs;
if (compressor.exposed(def)) return lhs;
remaining = remaining_refs(def);
if (def.fixed && lhs.fixed) remaining = Math.min(remaining, def.references.filter(function(ref) {
return ref.fixed === lhs.fixed;
}).length - 1);
if (def.fixed && lhs.fixed) {
var matches = def.references.filter(function(ref) {
return ref.fixed === lhs.fixed;
}).length - 1;
if (matches < remaining) {
remaining = matches;
assign_pos = 0;
}
}
mangleable_var(expr.right);
return lhs;
}