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 @@ -404,6 +404,7 @@ impl AstKind<'_> {
Self::TSMappedType(_) => "TSMappedType".into(),
Self::TSConstructSignatureDeclaration(_) => "TSConstructSignatureDeclaration".into(),
Self::TSExportAssignment(_) => "TSExportAssignment".into(),
Self::TSConstructorType(_) => "TSConstructorType".into(),
Self::V8IntrinsicExpression(_) => "V8IntrinsicExpression".into(),

Self::JSDocNullableType(_) => "JSDocNullableType".into(),
Expand Down
39 changes: 24 additions & 15 deletions crates/oxc_ast/src/generated/ast_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,21 +183,22 @@ pub enum AstType {
TSInferType = 166,
TSTypeQuery = 167,
TSImportType = 168,
TSMappedType = 169,
TSTemplateLiteralType = 170,
TSAsExpression = 171,
TSSatisfiesExpression = 172,
TSTypeAssertion = 173,
TSImportEqualsDeclaration = 174,
TSExternalModuleReference = 175,
TSNonNullExpression = 176,
Decorator = 177,
TSExportAssignment = 178,
TSNamespaceExportDeclaration = 179,
TSInstantiationExpression = 180,
JSDocNullableType = 181,
JSDocNonNullableType = 182,
JSDocUnknownType = 183,
TSConstructorType = 169,
TSMappedType = 170,
TSTemplateLiteralType = 171,
TSAsExpression = 172,
TSSatisfiesExpression = 173,
TSTypeAssertion = 174,
TSImportEqualsDeclaration = 175,
TSExternalModuleReference = 176,
TSNonNullExpression = 177,
Decorator = 178,
TSExportAssignment = 179,
TSNamespaceExportDeclaration = 180,
TSInstantiationExpression = 181,
JSDocNullableType = 182,
JSDocNonNullableType = 183,
JSDocUnknownType = 184,
}

/// Untyped AST Node Kind
Expand Down Expand Up @@ -385,6 +386,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,
TSConstructorType(&'a TSConstructorType<'a>) = AstType::TSConstructorType as u8,
TSMappedType(&'a TSMappedType<'a>) = AstType::TSMappedType as u8,
TSTemplateLiteralType(&'a TSTemplateLiteralType<'a>) = AstType::TSTemplateLiteralType as u8,
TSAsExpression(&'a TSAsExpression<'a>) = AstType::TSAsExpression as u8,
Expand Down Expand Up @@ -590,6 +592,7 @@ impl GetSpan for AstKind<'_> {
Self::TSInferType(it) => it.span(),
Self::TSTypeQuery(it) => it.span(),
Self::TSImportType(it) => it.span(),
Self::TSConstructorType(it) => it.span(),
Self::TSMappedType(it) => it.span(),
Self::TSTemplateLiteralType(it) => it.span(),
Self::TSAsExpression(it) => it.span(),
Expand Down Expand Up @@ -781,6 +784,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::TSConstructorType(it) => Address::from_ptr(it),
Self::TSMappedType(it) => Address::from_ptr(it),
Self::TSTemplateLiteralType(it) => Address::from_ptr(it),
Self::TSAsExpression(it) => Address::from_ptr(it),
Expand Down Expand Up @@ -1650,6 +1654,11 @@ impl<'a> AstKind<'a> {
if let Self::TSImportType(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 }
}

