fix corner case in collapse_vars (#5395)

fixes #5394
This commit is contained in:
Alex Lam S.L
2022-03-29 18:22:57 +01:00
committed by GitHub
parent 8922f08fbf
commit e3d328f741
2 changed files with 27 additions and 2 deletions

View File

@@ -2248,8 +2248,11 @@ Compressor.prototype.compress = function(node) {
var lvalues = get_lvalues(candidate);
var lhs_local = is_lhs_local(lhs);
var rhs_value = get_rvalue(candidate);
var rvalue = !compound && rhs_value instanceof AST_Sequence ? rhs_value.tail_node() : rhs_value;
if (!side_effects) side_effects = value_has_side_effects();
var rvalue = rhs_value;
if (!side_effects) {
if (!compound && rvalue instanceof AST_Sequence) rvalue = rvalue.tail_node();
side_effects = value_has_side_effects();
}
var check_destructured = in_try || !lhs_local ? function(node) {
return node instanceof AST_Destructured;
} : return_false;

View File

@@ -9925,3 +9925,25 @@ issue_5309_2: {
}
expect_stdout: "PASS"
}
issue_5394: {
options = {
collapse_vars: true,
evaluate: true,
}
input: {
try {
throw A.p = (console.log("FAIL"), []), !1;
} catch (e) {
console.log(typeof e);
}
}
expect: {
try {
throw !(A.p = (console.log("FAIL"), []));
} catch (e) {
console.log(typeof e);
}
}
expect_stdout: "object"
}