Skip to content

Commit

Permalink
feat(ast): visit TSTypeQuery (#2021)
Browse files Browse the repository at this point in the history
```ts
type Bar = typeof Foo;
```
  • Loading branch information
Dunqing committed Jan 13, 2024
1 parent 9b77d0e commit ac4b3a4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/oxc_ast/src/ast_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down
11 changes: 11 additions & 0 deletions crates/oxc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
_ => {}
}
}
Expand Down Expand Up @@ -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);
}
}
11 changes: 11 additions & 0 deletions crates/oxc_ast/src/visit_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
_ => {}
}
}
Expand Down Expand Up @@ -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);
}
}

0 comments on commit ac4b3a4

Please sign in to comment.