diff --git a/crates/oxc_isolated_declarations/src/lib.rs b/crates/oxc_isolated_declarations/src/lib.rs index 76796e6d096b3..276188de4f09f 100644 --- a/crates/oxc_isolated_declarations/src/lib.rs +++ b/crates/oxc_isolated_declarations/src/lib.rs @@ -313,14 +313,15 @@ impl<'a> IsolatedDeclarations<'a> { ) }) .name; - if last_function_name.as_ref().is_some_and(|last_name| last_name == name) - && func.body.is_some() - { - None + + if func.body.is_some() { + if last_function_name.as_ref().is_some_and(|last_name| last_name == name) { + return None; + } } else { last_function_name = Some(name.clone()); - Some(stmt) } + Some(stmt) } Statement::ExportNamedDeclaration(ref decl) => { if let Some(Declaration::FunctionDeclaration(ref func)) = decl.declaration { @@ -333,14 +334,14 @@ impl<'a> IsolatedDeclarations<'a> { ) }) .name; - if last_function_name.as_ref().is_some_and(|last_name| last_name == name) - && func.body.is_some() - { - None + if func.body.is_some() { + if last_function_name.as_ref().is_some_and(|last_name| last_name == name) { + return None; + } } else { last_function_name = Some(name.clone()); - Some(stmt) } + Some(stmt) } else { Some(stmt) } diff --git a/crates/oxc_isolated_declarations/tests/fixtures/function-overloads.ts b/crates/oxc_isolated_declarations/tests/fixtures/function-overloads.ts new file mode 100644 index 0000000000000..e33f9a36e753b --- /dev/null +++ b/crates/oxc_isolated_declarations/tests/fixtures/function-overloads.ts @@ -0,0 +1,7 @@ +function a(a: number): number; +function a(a: string): string; +function a(a: any): any {} + + +function b(a: number): number {}; +function b(a: string): string {}; \ No newline at end of file diff --git a/crates/oxc_isolated_declarations/tests/snapshots/function-overloads.snap b/crates/oxc_isolated_declarations/tests/snapshots/function-overloads.snap new file mode 100644 index 0000000000000..b523859d01949 --- /dev/null +++ b/crates/oxc_isolated_declarations/tests/snapshots/function-overloads.snap @@ -0,0 +1,10 @@ +--- +source: crates/oxc_isolated_declarations/tests/mod.rs +input_file: crates/oxc_isolated_declarations/tests/fixtures/function-overloads.ts +--- +==================== .D.TS ==================== + +declare function a(a: number): number; +declare function a(a: string): string; +declare function b(a: number): number; +declare function b(a: string): string;