Skip to content

Commit

Permalink
feat(isolated-declarations): support for export default function over…
Browse files Browse the repository at this point in the history
…loads (#3809)
  • Loading branch information
Dunqing committed Jun 21, 2024
1 parent eadf495 commit 231b8f0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
16 changes: 16 additions & 0 deletions crates/oxc_isolated_declarations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ impl<'a> IsolatedDeclarations<'a> {
stmts: oxc_allocator::Vec<'a, Statement<'a>>,
) -> impl Iterator<Item = Statement<'a>> + '_ {
let mut last_function_name: Option<Atom<'a>> = None;
let mut is_export_default_function_overloads = false;

stmts.into_iter().filter_map(move |stmt| match stmt {
Statement::FunctionDeclaration(ref func) => {
Expand Down Expand Up @@ -373,6 +374,21 @@ impl<'a> IsolatedDeclarations<'a> {
Some(stmt)
}
}
Statement::ExportDefaultDeclaration(ref decl) => {
if let ExportDefaultDeclarationKind::FunctionDeclaration(ref func) =
decl.declaration
{
if is_export_default_function_overloads && func.body.is_some() {
is_export_default_function_overloads = false;
return None;
}
is_export_default_function_overloads = true;
Some(stmt)
} else {
is_export_default_function_overloads = false;
Some(stmt)
}
}
_ => Some(stmt),
})
}
Expand Down
15 changes: 7 additions & 8 deletions crates/oxc_isolated_declarations/tests/deno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,13 @@ export function foo(a: any): number {
"export default function(a: number, b: number): number {};",
"export default function(a: number, b: number): number;",
);
// TODO export default function overloads
// transform_dts_test(
// "export default function(a: number, b: number): number;
// export default function(a: number, b: number): any {
// return foo
// };",
// "export default function(a: number, b: number): number;",
// );
transform_dts_test(
"export default function(a: number, b: number): number;
export default function(a: number, b: number): any {
return foo
};",
"export default function(a: number, b: number): number;",
);
transform_dts_test(
"export default class {foo = 2};",
"export default class {\n foo: number;\n}",
Expand Down

0 comments on commit 231b8f0

Please sign in to comment.