fix(minifier): keep esm in dce (#8677)

fixes https://github.com/rolldown/rolldown/issues/3402
This commit is contained in:
Boshen 2025-01-23 13:30:40 +00:00
parent ce2b9da5c7
commit 883d25b27d

View file

@ -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");
}
}