Skip to content

Commit

Permalink
fix corner case in unused (#5708)
Browse files Browse the repository at this point in the history
fixes #5707
  • Loading branch information
alexlamsl authored Oct 10, 2022
1 parent bccb1c3 commit 7edd10e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion test/compress/side_effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,9 @@ issue_4668: {
}
expect: {
console.log(function f() {
(function g() {})();
(function g() {
0;
})();
}());
}
expect_stdout: "undefined"
Expand Down
21 changes: 21 additions & 0 deletions test/compress/yields.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 7edd10e

Please sign in to comment.