fix corner case in assignments (#5426)

fixes #5425
This commit is contained in:
Alex Lam S.L
2022-04-19 13:19:30 +08:00
committed by GitHub
parent fbdb7eeda3
commit a0c0c294c5
2 changed files with 31 additions and 3 deletions

View File

@@ -11139,9 +11139,15 @@ Compressor.prototype.compress = function(node) {
&& assign instanceof AST_Assign
&& assign.operator == "="
&& self.left.equivalent_to(assign.left)) {
self.right = assign.right;
assign.right = self;
return assign;
return make_node(AST_Assign, self, {
operator: "=",
left: assign.left,
right: make_node(AST_Binary, self, {
operator: self.operator,
left: self.left,
right: assign.right,
}),
}).optimize(compressor);
}
}
if (compressor.option("comparisons")) switch (self.operator) {

View File

@@ -1525,3 +1525,25 @@ issue_5385_2: {
]
node_version: ">=10"
}
issue_5425: {
options = {
assignments: true,
ie: true,
toplevel: true,
unused: true,
yields: true,
}
input: {
var a = "FAIL";
var b = function* f() {}(a ? a = "PASS" : 42);
console.log(a, typeof f);
}
expect: {
var a = "FAIL";
(function* f() {})(a && (a = "PASS"));
console.log(a, typeof f);
}
expect_stdout: "PASS undefined"
node_version: ">=4"
}