Skip to content

Commit

Permalink
fix(isolated-declarations): transform incorrectly when there are mult…
Browse files Browse the repository at this point in the history
…iple functions with the same name (#3753)
  • Loading branch information
Dunqing committed Jun 19, 2024
1 parent e95d8e3 commit d29316a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
21 changes: 11 additions & 10 deletions crates/oxc_isolated_declarations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {};
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit d29316a

Please sign in to comment.