Skip to content

Commit

Permalink
fix(es/minifier): Respect top_retain for top-level functions (#8814)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Apr 5, 2024
1 parent 2a7a6e9 commit 811308c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
8 changes: 8 additions & 0 deletions crates/swc_ecma_minifier/src/compress/optimize/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,14 @@ impl Optimizer<'_> {
return;
}

if !self.may_remove_ident(ident) {
log_abort!(
"unused: Preserving function `{}` because it's top-level",
ident.sym
);
return;
}

// If it is not used, drop it.
if self
.data
Expand Down
1 change: 0 additions & 1 deletion crates/swc_ecma_minifier/tests/TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ drop_unused/delete_assign_1/input.js
drop_unused/delete_assign_2/input.js
drop_unused/double_assign_1/input.js
drop_unused/double_assign_2/input.js
drop_unused/drop_toplevel_all_retain/input.js
drop_unused/drop_toplevel_funcs/input.js
drop_unused/drop_toplevel_funcs_retain/input.js
drop_unused/drop_toplevel_keep_assign/input.js
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
var a;
function f(d) {
return function () {
2;
};
return function() {};
}
a = 2;
console.log(3);

0 comments on commit 811308c

Please sign in to comment.