diff --git a/crates/oxc_minifier/src/peephole/remove_dead_code.rs b/crates/oxc_minifier/src/peephole/remove_dead_code.rs index e3cdbba8feba1..8f54eda42026b 100644 --- a/crates/oxc_minifier/src/peephole/remove_dead_code.rs +++ b/crates/oxc_minifier/src/peephole/remove_dead_code.rs @@ -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 @@ -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"); + } }