Skip to content

Commit

Permalink
fix(minifier): keep esm in dce (#8677)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Jan 23, 2025
1 parent ce2b9da commit 883d25b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions crates/oxc_minifier/src/peephole/remove_dead_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ impl<'a, 'b> PeepholeOptimizations {
if i - 1 <= index {
return true;
}
// keep function declaration
if matches!(s.as_declaration(), Some(Declaration::FunctionDeclaration(_))) {
// Keep module syntax and function declaration
if s.is_module_declaration()
|| matches!(s.as_declaration(), Some(Declaration::FunctionDeclaration(_)))
{
return true;
}
false
Expand Down Expand Up @@ -812,4 +814,10 @@ mod test {
test("!1", "");
test("1", "");
}

#[test]
fn keep_module_syntax() {
test_same("throw foo; export let bar");
test_same("throw foo; export default bar");
}
}

0 comments on commit 883d25b

Please sign in to comment.