diff --git a/lib/compress.js b/lib/compress.js index 58f083226d2..903558585ef 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -7251,16 +7251,19 @@ Compressor.prototype.compress = function(node) { node.name = null; } if (node instanceof AST_Lambda) { - descend_scope(); if (drop_funcs && node !== self && node instanceof AST_LambdaDefinition) { var def = node.name.definition(); if (!(def.id in in_use_ids)) { log(node.name, "Dropping unused function {name}"); def.eliminated++; - if (parent instanceof AST_ExportDefault) return to_func_expr(node, true); + if (parent instanceof AST_ExportDefault) { + descend_scope(); + return to_func_expr(node, true); + } return in_list ? List.skip : make_node(AST_EmptyStatement, node); } } + descend_scope(); if (node instanceof AST_LambdaExpression && node.name && drop_fn_name(node.name.definition())) { node.name = null; } diff --git a/test/compress/side_effects.js b/test/compress/side_effects.js index 3c09448d088..090a6566207 100644 --- a/test/compress/side_effects.js +++ b/test/compress/side_effects.js @@ -584,7 +584,9 @@ issue_4668: { } expect: { console.log(function f() { - (function g() {})(); + (function g() { + 0; + })(); }()); } expect_stdout: "undefined" diff --git a/test/compress/yields.js b/test/compress/yields.js index 8478d541c9a..c49f7f3980f 100644 --- a/test/compress/yields.js +++ b/test/compress/yields.js @@ -2018,3 +2018,24 @@ issue_5684: { expect_stdout: "PASS" node_version: ">=10" } + +issue_5707: { + options = { + hoist_props: true, + reduce_vars: true, + side_effects: true, + toplevel: true, + unused: true, + yields: true, + } + input: { + var a, b; + function* f(c = (b = 42, console.log("PASS"))) {} + b = f(); + } + expect: { + console.log("PASS"); + } + expect_stdout: "PASS" + node_version: ">=6" +}