fix corner case in hoist_props (#5654)

fixes #5653
This commit is contained in:
Alex Lam S.L
2022-09-08 03:55:59 +01:00
committed by GitHub
parent 5b5f6e329c
commit 02d966d914
2 changed files with 37 additions and 3 deletions

View File

@@ -8486,9 +8486,18 @@ Compressor.prototype.compress = function(node) {
return make_sequence(node, assignments); return make_sequence(node, assignments);
} }
if (node instanceof AST_Scope) { if (node instanceof AST_Scope) {
if (node === self) return; var parent;
var parent = tt.parent(); if (node === self || (parent = tt.parent()).TYPE == "Call" && parent.expression === node) {
if (parent.TYPE == "Call" && parent.expression === node) return; 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; return node;
} }
if (node instanceof AST_VarDef) { if (node instanceof AST_VarDef) {

View File

@@ -1212,3 +1212,28 @@ issue_5495: {
expect_stdout: "undefined" expect_stdout: "undefined"
node_version: ">=4" 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"
}