From 0739b5f1e36a3ec70f89d0cda3674866e8c80ff8 Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Wed, 11 Sep 2024 07:57:15 +0000 Subject: [PATCH] fix(transformer/react): don't transform declaration of function overloads (#5642) Found a bug in https://github.com/oxc-project/oxc/actions/runs/10768809028/job/29858692560; We don't need to transform typescript-syntax-only function --- crates/oxc_transformer/src/react/refresh.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/oxc_transformer/src/react/refresh.rs b/crates/oxc_transformer/src/react/refresh.rs index 793e88479ea75..bb85901e0b4ac 100644 --- a/crates/oxc_transformer/src/react/refresh.rs +++ b/crates/oxc_transformer/src/react/refresh.rs @@ -788,7 +788,7 @@ impl<'a> ReactRefresh<'a> { } ExportDefaultDeclarationKind::FunctionDeclaration(func) => { if let Some(id) = &func.id { - if !is_componentish_name(&id.name) { + if func.is_typescript_syntax() || !is_componentish_name(&id.name) { return None; } @@ -812,7 +812,7 @@ impl<'a> ReactRefresh<'a> { return None; }; - if !is_componentish_name(&id.name) { + if func.is_typescript_syntax() || !is_componentish_name(&id.name) { return None; } @@ -950,7 +950,9 @@ fn get_symbol_id_from_function_and_declarator(stmt: &Statement<'_>) -> Vec { - symbol_ids.push(func.symbol_id().unwrap()); + if !func.is_typescript_syntax() { + symbol_ids.push(func.symbol_id().unwrap()); + } } Statement::VariableDeclaration(ref decl) => { symbol_ids.extend(decl.declarations.iter().filter_map(|decl| { @@ -959,7 +961,9 @@ fn get_symbol_id_from_function_and_declarator(stmt: &Statement<'_>) -> Vec { if let Some(Declaration::FunctionDeclaration(func)) = &export_decl.declaration { - symbol_ids.push(func.symbol_id().unwrap()); + if !func.is_typescript_syntax() { + symbol_ids.push(func.symbol_id().unwrap()); + } } else if let Some(Declaration::VariableDeclaration(decl)) = &export_decl.declaration { symbol_ids.extend(decl.declarations.iter().filter_map(|decl| { decl.id.get_binding_identifier().and_then(|id| id.symbol_id.get())