Skip to content

Commit

Permalink
fix corner case in hoist_props (#5654)
Browse files Browse the repository at this point in the history
fixes #5653
  • Loading branch information
alexlamsl authored Sep 8, 2022
1 parent 5b5f6e3 commit 02d966d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -8486,9 +8486,18 @@ Compressor.prototype.compress = function(node) {
return make_sequence(node, assignments);
}
if (node instanceof AST_Scope) {
if (node === self) return;
var parent = tt.parent();
if (parent.TYPE == "Call" && parent.expression === node) return;
var parent;
if (node === self || (parent = tt.parent()).TYPE == "Call" && parent.expression === node) {
if (!(is_arrow(node) && node.value)) return;
var stat = node.first_statement();
node.body = [ stat ];
node.value = null;
descend(node, tt);
if (node.body.length == 1 && node.body[0] === stat) {
node.body.length = 0;
node.value = stat.value;
}
}
return node;
}
if (node instanceof AST_VarDef) {
Expand Down
25 changes: 25 additions & 0 deletions test/compress/arrows.js
Original file line number Diff line number Diff line change
Expand Up @@ -1212,3 +1212,28 @@ issue_5495: {
expect_stdout: "undefined"
node_version: ">=4"
}

issue_5653: {
options = {
arrows: true,
hoist_props: true,
passes: 2,
reduce_vars: true,
sequences: true,
side_effects: true,
unused: true,
}
input: {
console.log((a => {
a = { p: console };
return a++;
})());
}
expect: {
console.log((a => {
return console, +{};
})());
}
expect_stdout: "NaN"
node_version: ">=4"
}

0 comments on commit 02d966d

Please sign in to comment.