fix corner case in side_effects (#5479)

fixes #5478
This commit is contained in:
Alex Lam S.L
2022-05-30 17:27:40 +01:00
committed by GitHub
parent 8bc03dc6c4
commit 3c9e1693d5
2 changed files with 37 additions and 0 deletions

View File

@@ -8345,6 +8345,9 @@ Compressor.prototype.compress = function(node) {
var dropped = value.drop_side_effect_free(compressor);
if (dropped !== value) {
changed = true;
if (dropped && async && !is_primitive(compressor, dropped)) {
dropped = dropped.negate(compressor);
}
node.value = dropped;
}
}

View File

@@ -3001,3 +3001,37 @@ issue_5456: {
expect_stdout: "foo"
node_version: ">=8"
}
issue_5478: {
options = {
side_effects: true,
}
input: {
A = {
get then() {
a = "FAIL";
},
};
var a = "PASS";
(async function() {
for (var b in "foo")
return void A;
})();
console.log(a);
}
expect: {
A = {
get then() {
a = "FAIL";
},
};
var a = "PASS";
(async function() {
for (var b in "foo")
return !A;
})();
console.log(a);
}
expect_stdout: "PASS"
node_version: ">=8"
}