mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
refactor(ast): clean up the ts type visit methods
This commit is contained in:
parent
88270fe605
commit
59748199da
3 changed files with 174 additions and 156 deletions
|
|
@ -151,28 +151,29 @@ ast_kinds! {
|
|||
|
||||
// NOTE: make sure add these to AstKind::is_type below
|
||||
TSAnyKeyword(&'a TSAnyKeyword),
|
||||
TSIntersectionType(&'a TSIntersectionType<'a>),
|
||||
TSLiteralType(&'a TSLiteralType<'a>),
|
||||
TSMethodSignature(&'a TSMethodSignature<'a>),
|
||||
TSNullKeyword(&'a TSNullKeyword),
|
||||
TSTypeLiteral(&'a TSTypeLiteral<'a>),
|
||||
TSTypeReference(&'a TSTypeReference<'a>),
|
||||
TSUnionType(&'a TSUnionType<'a>),
|
||||
TSVoidKeyword(&'a TSVoidKeyword),
|
||||
TSBigIntKeyword(&'a TSBigIntKeyword),
|
||||
TSBooleanKeyword(&'a TSBooleanKeyword),
|
||||
TSNeverKeyword(&'a TSNeverKeyword),
|
||||
TSNullKeyword(&'a TSNullKeyword),
|
||||
TSNumberKeyword(&'a TSNumberKeyword),
|
||||
TSObjectKeyword(&'a TSObjectKeyword),
|
||||
TSStringKeyword(&'a TSStringKeyword),
|
||||
TSSymbolKeyword(&'a TSSymbolKeyword),
|
||||
TSThisType(&'a TSThisType),
|
||||
TSUndefinedKeyword(&'a TSUndefinedKeyword),
|
||||
TSUnknownKeyword(&'a TSUnknownKeyword),
|
||||
TSInferType(&'a TSInferType<'a>),
|
||||
TSTemplateLiteralType(&'a TSTemplateLiteralType<'a>),
|
||||
TSVoidKeyword(&'a TSVoidKeyword),
|
||||
|
||||
// NOTE: make sure add these to AstKind::is_type below
|
||||
TSIndexedAccessType(&'a TSIndexedAccessType<'a>),
|
||||
TSInferType(&'a TSInferType<'a>),
|
||||
TSIntersectionType(&'a TSIntersectionType<'a>),
|
||||
TSLiteralType(&'a TSLiteralType<'a>),
|
||||
TSMethodSignature(&'a TSMethodSignature<'a>),
|
||||
TSTemplateLiteralType(&'a TSTemplateLiteralType<'a>),
|
||||
TSThisType(&'a TSThisType),
|
||||
TSTypeLiteral(&'a TSTypeLiteral<'a>),
|
||||
TSTypeReference(&'a TSTypeReference<'a>),
|
||||
TSUnionType(&'a TSUnionType<'a>),
|
||||
|
||||
TSAsExpression(&'a TSAsExpression<'a>),
|
||||
TSSatisfiesExpression(&'a TSSatisfiesExpression<'a>),
|
||||
|
|
@ -247,30 +248,14 @@ impl<'a> AstKind<'a> {
|
|||
| Self::LabelIdentifier(_))
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
pub fn is_type(self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
Self::TSIntersectionType(_)
|
||||
| Self::TSLiteralType(_)
|
||||
| Self::TSTypeReference(_)
|
||||
| Self::TSMethodSignature(_)
|
||||
| Self::TSNullKeyword(_)
|
||||
| Self::TSTypeLiteral(_)
|
||||
| Self::TSUnionType(_)
|
||||
| Self::TSVoidKeyword(_)
|
||||
| Self::TSBigIntKeyword(_)
|
||||
| Self::TSBooleanKeyword(_)
|
||||
| Self::TSNeverKeyword(_)
|
||||
| Self::TSNumberKeyword(_)
|
||||
| Self::TSObjectKeyword(_)
|
||||
| Self::TSStringKeyword(_)
|
||||
| Self::TSSymbolKeyword(_)
|
||||
| Self::TSThisType(_)
|
||||
| Self::TSUndefinedKeyword(_)
|
||||
| Self::TSUnknownKeyword(_)
|
||||
| Self::TSInferType(_)
|
||||
| Self::TSTemplateLiteralType(_)
|
||||
)
|
||||
matches!(self, Self::TSAnyKeyword(_) | Self::TSBigIntKeyword(_) | Self::TSBooleanKeyword(_) | Self::TSNeverKeyword(_)
|
||||
| Self::TSNullKeyword(_) | Self::TSNumberKeyword(_) | Self::TSObjectKeyword(_) | Self::TSStringKeyword(_)
|
||||
| Self::TSSymbolKeyword(_) | Self::TSUndefinedKeyword(_) | Self::TSUnknownKeyword(_) | Self::TSVoidKeyword(_)
|
||||
| Self::TSIndexedAccessType(_) | Self::TSInferType(_) | Self::TSIntersectionType(_) | Self::TSLiteralType(_)
|
||||
| Self::TSMethodSignature(_) | Self::TSTemplateLiteralType(_) | Self::TSThisType(_) | Self::TSTypeLiteral(_)
|
||||
| Self::TSTypeReference(_) | Self::TSUnionType(_))
|
||||
}
|
||||
|
||||
pub fn is_literal(self) -> bool {
|
||||
|
|
|
|||
|
|
@ -636,10 +636,6 @@ pub trait Visit<'a>: Sized {
|
|||
walk_ts_external_module_reference(self, reference);
|
||||
}
|
||||
|
||||
fn visit_ts_qualified_name(&mut self, name: &TSQualifiedName<'a>) {
|
||||
walk_ts_qualified_name(self, name);
|
||||
}
|
||||
|
||||
fn visit_ts_module_declaration(&mut self, decl: &TSModuleDeclaration<'a>) {
|
||||
walk_ts_module_declaration(self, decl);
|
||||
}
|
||||
|
|
@ -684,38 +680,10 @@ pub trait Visit<'a>: Sized {
|
|||
walk_ts_type(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_type_literal(&mut self, ty: &TSTypeLiteral<'a>) {
|
||||
walk_ts_type_literal(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_indexed_access_type(&mut self, ty: &TSIndexedAccessType<'a>) {
|
||||
walk_ts_indexed_access_type(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_type_predicate(&mut self, ty: &TSTypePredicate<'a>) {
|
||||
walk_ts_type_predicate(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_type_operator_type(&mut self, ty: &TSTypeOperator<'a>) {
|
||||
walk_ts_type_operator_type(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_tuple_type(&mut self, ty: &TSTupleType<'a>) {
|
||||
walk_ts_tuple_type(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_tuple_element(&mut self, ty: &TSTupleElement<'a>) {
|
||||
walk_ts_tuple_element(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_mapped_type(&mut self, ty: &TSMappedType<'a>) {
|
||||
walk_ts_mapped_type(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_function_type(&mut self, ty: &TSFunctionType<'a>) {
|
||||
walk_ts_function_type(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_type_parameter(&mut self, ty: &TSTypeParameter<'a>) {
|
||||
walk_ts_type_parameter(self, ty);
|
||||
}
|
||||
|
|
@ -728,34 +696,130 @@ pub trait Visit<'a>: Sized {
|
|||
walk_ts_type_parameter_declaration(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_constructor_type(&mut self, ty: &TSConstructorType<'a>) {
|
||||
walk_ts_constructor_type(self, ty);
|
||||
fn visit_ts_any_keyword(&mut self, ty: &TSAnyKeyword) {
|
||||
walk_ts_any_keyword(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_conditional_type(&mut self, ty: &TSConditionalType<'a>) {
|
||||
walk_ts_conditional_type(self, ty);
|
||||
fn visit_ts_big_int_keyword(&mut self, ty: &TSBigIntKeyword) {
|
||||
walk_ts_big_int_keyword(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_array_type(&mut self, ty: &TSArrayType<'a>) {
|
||||
walk_ts_array_type(self, ty);
|
||||
fn visit_ts_boolean_keyword(&mut self, ty: &TSBooleanKeyword) {
|
||||
walk_ts_boolean_keyword(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_never_keyword(&mut self, ty: &TSNeverKeyword) {
|
||||
walk_ts_never_keyword(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_null_keyword(&mut self, ty: &TSNullKeyword) {
|
||||
walk_ts_null_keyword(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_any_keyword(&mut self, ty: &TSAnyKeyword) {
|
||||
walk_ts_any_keyword(self, ty);
|
||||
fn visit_ts_number_keyword(&mut self, ty: &TSNumberKeyword) {
|
||||
walk_ts_number_keyword(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_object_keyword(&mut self, ty: &TSObjectKeyword) {
|
||||
walk_ts_object_keyword(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_string_keyword(&mut self, ty: &TSStringKeyword) {
|
||||
walk_ts_string_keyword(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_symbol_keyword(&mut self, ty: &TSSymbolKeyword) {
|
||||
walk_ts_symbol_keyword(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_undefined_keyword(&mut self, ty: &TSUndefinedKeyword) {
|
||||
walk_ts_undefined_keyword(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_unknown_keyword(&mut self, ty: &TSUnknownKeyword) {
|
||||
walk_ts_unknown_keyword(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_void_keyword(&mut self, ty: &TSVoidKeyword) {
|
||||
walk_ts_void_keyword(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_array_type(&mut self, ty: &TSArrayType<'a>) {
|
||||
walk_ts_array_type(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_conditional_type(&mut self, ty: &TSConditionalType<'a>) {
|
||||
walk_ts_conditional_type(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_constructor_type(&mut self, ty: &TSConstructorType<'a>) {
|
||||
walk_ts_constructor_type(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_function_type(&mut self, ty: &TSFunctionType<'a>) {
|
||||
walk_ts_function_type(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_import_type(&mut self, ty: &TSImportType<'a>) {
|
||||
walk_ts_import_type(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_indexed_access_type(&mut self, ty: &TSIndexedAccessType<'a>) {
|
||||
walk_ts_indexed_access_type(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_infer_type(&mut self, ty: &TSInferType<'a>) {
|
||||
walk_ts_infer_type(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_intersection_type(&mut self, ty: &TSIntersectionType<'a>) {
|
||||
walk_ts_intersection_type(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_literal_type(&mut self, ty: &TSLiteralType<'a>) {
|
||||
walk_ts_literal_type(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_mapped_type(&mut self, ty: &TSMappedType<'a>) {
|
||||
walk_ts_mapped_type(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_named_tuple_member(&mut self, ty: &TSNamedTupleMember<'a>) {
|
||||
walk_ts_named_tuple_member(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_qualified_name(&mut self, name: &TSQualifiedName<'a>) {
|
||||
walk_ts_qualified_name(self, name);
|
||||
}
|
||||
|
||||
fn visit_ts_template_literal_type(&mut self, ty: &TSTemplateLiteralType<'a>) {
|
||||
walk_ts_template_literal_type(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_this_type(&mut self, ty: &TSThisType) {
|
||||
walk_ts_this_type(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_tuple_type(&mut self, ty: &TSTupleType<'a>) {
|
||||
walk_ts_tuple_type(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_type_literal(&mut self, ty: &TSTypeLiteral<'a>) {
|
||||
walk_ts_type_literal(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_type_operator_type(&mut self, ty: &TSTypeOperator<'a>) {
|
||||
walk_ts_type_operator_type(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_type_predicate(&mut self, ty: &TSTypePredicate<'a>) {
|
||||
walk_ts_type_predicate(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_type_query(&mut self, ty: &TSTypeQuery<'a>) {
|
||||
walk_ts_type_query(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_type_reference(&mut self, ty: &TSTypeReference<'a>) {
|
||||
walk_ts_type_reference(self, ty);
|
||||
}
|
||||
|
|
@ -764,10 +828,6 @@ pub trait Visit<'a>: Sized {
|
|||
walk_ts_union_type(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_literal_type(&mut self, ty: &TSLiteralType<'a>) {
|
||||
walk_ts_literal_type(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_signature(&mut self, signature: &TSSignature<'a>) {
|
||||
walk_ts_signature(self, signature);
|
||||
}
|
||||
|
|
@ -799,14 +859,6 @@ pub trait Visit<'a>: Sized {
|
|||
walk_ts_call_signature_declaration(self, signature);
|
||||
}
|
||||
|
||||
fn visit_ts_type_query(&mut self, ty: &TSTypeQuery<'a>) {
|
||||
walk_ts_type_query(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_import_type(&mut self, ty: &TSImportType<'a>) {
|
||||
walk_ts_import_type(self, ty);
|
||||
}
|
||||
|
||||
fn visit_ts_import_attributes(&mut self, attributes: &TSImportAttributes<'a>) {
|
||||
walk_ts_import_attributes(self, attributes);
|
||||
}
|
||||
|
|
@ -818,46 +870,6 @@ pub trait Visit<'a>: Sized {
|
|||
fn visit_ts_import_attribute_name(&mut self, name: &TSImportAttributeName<'a>) {
|
||||
walk_ts_import_attribute_name(self, name);
|
||||
}
|
||||
|
||||
fn visit_ts_big_int_keyword(&mut self, ty: &TSBigIntKeyword) {
|
||||
walk_ts_big_int_keyword(self, ty);
|
||||
}
|
||||
fn visit_ts_boolean_keyword(&mut self, ty: &TSBooleanKeyword) {
|
||||
walk_ts_boolean_keyword(self, ty);
|
||||
}
|
||||
fn visit_ts_never_keyword(&mut self, ty: &TSNeverKeyword) {
|
||||
walk_ts_never_keyword(self, ty);
|
||||
}
|
||||
fn visit_ts_number_keyword(&mut self, ty: &TSNumberKeyword) {
|
||||
walk_ts_number_keyword(self, ty);
|
||||
}
|
||||
fn visit_ts_object_keyword(&mut self, ty: &TSObjectKeyword) {
|
||||
walk_ts_object_keyword(self, ty);
|
||||
}
|
||||
fn visit_ts_string_keyword(&mut self, ty: &TSStringKeyword) {
|
||||
walk_ts_string_keyword(self, ty);
|
||||
}
|
||||
fn visit_ts_symbol_keyword(&mut self, ty: &TSSymbolKeyword) {
|
||||
walk_ts_symbol_keyword(self, ty);
|
||||
}
|
||||
fn visit_ts_this_type(&mut self, ty: &TSThisType) {
|
||||
walk_ts_this_type(self, ty);
|
||||
}
|
||||
fn visit_ts_undefined_keyword(&mut self, ty: &TSUndefinedKeyword) {
|
||||
walk_ts_undefined_keyword(self, ty);
|
||||
}
|
||||
fn visit_ts_unknown_keyword(&mut self, ty: &TSUnknownKeyword) {
|
||||
walk_ts_unknown_keyword(self, ty);
|
||||
}
|
||||
fn visit_ts_infer_type(&mut self, ty: &TSInferType<'a>) {
|
||||
walk_ts_infer_type(self, ty);
|
||||
}
|
||||
fn visit_ts_named_tuple_member(&mut self, ty: &TSNamedTupleMember<'a>) {
|
||||
walk_ts_named_tuple_member(self, ty);
|
||||
}
|
||||
fn visit_ts_template_literal_type(&mut self, ty: &TSTemplateLiteralType<'a>) {
|
||||
walk_ts_template_literal_type(self, ty);
|
||||
}
|
||||
}
|
||||
|
||||
pub mod walk {
|
||||
|
|
@ -2645,39 +2657,42 @@ pub mod walk {
|
|||
|
||||
pub fn walk_ts_type<'a, V: Visit<'a>>(visitor: &mut V, ty: &TSType<'a>) {
|
||||
match ty {
|
||||
// Keyword
|
||||
TSType::TSAnyKeyword(ty) => visitor.visit_ts_any_keyword(ty),
|
||||
TSType::TSNullKeyword(ty) => visitor.visit_ts_null_keyword(ty),
|
||||
TSType::TSVoidKeyword(ty) => visitor.visit_ts_void_keyword(ty),
|
||||
TSType::TSIntersectionType(ty) => visitor.visit_ts_intersection_type(ty),
|
||||
TSType::TSTypeReference(ty) => visitor.visit_ts_type_reference(ty),
|
||||
TSType::TSUnionType(ty) => visitor.visit_ts_union_type(ty),
|
||||
TSType::TSLiteralType(ty) => visitor.visit_ts_literal_type(ty),
|
||||
TSType::TSArrayType(ty) => visitor.visit_ts_array_type(ty),
|
||||
TSType::TSConditionalType(ty) => visitor.visit_ts_conditional_type(ty),
|
||||
TSType::TSConstructorType(ty) => visitor.visit_ts_constructor_type(ty),
|
||||
TSType::TSFunctionType(ty) => visitor.visit_ts_function_type(ty),
|
||||
TSType::TSMappedType(ty) => visitor.visit_ts_mapped_type(ty),
|
||||
TSType::TSTupleType(ty) => visitor.visit_ts_tuple_type(ty),
|
||||
TSType::TSTypeOperatorType(ty) => visitor.visit_ts_type_operator_type(ty),
|
||||
TSType::TSTypePredicate(ty) => visitor.visit_ts_type_predicate(ty),
|
||||
TSType::TSTypeLiteral(ty) => visitor.visit_ts_type_literal(ty),
|
||||
TSType::TSIndexedAccessType(ty) => visitor.visit_ts_indexed_access_type(ty),
|
||||
TSType::TSTypeQuery(ty) => visitor.visit_ts_type_query(ty),
|
||||
TSType::TSImportType(ty) => visitor.visit_ts_import_type(ty),
|
||||
TSType::TSBigIntKeyword(ty) => visitor.visit_ts_big_int_keyword(ty),
|
||||
TSType::TSBooleanKeyword(ty) => visitor.visit_ts_boolean_keyword(ty),
|
||||
TSType::TSNeverKeyword(ty) => visitor.visit_ts_never_keyword(ty),
|
||||
TSType::TSNullKeyword(ty) => visitor.visit_ts_null_keyword(ty),
|
||||
TSType::TSNumberKeyword(ty) => visitor.visit_ts_number_keyword(ty),
|
||||
TSType::TSObjectKeyword(ty) => visitor.visit_ts_object_keyword(ty),
|
||||
TSType::TSStringKeyword(ty) => visitor.visit_ts_string_keyword(ty),
|
||||
TSType::TSSymbolKeyword(ty) => visitor.visit_ts_symbol_keyword(ty),
|
||||
TSType::TSThisType(ty) => visitor.visit_ts_this_type(ty),
|
||||
TSType::TSUndefinedKeyword(ty) => visitor.visit_ts_undefined_keyword(ty),
|
||||
TSType::TSUnknownKeyword(ty) => visitor.visit_ts_unknown_keyword(ty),
|
||||
TSType::TSVoidKeyword(ty) => visitor.visit_ts_void_keyword(ty),
|
||||
// Compound
|
||||
TSType::TSArrayType(ty) => visitor.visit_ts_array_type(ty),
|
||||
TSType::TSConditionalType(ty) => visitor.visit_ts_conditional_type(ty),
|
||||
TSType::TSConstructorType(ty) => visitor.visit_ts_constructor_type(ty),
|
||||
TSType::TSFunctionType(ty) => visitor.visit_ts_function_type(ty),
|
||||
TSType::TSImportType(ty) => visitor.visit_ts_import_type(ty),
|
||||
TSType::TSIndexedAccessType(ty) => visitor.visit_ts_indexed_access_type(ty),
|
||||
TSType::TSInferType(ty) => visitor.visit_ts_infer_type(ty),
|
||||
TSType::TSIntersectionType(ty) => visitor.visit_ts_intersection_type(ty),
|
||||
TSType::TSLiteralType(ty) => visitor.visit_ts_literal_type(ty),
|
||||
TSType::TSMappedType(ty) => visitor.visit_ts_mapped_type(ty),
|
||||
TSType::TSNamedTupleMember(ty) => visitor.visit_ts_named_tuple_member(ty),
|
||||
TSType::TSQualifiedName(ty) => visitor.visit_ts_qualified_name(ty),
|
||||
TSType::TSTemplateLiteralType(ty) => visitor.visit_ts_template_literal_type(ty),
|
||||
TSType::TSThisType(ty) => visitor.visit_ts_this_type(ty),
|
||||
TSType::TSTupleType(ty) => visitor.visit_ts_tuple_type(ty),
|
||||
TSType::TSTypeLiteral(ty) => visitor.visit_ts_type_literal(ty),
|
||||
TSType::TSTypeOperatorType(ty) => visitor.visit_ts_type_operator_type(ty),
|
||||
TSType::TSTypePredicate(ty) => visitor.visit_ts_type_predicate(ty),
|
||||
TSType::TSTypeQuery(ty) => visitor.visit_ts_type_query(ty),
|
||||
TSType::TSTypeReference(ty) => visitor.visit_ts_type_reference(ty),
|
||||
TSType::TSUnionType(ty) => visitor.visit_ts_union_type(ty),
|
||||
// JSDoc
|
||||
TSType::JSDocNullableType(_) | TSType::JSDocUnknownType(_) => { /* TODO */ }
|
||||
}
|
||||
}
|
||||
|
|
@ -3017,57 +3032,68 @@ pub mod walk {
|
|||
visitor.enter_node(kind);
|
||||
visitor.leave_node(kind);
|
||||
}
|
||||
|
||||
pub fn walk_ts_boolean_keyword<'a, V: Visit<'a>>(visitor: &mut V, ty: &TSBooleanKeyword) {
|
||||
let kind = AstKind::TSBooleanKeyword(visitor.alloc(ty));
|
||||
visitor.enter_node(kind);
|
||||
visitor.leave_node(kind);
|
||||
}
|
||||
|
||||
pub fn walk_ts_never_keyword<'a, V: Visit<'a>>(visitor: &mut V, ty: &TSNeverKeyword) {
|
||||
let kind = AstKind::TSNeverKeyword(visitor.alloc(ty));
|
||||
visitor.enter_node(kind);
|
||||
visitor.leave_node(kind);
|
||||
}
|
||||
|
||||
pub fn walk_ts_number_keyword<'a, V: Visit<'a>>(visitor: &mut V, ty: &TSNumberKeyword) {
|
||||
let kind = AstKind::TSNumberKeyword(visitor.alloc(ty));
|
||||
visitor.enter_node(kind);
|
||||
visitor.leave_node(kind);
|
||||
}
|
||||
|
||||
pub fn walk_ts_object_keyword<'a, V: Visit<'a>>(visitor: &mut V, ty: &TSObjectKeyword) {
|
||||
let kind = AstKind::TSObjectKeyword(visitor.alloc(ty));
|
||||
visitor.enter_node(kind);
|
||||
visitor.leave_node(kind);
|
||||
}
|
||||
|
||||
pub fn walk_ts_string_keyword<'a, V: Visit<'a>>(visitor: &mut V, ty: &TSStringKeyword) {
|
||||
let kind = AstKind::TSStringKeyword(visitor.alloc(ty));
|
||||
visitor.enter_node(kind);
|
||||
visitor.leave_node(kind);
|
||||
}
|
||||
|
||||
pub fn walk_ts_symbol_keyword<'a, V: Visit<'a>>(visitor: &mut V, ty: &TSSymbolKeyword) {
|
||||
let kind = AstKind::TSSymbolKeyword(visitor.alloc(ty));
|
||||
visitor.enter_node(kind);
|
||||
visitor.leave_node(kind);
|
||||
}
|
||||
|
||||
pub fn walk_ts_this_type<'a, V: Visit<'a>>(visitor: &mut V, ty: &TSThisType) {
|
||||
let kind = AstKind::TSThisType(visitor.alloc(ty));
|
||||
visitor.enter_node(kind);
|
||||
visitor.leave_node(kind);
|
||||
}
|
||||
|
||||
pub fn walk_ts_undefined_keyword<'a, V: Visit<'a>>(visitor: &mut V, ty: &TSUndefinedKeyword) {
|
||||
let kind = AstKind::TSUndefinedKeyword(visitor.alloc(ty));
|
||||
visitor.enter_node(kind);
|
||||
visitor.leave_node(kind);
|
||||
}
|
||||
|
||||
pub fn walk_ts_unknown_keyword<'a, V: Visit<'a>>(visitor: &mut V, ty: &TSUnknownKeyword) {
|
||||
let kind = AstKind::TSUnknownKeyword(visitor.alloc(ty));
|
||||
visitor.enter_node(kind);
|
||||
visitor.leave_node(kind);
|
||||
}
|
||||
|
||||
pub fn walk_ts_infer_type<'a, V: Visit<'a>>(visitor: &mut V, ty: &TSInferType<'a>) {
|
||||
let kind = AstKind::TSInferType(visitor.alloc(ty));
|
||||
visitor.enter_node(kind);
|
||||
visitor.visit_ts_type_parameter(&ty.type_parameter);
|
||||
visitor.leave_node(kind);
|
||||
}
|
||||
|
||||
pub fn walk_ts_named_tuple_member<'a, V: Visit<'a>>(
|
||||
visitor: &mut V,
|
||||
ty: &TSNamedTupleMember<'a>,
|
||||
|
|
@ -3078,6 +3104,7 @@ pub mod walk {
|
|||
visitor.visit_ts_type(&ty.element_type);
|
||||
visitor.leave_node(kind);
|
||||
}
|
||||
|
||||
pub fn walk_ts_template_literal_type<'a, V: Visit<'a>>(
|
||||
visitor: &mut V,
|
||||
ty: &TSTemplateLiteralType<'a>,
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ use std::{env, path::Path};
|
|||
|
||||
use oxc_allocator::Allocator;
|
||||
use oxc_ast::{
|
||||
ast::{Class, Function},
|
||||
visit::walk::{walk_class, walk_function},
|
||||
ast::{Class, Function, TSImportType},
|
||||
visit::walk,
|
||||
Visit,
|
||||
};
|
||||
use oxc_parser::Parser;
|
||||
|
|
@ -30,7 +30,7 @@ fn main() -> std::io::Result<()> {
|
|||
|
||||
let program = ret.program;
|
||||
|
||||
let mut ast_pass = ASTPass::default();
|
||||
let mut ast_pass = CountASTNodes::default();
|
||||
ast_pass.visit_program(&program);
|
||||
println!("{ast_pass:?}");
|
||||
|
||||
|
|
@ -38,19 +38,25 @@ fn main() -> std::io::Result<()> {
|
|||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
struct ASTPass {
|
||||
number_of_functions: usize,
|
||||
number_of_classes: usize,
|
||||
struct CountASTNodes {
|
||||
functions: usize,
|
||||
classes: usize,
|
||||
ts_import_types: usize,
|
||||
}
|
||||
|
||||
impl<'a> Visit<'a> for ASTPass {
|
||||
impl<'a> Visit<'a> for CountASTNodes {
|
||||
fn visit_function(&mut self, func: &Function<'a>, flags: Option<ScopeFlags>) {
|
||||
self.number_of_functions += 1;
|
||||
walk_function(self, func, flags);
|
||||
self.functions += 1;
|
||||
walk::walk_function(self, func, flags);
|
||||
}
|
||||
|
||||
fn visit_class(&mut self, class: &Class<'a>) {
|
||||
self.number_of_classes += 1;
|
||||
walk_class(self, class);
|
||||
self.classes += 1;
|
||||
walk::walk_class(self, class);
|
||||
}
|
||||
|
||||
fn visit_ts_import_type(&mut self, ty: &TSImportType<'a>) {
|
||||
self.ts_import_types += 1;
|
||||
walk::walk_ts_import_type(self, ty);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue