mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
refactor(transformer/typescript): remove unnecessary code (#4321)
close: #3827
This commit is contained in:
parent
95e15b6dc5
commit
a197e01b5c
3 changed files with 17 additions and 59 deletions
|
|
@ -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>,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue