Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/oxc_ast/src/ast_kind_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ impl AstKind<'_> {
Self::TSArrayType(_) => "TSArrayType".into(),
Self::TSOptionalType(_) => "TSOptionalType".into(),
Self::TSTypeOperator(_) => "TSTypeOperator".into(),
Self::TSFunctionType(_) => "TSFunctionType".into(),

Self::TSIndexedAccessType(_) => "TSIndexedAccessType".into(),

Expand Down
41 changes: 25 additions & 16 deletions crates/oxc_ast/src/generated/ast_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,22 +185,23 @@ pub enum AstType {
TSInferType = 168,
TSTypeQuery = 169,
TSImportType = 170,
TSConstructorType = 171,
TSMappedType = 172,
TSTemplateLiteralType = 173,
TSAsExpression = 174,
TSSatisfiesExpression = 175,
TSTypeAssertion = 176,
TSImportEqualsDeclaration = 177,
TSExternalModuleReference = 178,
TSNonNullExpression = 179,
Decorator = 180,
TSExportAssignment = 181,
TSNamespaceExportDeclaration = 182,
TSInstantiationExpression = 183,
JSDocNullableType = 184,
JSDocNonNullableType = 185,
JSDocUnknownType = 186,
TSFunctionType = 171,
TSConstructorType = 172,
TSMappedType = 173,
TSTemplateLiteralType = 174,
TSAsExpression = 175,
TSSatisfiesExpression = 176,
TSTypeAssertion = 177,
TSImportEqualsDeclaration = 178,
TSExternalModuleReference = 179,
TSNonNullExpression = 180,
Decorator = 181,
TSExportAssignment = 182,
TSNamespaceExportDeclaration = 183,
TSInstantiationExpression = 184,
JSDocNullableType = 185,
JSDocNonNullableType = 186,
JSDocUnknownType = 187,
}

/// Untyped AST Node Kind
Expand Down Expand Up @@ -391,6 +392,7 @@ pub enum AstKind<'a> {
TSInferType(&'a TSInferType<'a>) = AstType::TSInferType as u8,
TSTypeQuery(&'a TSTypeQuery<'a>) = AstType::TSTypeQuery as u8,
TSImportType(&'a TSImportType<'a>) = AstType::TSImportType as u8,
TSFunctionType(&'a TSFunctionType<'a>) = AstType::TSFunctionType as u8,
TSConstructorType(&'a TSConstructorType<'a>) = AstType::TSConstructorType as u8,
TSMappedType(&'a TSMappedType<'a>) = AstType::TSMappedType as u8,
TSTemplateLiteralType(&'a TSTemplateLiteralType<'a>) = AstType::TSTemplateLiteralType as u8,
Expand Down Expand Up @@ -599,6 +601,7 @@ impl GetSpan for AstKind<'_> {
Self::TSInferType(it) => it.span(),
Self::TSTypeQuery(it) => it.span(),
Self::TSImportType(it) => it.span(),
Self::TSFunctionType(it) => it.span(),
Self::TSConstructorType(it) => it.span(),
Self::TSMappedType(it) => it.span(),
Self::TSTemplateLiteralType(it) => it.span(),
Expand Down Expand Up @@ -793,6 +796,7 @@ impl GetAddress for AstKind<'_> {
Self::TSInferType(it) => Address::from_ptr(it),
Self::TSTypeQuery(it) => Address::from_ptr(it),
Self::TSImportType(it) => Address::from_ptr(it),
Self::TSFunctionType(it) => Address::from_ptr(it),
Self::TSConstructorType(it) => Address::from_ptr(it),
Self::TSMappedType(it) => Address::from_ptr(it),
Self::TSTemplateLiteralType(it) => Address::from_ptr(it),
Expand Down Expand Up @@ -1677,6 +1681,11 @@ impl<'a> AstKind<'a> {
if let Self::TSImportType(v) = self { Some(v) } else { None }
}

#[inline]
pub fn as_ts_function_type(self) -> Option<&'a TSFunctionType<'a>> {
if let Self::TSFunctionType(v) = self { Some(v) } else { None }
}

