diff --git a/crates/oxc_transformer/src/lib.rs b/crates/oxc_transformer/src/lib.rs index a4c13473460a2..438f2f3c2aeed 100644 --- a/crates/oxc_transformer/src/lib.rs +++ b/crates/oxc_transformer/src/lib.rs @@ -149,23 +149,6 @@ impl<'a> Traverse<'a> for Transformer<'a> { fn enter_class_body(&mut self, body: &mut ClassBody<'a>, _ctx: &mut TraverseCtx<'a>) { self.x0_typescript.transform_class_body(body); } - - fn enter_import_declaration( - &mut self, - decl: &mut ImportDeclaration<'a>, - _ctx: &mut TraverseCtx<'a>, - ) { - self.x0_typescript.transform_import_declaration(decl); - } - - fn enter_export_named_declaration( - &mut self, - decl: &mut ExportNamedDeclaration<'a>, - _ctx: &mut TraverseCtx<'a>, - ) { - self.x0_typescript.transform_export_named_declaration(decl); - } - fn enter_ts_module_declaration( &mut self, decl: &mut TSModuleDeclaration<'a>, diff --git a/crates/oxc_transformer/src/typescript/annotations.rs b/crates/oxc_transformer/src/typescript/annotations.rs index 8cf12753eeb30..182afb6a42c91 100644 --- a/crates/oxc_transformer/src/typescript/annotations.rs +++ b/crates/oxc_transformer/src/typescript/annotations.rs @@ -78,8 +78,23 @@ impl<'a> TypeScriptAnnotations<'a> { false } else { decl.specifiers.retain(|specifier| { - !specifier.export_kind.is_type() - && !self.type_identifier_names.contains(&specifier.exported.name()) + !(specifier.export_kind.is_type() + || self.type_identifier_names.contains(&specifier.exported.name()) + || { + if let ModuleExportName::IdentifierReference(ident) = + &specifier.local + { + ident.reference_id.get().is_some_and(|id| { + ctx.symbols().references[id].symbol_id().is_some_and( + |symbol_id| { + ctx.symbols().get_flag(symbol_id).is_type() + }, + ) + }) + } else { + false + } + }) }); !decl.specifiers.is_empty() @@ -476,38 +491,6 @@ impl<'a> TypeScriptAnnotations<'a> { self.has_jsx_fragment = true; } - pub fn transform_import_declaration(&mut self, decl: &mut ImportDeclaration<'a>) { - let Some(specifiers) = &decl.specifiers else { - return; - }; - let is_type = decl.import_kind.is_type(); - for specifier in specifiers { - let mut specifier_is_type = is_type; - let id = match specifier { - ImportDeclarationSpecifier::ImportSpecifier(s) => { - if s.import_kind.is_type() { - specifier_is_type = true; - } - &s.local - } - ImportDeclarationSpecifier::ImportDefaultSpecifier(s) => &s.local, - ImportDeclarationSpecifier::ImportNamespaceSpecifier(s) => &s.local, - }; - if specifier_is_type { - self.type_identifier_names.insert(id.name.clone()); - } - } - } - - pub fn transform_export_named_declaration(&mut self, decl: &mut ExportNamedDeclaration<'a>) { - let is_type = decl.export_kind.is_type(); - for specifier in &decl.specifiers { - if is_type || specifier.export_kind.is_type() { - self.type_identifier_names.insert(specifier.local.name().clone()); - } - } - } - pub fn transform_ts_module_declaration(&mut self, decl: &mut TSModuleDeclaration<'a>) { // NB: Namespace transform happens in `enter_program` visitor, and replaces retained // namespaces with functions. This visitor is called after, by which time any remaining diff --git a/crates/oxc_transformer/src/typescript/mod.rs b/crates/oxc_transformer/src/typescript/mod.rs index c8be446b5d410..98848ea3c98c0 100644 --- a/crates/oxc_transformer/src/typescript/mod.rs +++ b/crates/oxc_transformer/src/typescript/mod.rs @@ -99,14 +99,6 @@ impl<'a> TypeScript<'a> { self.annotations.transform_class_body(body); } - pub fn transform_import_declaration(&mut self, decl: &mut ImportDeclaration<'a>) { - self.annotations.transform_import_declaration(decl); - } - - pub fn transform_export_named_declaration(&mut self, decl: &mut ExportNamedDeclaration<'a>) { - self.annotations.transform_export_named_declaration(decl); - } - pub fn transform_ts_module_declaration(&mut self, decl: &mut TSModuleDeclaration<'a>) { self.annotations.transform_ts_module_declaration(decl); }