fix corner case in collapse_vars (#5274)

fixes #5273
This commit is contained in:
Alex Lam S.L
2022-01-07 07:00:23 +00:00
committed by GitHub
parent 58bea676ac
commit be8c75bae1
2 changed files with 43 additions and 8 deletions

View File

@@ -1962,21 +1962,27 @@ Compressor.prototype.compress = function(node) {
can_replace = false;
node.right.transform(scanner);
clear_write_only(candidate);
var assign = make_node(AST_Assign, node, {
var folded;
if (abort) {
folded = candidate;
} else {
abort = true;
lhs.definition().fixed = false;
folded = make_node(AST_Binary, candidate, {
operator: compound,
left: lhs,
right: rvalue,
});
}
return make_node(AST_Assign, node, {
operator: "=",
left: node.left,
right: make_node(AST_Binary, node, {
operator: node.operator.slice(0, -1),
left: abort ? candidate : make_node(AST_Binary, candidate, {
operator: compound,
left: lhs,
right: rvalue,
}),
left: folded,
right: node.right,
}),
});
abort = true;
return assign;
}
// Stop immediately if these node types are encountered
if (should_stop(node, parent)) {