#[inline]
pub fn as_ts_mapped_type(self) -> Option<&'a TSMappedType<'a>> {
if let Self::TSMappedType(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 @@ -3954,13 +3954,15 @@ pub mod walk {

#[inline]
pub fn walk_ts_constructor_type<'a, V: Visit<'a>>(visitor: &mut V, it: &TSConstructorType<'a>) {
// No `AstKind` for this type
let kind = AstKind::TSConstructorType(visitor.alloc(it));
visitor.enter_node(kind);
visitor.visit_span(&it.span);
if let Some(type_parameters) = &it.type_parameters {
visitor.visit_ts_type_parameter_declaration(type_parameters);
}
visitor.visit_formal_parameters(&it.params);
visitor.visit_ts_type_annotation(&it.return_type);
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 @@ -4169,13 +4169,15 @@ pub mod walk_mut {
visitor: &mut V,
it: &mut TSConstructorType<'a>,
) {
// No `AstType` for this type
let kind = AstType::TSConstructorType;
visitor.enter_node(kind);
visitor.visit_span(&mut it.span);
if let Some(type_parameters) = &mut it.type_parameters {
visitor.visit_ts_type_parameter_declaration(type_parameters);
}
visitor.visit_formal_parameters(&mut it.params);
visitor.visit_ts_type_annotation(&mut it.return_type);
visitor.leave_node(kind);
}

#[inline]
Expand Down
20 changes: 14 additions & 6 deletions crates/oxc_formatter/src/generated/ast_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ pub enum AstNodes<'a> {
TSInferType(&'a AstNode<'a, TSInferType<'a>>),
TSTypeQuery(&'a AstNode<'a, TSTypeQuery<'a>>),
TSImportType(&'a AstNode<'a, TSImportType<'a>>),
TSConstructorType(&'a AstNode<'a, TSConstructorType<'a>>),
TSMappedType(&'a AstNode<'a, TSMappedType<'a>>),
TSTemplateLiteralType(&'a AstNode<'a, TSTemplateLiteralType<'a>>),
TSAsExpression(&'a AstNode<'a, TSAsExpression<'a>>),
Expand Down Expand Up @@ -2480,6 +2481,7 @@ impl<'a> AstNodes<'a> {
Self::TSInferType(n) => n.span(),
Self::TSTypeQuery(n) => n.span(),
Self::TSImportType(n) => n.span(),
Self::TSConstructorType(n) => n.span(),
Self::TSMappedType(n) => n.span(),
Self::TSTemplateLiteralType(n) => n.span(),
Self::TSAsExpression(n) => n.span(),
Expand Down Expand Up @@ -2670,6 +2672,7 @@ impl<'a> AstNodes<'a> {
Self::TSInferType(n) => n.parent,
Self::TSTypeQuery(n) => n.parent,
Self::TSImportType(n) => n.parent,
Self::TSConstructorType(n) => n.parent,
Self::TSMappedType(n) => n.parent,
Self::TSTemplateLiteralType(n) => n.parent,
Self::TSAsExpression(n) => n.parent,
Expand Down Expand Up @@ -2860,6 +2863,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::TSConstructorType(n) => SiblingNode::from(n.inner),
Self::TSMappedType(n) => SiblingNode::from(n.inner),
Self::TSTemplateLiteralType(n) => SiblingNode::from(n.inner),
Self::TSAsExpression(n) => SiblingNode::from(n.inner),
Expand Down Expand Up @@ -3050,6 +3054,7 @@ impl<'a> AstNodes<'a> {
Self::TSInferType(_) => "TSInferType",
Self::TSTypeQuery(_) => "TSTypeQuery",
Self::TSImportType(_) => "TSImportType",
Self::TSConstructorType(_) => "TSConstructorType",
Self::TSMappedType(_) => "TSMappedType",
Self::TSTemplateLiteralType(_) => "TSTemplateLiteralType",
Self::TSAsExpression(_) => "TSAsExpression",
Expand Down Expand Up @@ -8928,9 +8933,12 @@ impl<'a> AstNode<'a, TSType<'a>> {
}))
}
TSType::TSConstructorType(s) => {
panic!(
"No kind for current enum variant yet, please see `tasks/ast_tools/src/generators/ast_kind.rs`"
)
AstNodes::TSConstructorType(self.allocator.alloc(AstNode {
inner: s.as_ref(),
parent,
allocator: self.allocator,
following_node: self.following_node,
}))
}
TSType::TSFunctionType(s) => {
panic!(
Expand Down Expand Up @@ -10753,7 +10761,7 @@ impl<'a> AstNode<'a, TSConstructorType<'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::TSConstructorType(transmute_self(self))),
following_node,
}))
.as_ref()
Expand All @@ -10765,7 +10773,7 @@ impl<'a> AstNode<'a, TSConstructorType<'a>> {
self.allocator.alloc(AstNode {
inner: self.inner.params.as_ref(),
allocator: self.allocator,
parent: self.parent,
parent: self.allocator.alloc(AstNodes::TSConstructorType(transmute_self(self))),
following_node,
})
}
Expand All @@ -10776,7 +10784,7 @@ impl<'a> AstNode<'a, TSConstructorType<'a>> {
self.allocator.alloc(AstNode {
inner: self.inner.return_type.as_ref(),
allocator: self.allocator,
parent: self.parent,
parent: self.allocator.alloc(AstNodes::TSConstructorType(transmute_self(self))),
following_node,
})
}
Expand Down
10 changes: 9 additions & 1 deletion crates/oxc_formatter/src/generated/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2783,7 +2783,15 @@ impl<'a> Format<'a> for AstNode<'a, TSFunctionType<'a>> {

impl<'a> Format<'a> for AstNode<'a, TSConstructorType<'a>> {
fn fmt(&self, f: &mut Formatter<'_, 'a>) -> FormatResult<()> {
self.write(f)
format_leading_comments(self.span).fmt(f)?;
let result = self.write(f);
format_trailing_comments(
&self.parent.as_sibling_node(),
&SiblingNode::from(self.inner),
self.following_node.as_ref(),
)
.fmt(f)?;
result
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"flags": "ReferenceFlags(Type)",
"id": 0,
"name": "U",
"node_id": 16
"node_id": 17
}
]
}
Expand All @@ -49,7 +49,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"flags": "ReferenceFlags(Type)",
"id": 1,
"name": "T",
"node_id": 20
"node_id": 21
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"flags": "ReferenceFlags(Type)",
"id": 0,
"name": "U",
"node_id": 16
"node_id": 17
}
]
}
Expand All @@ -49,7 +49,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"flags": "ReferenceFlags(Type)",
"id": 1,
"name": "T",
"node_id": 20
"node_id": 21
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"flags": "ReferenceFlags(Type)",
"id": 0,
"name": "T",
"node_id": 13
"node_id": 14
},
{
"flags": "ReferenceFlags(Type)",
"id": 1,
"name": "T",
"node_id": 17
"node_id": 18
}
]
},
Expand Down
1 change: 0 additions & 1 deletion tasks/ast_tools/src/generators/ast_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const STRUCTS_BLACK_LIST: &[&str] = &[
"TSInterfaceBody",
"TSIndexSignature",
"TSFunctionType",
"TSConstructorType",
"Span",
];

Expand Down
Loading