#[inline]
pub fn as_ts_constructor_type(self) -> Option<&'a TSConstructorType<'a>> {
if let Self::TSConstructorType(v) = self { Some(v) } else { None }
Expand Down
4 changes: 3 additions & 1 deletion crates/oxc_ast_visit/src/generated/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3943,7 +3943,8 @@ pub mod walk {

#[inline]
pub fn walk_ts_function_type<'a, V: Visit<'a>>(visitor: &mut V, it: &TSFunctionType<'a>) {
// No `AstKind` for this type
let kind = AstKind::TSFunctionType(visitor.alloc(it));
visitor.enter_node(kind);
visitor.enter_scope(ScopeFlags::empty(), &it.scope_id);
visitor.visit_span(&it.span);
if let Some(type_parameters) = &it.type_parameters {
Expand All @@ -3955,6 +3956,7 @@ pub mod walk {
visitor.visit_formal_parameters(&it.params);
visitor.visit_ts_type_annotation(&it.return_type);
visitor.leave_scope();
visitor.leave_node(kind);
}

#[inline]
Expand Down
4 changes: 3 additions & 1 deletion crates/oxc_ast_visit/src/generated/visit_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4155,7 +4155,8 @@ pub mod walk_mut {
visitor: &mut V,
it: &mut TSFunctionType<'a>,
) {
// No `AstType` for this type
let kind = AstType::TSFunctionType;
visitor.enter_node(kind);
visitor.enter_scope(ScopeFlags::empty(), &it.scope_id);
visitor.visit_span(&mut it.span);
if let Some(type_parameters) = &mut it.type_parameters {
Expand All @@ -4167,6 +4168,7 @@ pub mod walk_mut {
visitor.visit_formal_parameters(&mut it.params);
visitor.visit_ts_type_annotation(&mut it.return_type);
visitor.leave_scope();
visitor.leave_node(kind);
}

#[inline]
Expand Down
24 changes: 15 additions & 9 deletions crates/oxc_formatter/src/generated/ast_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ pub enum AstNodes<'a> {
TSInferType(&'a AstNode<'a, TSInferType<'a>>),
TSTypeQuery(&'a AstNode<'a, TSTypeQuery<'a>>),
TSImportType(&'a AstNode<'a, TSImportType<'a>>),
TSFunctionType(&'a AstNode<'a, TSFunctionType<'a>>),
TSConstructorType(&'a AstNode<'a, TSConstructorType<'a>>),
TSMappedType(&'a AstNode<'a, TSMappedType<'a>>),
TSTemplateLiteralType(&'a AstNode<'a, TSTemplateLiteralType<'a>>),
Expand Down Expand Up @@ -2486,6 +2487,7 @@ impl<'a> AstNodes<'a> {
Self::TSInferType(n) => n.span(),
Self::TSTypeQuery(n) => n.span(),
Self::TSImportType(n) => n.span(),
Self::TSFunctionType(n) => n.span(),
Self::TSConstructorType(n) => n.span(),
Self::TSMappedType(n) => n.span(),
Self::TSTemplateLiteralType(n) => n.span(),
Expand Down Expand Up @@ -2679,6 +2681,7 @@ impl<'a> AstNodes<'a> {
Self::TSInferType(n) => n.parent,
Self::TSTypeQuery(n) => n.parent,
Self::TSImportType(n) => n.parent,
Self::TSFunctionType(n) => n.parent,
Self::TSConstructorType(n) => n.parent,
Self::TSMappedType(n) => n.parent,
Self::TSTemplateLiteralType(n) => n.parent,
Expand Down Expand Up @@ -2872,6 +2875,7 @@ impl<'a> AstNodes<'a> {
Self::TSInferType(n) => SiblingNode::from(n.inner),
Self::TSTypeQuery(n) => SiblingNode::from(n.inner),
Self::TSImportType(n) => SiblingNode::from(n.inner),
Self::TSFunctionType(n) => SiblingNode::from(n.inner),
Self::TSConstructorType(n) => SiblingNode::from(n.inner),
Self::TSMappedType(n) => SiblingNode::from(n.inner),
Self::TSTemplateLiteralType(n) => SiblingNode::from(n.inner),
Expand Down Expand Up @@ -3065,6 +3069,7 @@ impl<'a> AstNodes<'a> {
Self::TSInferType(_) => "TSInferType",
Self::TSTypeQuery(_) => "TSTypeQuery",
Self::TSImportType(_) => "TSImportType",
Self::TSFunctionType(_) => "TSFunctionType",
Self::TSConstructorType(_) => "TSConstructorType",
Self::TSMappedType(_) => "TSMappedType",
Self::TSTemplateLiteralType(_) => "TSTemplateLiteralType",
Expand Down Expand Up @@ -10549,11 +10554,12 @@ impl<'a> AstNode<'a, TSType<'a>> {
following_node: self.following_node,
}))
}
TSType::TSFunctionType(s) => {
panic!(
"No kind for current enum variant yet, please see `tasks/ast_tools/src/generators/ast_kind.rs`"
)
}
TSType::TSFunctionType(s) => AstNodes::TSFunctionType(self.allocator.alloc(AstNode {
inner: s.as_ref(),
parent,
allocator: self.allocator,
following_node: self.following_node,
})),
TSType::TSImportType(s) => AstNodes::TSImportType(self.allocator.alloc(AstNode {
inner: s.as_ref(),
parent,
Expand Down Expand Up @@ -12948,7 +12954,7 @@ impl<'a> AstNode<'a, TSFunctionType<'a>> {
.alloc(self.inner.type_parameters.as_ref().map(|inner| AstNode {
inner: inner.as_ref(),
allocator: self.allocator,
parent: self.parent,
parent: self.allocator.alloc(AstNodes::TSFunctionType(transmute_self(self))),
following_node,
}))
.as_ref()
Expand All @@ -12961,7 +12967,7 @@ impl<'a> AstNode<'a, TSFunctionType<'a>> {
.alloc(self.inner.this_param.as_ref().map(|inner| AstNode {
inner: inner.as_ref(),
allocator: self.allocator,
parent: self.parent,
parent: self.allocator.alloc(AstNodes::TSFunctionType(transmute_self(self))),
following_node,
}))
.as_ref()
Expand All @@ -12973,7 +12979,7 @@ impl<'a> AstNode<'a, TSFunctionType<'a>> {
self.allocator.alloc(AstNode {
inner: self.inner.params.as_ref(),
allocator: self.allocator,
parent: self.parent,
parent: self.allocator.alloc(AstNodes::TSFunctionType(transmute_self(self))),
following_node,
})
}
Expand All @@ -12984,7 +12990,7 @@ impl<'a> AstNode<'a, TSFunctionType<'a>> {
self.allocator.alloc(AstNode {
inner: self.inner.return_type.as_ref(),
allocator: self.allocator,
parent: self.parent,
parent: self.allocator.alloc(AstNodes::TSFunctionType(transmute_self(self))),
following_node,
})
}
Expand Down
5 changes: 4 additions & 1 deletion crates/oxc_formatter/src/generated/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2007,7 +2007,10 @@ impl<'a> Format<'a> for AstNode<'a, TSImportType<'a>> {

impl<'a> Format<'a> for AstNode<'a, TSFunctionType<'a>> {
fn fmt(&self, f: &mut Formatter<'_, 'a>) -> FormatResult<()> {
self.write(f)
self.format_leading_comments(f)?;
let result = self.write(f);
self.format_trailing_comments(f)?;
result
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/decorators/clas
"children": [],
"flags": "ScopeFlags(StrictMode)",
"id": 2,
"node": "TSTypeAnnotation",
"node": "TSFunctionType",
"symbols": []
}
],
Expand Down Expand Up @@ -50,7 +50,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/decorators/clas
"flags": "ReferenceFlags(Read)",
"id": 0,
"name": "deco",
"node_id": 19
"node_id": 20
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"children": [],
"flags": "ScopeFlags(StrictMode)",
"id": 3,
"node": "TSConditionalType",
"node": "TSFunctionType",
"symbols": []
}
],
Expand All @@ -31,7 +31,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"flags": "ReferenceFlags(Type)",
"id": 1,
"name": "I",
"node_id": 19
"node_id": 20
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"children": [],
"flags": "ScopeFlags(StrictMode)",
"id": 4,
"node": "TSTypeAnnotation",
"node": "TSFunctionType",
"symbols": []
}
],
"flags": "ScopeFlags(StrictMode)",
"id": 3,
"node": "TSConditionalType",
"node": "TSFunctionType",
"symbols": []
}
],
Expand All @@ -39,7 +39,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"flags": "ReferenceFlags(Type)",
"id": 1,
"name": "I",
"node_id": 31
"node_id": 33
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"children": [],
"flags": "ScopeFlags(StrictMode)",
"id": 3,
"node": "TSTypeAliasDeclaration",
"node": "TSFunctionType",
"symbols": []
}
],
Expand All @@ -36,7 +36,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"flags": "ReferenceFlags(Type)",
"id": 0,
"name": "U",
"node_id": 15
"node_id": 16
}
]
}
Expand All @@ -57,7 +57,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"flags": "ReferenceFlags(Type)",
"id": 1,
"name": "T",
"node_id": 18
"node_id": 19
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"children": [],
"flags": "ScopeFlags(StrictMode)",
"id": 3,
"node": "TSTypeAliasDeclaration",
"node": "TSFunctionType",
"symbols": [
{
"flags": "SymbolFlags(TypeParameter)",
Expand All @@ -30,7 +30,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"flags": "ReferenceFlags(Type)",
"id": 0,
"name": "U",
"node_id": 15
"node_id": 16
}
]
}
Expand All @@ -57,7 +57,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"flags": "ReferenceFlags(Type)",
"id": 1,
"name": "T",
"node_id": 18
"node_id": 19
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"children": [],
"flags": "ScopeFlags(StrictMode)",
"id": 3,
"node": "TSTypeAliasDeclaration",
"node": "TSFunctionType",
"symbols": []
}
],
Expand All @@ -42,13 +42,13 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"flags": "ReferenceFlags(Type)",
"id": 0,
"name": "T",
"node_id": 12
"node_id": 13
},
{
"flags": "ReferenceFlags(Type)",
"id": 1,
"name": "T",
"node_id": 15
"node_id": 16
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"children": [],
"flags": "ScopeFlags(StrictMode)",
"id": 2,
"node": "TSTypeAliasDeclaration",
"node": "TSFunctionType",
"symbols": []
}
],
Expand All @@ -35,7 +35,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"flags": "ReferenceFlags(Type)",
"id": 0,
"name": "arg",
"node_id": 14
"node_id": 15
}
]
},
Expand Down
Loading
Loading