Skip to content

Commit

Permalink
fix corner case in side_effects (#5002)
Browse files Browse the repository at this point in the history
fixes #5001
  • Loading branch information
alexlamsl committed Jun 13, 2021
1 parent f8b2215 commit 6fc7a2a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -7596,11 +7596,22 @@ merge(Compressor.prototype, {
node.body = body;
}
} else if (body instanceof AST_Sequence) {
var tail = body.tail_node();
if (tail instanceof AST_Await && is_primitive(compressor, tail.expression)) {
tail = tail.expression.drop_side_effect_free(compressor);
body.expressions.pop();
if (tail) body.expressions.push(tail);
var exprs = body.expressions;
for (var i = exprs.length; --i >= 0;) {
var tail = exprs[i];
if (!(tail instanceof AST_Await)) break;
if (!is_primitive(compressor, tail.expression)) break;
if (exprs[i] = tail.expression.drop_side_effect_free(compressor)) break;
}
switch (i) {
case -1:
return make_node(AST_EmptyStatement, node);
case 0:
node.body = exprs[0];
break;
default:
exprs.length = i + 1;
break;
}
}
return node;
Expand Down
22 changes: 22 additions & 0 deletions test/compress/awaits.js
Original file line number Diff line number Diff line change
Expand Up @@ -1758,3 +1758,25 @@ issue_4987: {
]
node_version: ">=8"
}

issue_5001: {
options = {
awaits: true,
inline: true,
side_effects: true,
}
input: {
var a = 0;
(async function() {
a++ | await 42;
})();
console.log(a ? "PASS" : "FAIL");
}
expect: {
var a = 0;
void a++;
console.log(a ? "PASS" : "FAIL");
}
expect_stdout: "PASS"
node_version: ">=8"
}

0 comments on commit 6fc7a2a

Please sign in to comment.