mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
fix(isolated-declarations): transform incorrectly when there are multiple functions with the same name (#3753)
This commit is contained in:
parent
e95d8e3990
commit
d29316a5ff
3 changed files with 28 additions and 10 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
7
crates/oxc_isolated_declarations/tests/fixtures/function-overloads.ts
vendored
Normal file
7
crates/oxc_isolated_declarations/tests/fixtures/function-overloads.ts
vendored
Normal file
|
|
@ -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 {};
|
||||
|
|
@ -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;
|
||||
Loading…
Reference in a new issue