From 63376dda34bcf0507a402e3fbfd98d13ea6b6f43 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Sat, 13 Jan 2024 23:21:33 +0800 Subject: [PATCH] feat(ast): visit TSTypeQuery --- crates/oxc_ast/src/ast_kind.rs | 3 +++ crates/oxc_ast/src/visit.rs | 11 +++++++++++ crates/oxc_ast/src/visit_mut.rs | 11 +++++++++++ 3 files changed, 25 insertions(+) diff --git a/crates/oxc_ast/src/ast_kind.rs b/crates/oxc_ast/src/ast_kind.rs index ac9a2714cae52..03cf2c0834540 100644 --- a/crates/oxc_ast/src/ast_kind.rs +++ b/crates/oxc_ast/src/ast_kind.rs @@ -160,6 +160,7 @@ pub enum AstKind<'a> { TSModuleDeclaration(&'a TSModuleDeclaration<'a>), TSTypeAliasDeclaration(&'a TSTypeAliasDeclaration<'a>), TSTypeAnnotation(&'a TSTypeAnnotation<'a>), + TSTypeQuery(&'a TSTypeQuery<'a>), TSTypeAssertion(&'a TSTypeAssertion<'a>), TSTypeParameter(&'a TSTypeParameter<'a>), TSTypeParameterDeclaration(&'a TSTypeParameterDeclaration<'a>), @@ -467,6 +468,7 @@ impl<'a> GetSpan for AstKind<'a> { Self::TSModuleDeclaration(x) => x.span, Self::TSTypeAliasDeclaration(x) => x.span, Self::TSTypeAnnotation(x) => x.span, + Self::TSTypeQuery(x) => x.span, Self::TSTypeAssertion(x) => x.span, Self::TSTypeParameter(x) => x.span, Self::TSTypeParameterDeclaration(x) => x.span, @@ -647,6 +649,7 @@ impl<'a> AstKind<'a> { Self::TSModuleDeclaration(_) => "TSModuleDeclaration".into(), Self::TSTypeAliasDeclaration(_) => "TSTypeAliasDeclaration".into(), Self::TSTypeAnnotation(_) => "TSTypeAnnotation".into(), + Self::TSTypeQuery(_) => "TSTypeQuery".into(), Self::TSTypeAssertion(_) => "TSTypeAssertion".into(), Self::TSTypeParameter(_) => "TSTypeParameter".into(), Self::TSTypeParameterDeclaration(_) => "TSTypeParameterDeclaration".into(), diff --git a/crates/oxc_ast/src/visit.rs b/crates/oxc_ast/src/visit.rs index a95694aeedff5..056b12315563f 100644 --- a/crates/oxc_ast/src/visit.rs +++ b/crates/oxc_ast/src/visit.rs @@ -1600,6 +1600,7 @@ pub trait Visit<'a>: Sized { TSType::TSTypePredicate(ty) => self.visit_ts_type_predicate(ty), TSType::TSTypeLiteral(ty) => self.visit_ts_type_literal(ty), TSType::TSIndexedAccessType(ty) => self.visit_ts_indexed_access_type(ty), + TSType::TSTypeQuery(ty) => self.visit_ts_type_query(ty), _ => {} } } @@ -1850,4 +1851,14 @@ pub trait Visit<'a>: Sized { self.visit_ts_type_annotation(annotation); } } + + fn visit_ts_type_query(&mut self, ty: &TSTypeQuery<'a>) { + let kind = AstKind::TSTypeQuery(self.alloc(ty)); + self.enter_node(kind); + self.visit_ts_type_name(&ty.expr_name); + if let Some(type_parameters) = &ty.type_parameters { + self.visit_ts_type_parameter_instantiation(type_parameters); + } + self.leave_node(kind); + } } diff --git a/crates/oxc_ast/src/visit_mut.rs b/crates/oxc_ast/src/visit_mut.rs index c73f27a073e05..c538a857e00fd 100644 --- a/crates/oxc_ast/src/visit_mut.rs +++ b/crates/oxc_ast/src/visit_mut.rs @@ -1595,6 +1595,7 @@ pub trait VisitMut<'a>: Sized { TSType::TSTypePredicate(ty) => self.visit_ts_type_predicate(ty), TSType::TSTypeLiteral(ty) => self.visit_ts_type_literal(ty), TSType::TSIndexedAccessType(ty) => self.visit_ts_indexed_access_type(ty), + TSType::TSTypeQuery(ty) => self.visit_ts_type_query(ty), _ => {} } } @@ -1848,4 +1849,14 @@ pub trait VisitMut<'a>: Sized { self.visit_ts_type_annotation(annotation); } } + + fn visit_ts_type_query(&mut self, ty: &mut TSTypeQuery<'a>) { + let kind = AstKind::TSTypeQuery(self.alloc(ty)); + self.enter_node(kind); + self.visit_ts_type_name(&mut ty.expr_name); + if let Some(type_parameters) = &mut ty.type_parameters { + self.visit_ts_type_parameter_instantiation(type_parameters); + } + self.leave_node(kind); + } }