From 883d25b27dc8027f6c9bc6485e5f25a14aaf7f8c Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Thu, 23 Jan 2025 13:30:40 +0000 Subject: [PATCH] fix(minifier): keep esm in dce (#8677) fixes https://github.com/rolldown/rolldown/issues/3402 --- crates/oxc_minifier/src/peephole/remove_dead_code.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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"); + } }