Skip to content

Commit 6095438

Browse files
feat(ast): Add AstKind to TSRestType node (#11752)
This PR is part of the ongoing work in #11490. Adds AstKind to `TSRestType` nodes by removing the entry from the list of exceptions in ast_tools. --------- Co-authored-by: Cameron Clark <cameron.clark@hey.com>
1 parent b8237b8 commit 6095438

File tree

9 files changed

+82
-62
lines changed

9 files changed

+82
-62
lines changed

crates/oxc_ast/src/ast_kind_impl.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ impl AstKind<'_> {
338338

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

341+
Self::TSRestType(_) => "TSRestType".into(),
342+
341343
Self::TSAsExpression(_) => "TSAsExpression".into(),
342344
Self::TSSatisfiesExpression(_) => "TSSatisfiesExpression".into(),
343345
Self::TSNonNullExpression(_) => "TSNonNullExpression".into(),

crates/oxc_ast/src/generated/ast_kind.rs

Lines changed: 58 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -140,56 +140,57 @@ pub enum AstType {
140140
TSTupleType = 124,
141141
TSNamedTupleMember = 125,
142142
TSOptionalType = 126,
143-
TSAnyKeyword = 127,
144-
TSStringKeyword = 128,
145-
TSBooleanKeyword = 129,
146-
TSNumberKeyword = 130,
147-
TSNeverKeyword = 131,
148-
TSIntrinsicKeyword = 132,
149-
TSUnknownKeyword = 133,
150-
TSNullKeyword = 134,
151-
TSUndefinedKeyword = 135,
152-
TSVoidKeyword = 136,
153-
TSSymbolKeyword = 137,
154-
TSThisType = 138,
155-
TSObjectKeyword = 139,
156-
TSBigIntKeyword = 140,
157-
TSTypeReference = 141,
158-
TSTypeName = 142,
159-
TSQualifiedName = 143,
160-
TSTypeParameterInstantiation = 144,
161-
TSTypeParameter = 145,
162-
TSTypeParameterDeclaration = 146,
163-
TSTypeAliasDeclaration = 147,
164-
TSClassImplements = 148,
165-
TSInterfaceDeclaration = 149,
166-
TSPropertySignature = 150,
167-
TSCallSignatureDeclaration = 151,
168-
TSMethodSignature = 152,
169-
TSConstructSignatureDeclaration = 153,
170-
TSIndexSignatureName = 154,
171-
TSInterfaceHeritage = 155,
172-
TSTypePredicate = 156,
173-
TSModuleDeclaration = 157,
174-
TSModuleBlock = 158,
175-
TSTypeLiteral = 159,
176-
TSInferType = 160,
177-
TSTypeQuery = 161,
178-
TSImportType = 162,
179-
TSMappedType = 163,
180-
TSTemplateLiteralType = 164,
181-
TSAsExpression = 165,
182-
TSSatisfiesExpression = 166,
183-
TSTypeAssertion = 167,
184-
TSImportEqualsDeclaration = 168,
185-
TSExternalModuleReference = 169,
186-
TSNonNullExpression = 170,
187-
Decorator = 171,
188-
TSExportAssignment = 172,
189-
TSInstantiationExpression = 173,
190-
JSDocNullableType = 174,
191-
JSDocNonNullableType = 175,
192-
JSDocUnknownType = 176,
143+
TSRestType = 127,
144+
TSAnyKeyword = 128,
145+
TSStringKeyword = 129,
146+
TSBooleanKeyword = 130,
147+
TSNumberKeyword = 131,
148+
TSNeverKeyword = 132,
149+
TSIntrinsicKeyword = 133,
150+
TSUnknownKeyword = 134,
151+
TSNullKeyword = 135,
152+
TSUndefinedKeyword = 136,
153+
TSVoidKeyword = 137,
154+
TSSymbolKeyword = 138,
155+
TSThisType = 139,
156+
TSObjectKeyword = 140,
157+
TSBigIntKeyword = 141,
158+
TSTypeReference = 142,
159+
TSTypeName = 143,
160+
TSQualifiedName = 144,
161+
TSTypeParameterInstantiation = 145,
162+
TSTypeParameter = 146,
163+
TSTypeParameterDeclaration = 147,
164+
TSTypeAliasDeclaration = 148,
165+
TSClassImplements = 149,
166+
TSInterfaceDeclaration = 150,
167+
TSPropertySignature = 151,
168+
TSCallSignatureDeclaration = 152,
169+
TSMethodSignature = 153,
170+
TSConstructSignatureDeclaration = 154,
171+
TSIndexSignatureName = 155,
172+
TSInterfaceHeritage = 156,
173+
TSTypePredicate = 157,
174+
TSModuleDeclaration = 158,
175+
TSModuleBlock = 159,
176+
TSTypeLiteral = 160,
177+
TSInferType = 161,
178+
TSTypeQuery = 162,
179+
TSImportType = 163,
180+
TSMappedType = 164,
181+
TSTemplateLiteralType = 165,
182+
TSAsExpression = 166,
183+
TSSatisfiesExpression = 167,
184+
TSTypeAssertion = 168,
185+
TSImportEqualsDeclaration = 169,
186+
TSExternalModuleReference = 170,
187+
TSNonNullExpression = 171,
188+
Decorator = 172,
189+
TSExportAssignment = 173,
190+
TSInstantiationExpression = 174,
191+
JSDocNullableType = 175,
192+
JSDocNonNullableType = 176,
193+
JSDocUnknownType = 177,
193194
}
194195

195196
/// Untyped AST Node Kind
@@ -330,6 +331,7 @@ pub enum AstKind<'a> {
330331
TSTupleType(&'a TSTupleType<'a>) = AstType::TSTupleType as u8,
331332
TSNamedTupleMember(&'a TSNamedTupleMember<'a>) = AstType::TSNamedTupleMember as u8,
332333
TSOptionalType(&'a TSOptionalType<'a>) = AstType::TSOptionalType as u8,
334+
TSRestType(&'a TSRestType<'a>) = AstType::TSRestType as u8,
333335
TSAnyKeyword(&'a TSAnyKeyword) = AstType::TSAnyKeyword as u8,
334336
TSStringKeyword(&'a TSStringKeyword) = AstType::TSStringKeyword as u8,
335337
TSBooleanKeyword(&'a TSBooleanKeyword) = AstType::TSBooleanKeyword as u8,
@@ -531,6 +533,7 @@ impl GetSpan for AstKind<'_> {
531533
Self::TSTupleType(it) => it.span(),
532534
Self::TSNamedTupleMember(it) => it.span(),
533535
Self::TSOptionalType(it) => it.span(),
536+
Self::TSRestType(it) => it.span(),
534537
Self::TSAnyKeyword(it) => it.span(),
535538
Self::TSStringKeyword(it) => it.span(),
536539
Self::TSBooleanKeyword(it) => it.span(),
@@ -1221,6 +1224,11 @@ impl<'a> AstKind<'a> {
12211224
if let Self::TSOptionalType(v) = self { Some(v) } else { None }
12221225
}
12231226

1227+
#[inline]
1228+
pub fn as_ts_rest_type(self) -> Option<&'a TSRestType<'a>> {
1229+
if let Self::TSRestType(v) = self { Some(v) } else { None }
1230+
}
1231+
12241232
#[inline]
12251233
pub fn as_ts_any_keyword(self) -> Option<&'a TSAnyKeyword> {
12261234
if let Self::TSAnyKeyword(v) = self { Some(v) } else { None }

crates/oxc_ast_visit/src/generated/visit.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3394,9 +3394,11 @@ pub mod walk {
33943394

33953395
#[inline]
33963396
pub fn walk_ts_rest_type<'a, V: Visit<'a>>(visitor: &mut V, it: &TSRestType<'a>) {
3397-
// No `AstKind` for this type
3397+
let kind = AstKind::TSRestType(visitor.alloc(it));
3398+
visitor.enter_node(kind);
33983399
visitor.visit_span(&it.span);
33993400
visitor.visit_ts_type(&it.type_annotation);
3401+
visitor.leave_node(kind);
34003402
}
34013403

34023404
#[inline]

crates/oxc_ast_visit/src/generated/visit_mut.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3564,9 +3564,11 @@ pub mod walk_mut {
35643564

35653565
#[inline]
35663566
pub fn walk_ts_rest_type<'a, V: VisitMut<'a>>(visitor: &mut V, it: &mut TSRestType<'a>) {
3567-
// No `AstType` for this type
3567+
let kind = AstType::TSRestType;
3568+
visitor.enter_node(kind);
35683569
visitor.visit_span(&mut it.span);
35693570
visitor.visit_ts_type(&mut it.type_annotation);
3571+
visitor.leave_node(kind);
35703572
}
35713573

35723574
#[inline]

crates/oxc_formatter/src/generated/ast_nodes.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ pub enum AstNodes<'a> {
154154
TSTupleType(&'a AstNode<'a, TSTupleType<'a>>),
155155
TSNamedTupleMember(&'a AstNode<'a, TSNamedTupleMember<'a>>),
156156
TSOptionalType(&'a AstNode<'a, TSOptionalType<'a>>),
157+
TSRestType(&'a AstNode<'a, TSRestType<'a>>),
157158
TSAnyKeyword(&'a AstNode<'a, TSAnyKeyword>),
158159
TSStringKeyword(&'a AstNode<'a, TSStringKeyword>),
159160
TSBooleanKeyword(&'a AstNode<'a, TSBooleanKeyword>),
@@ -337,6 +338,7 @@ impl<'a> AstNodes<'a> {
337338
Self::TSTupleType(n) => n.span(),
338339
Self::TSNamedTupleMember(n) => n.span(),
339340
Self::TSOptionalType(n) => n.span(),
341+
Self::TSRestType(n) => n.span(),
340342
Self::TSAnyKeyword(n) => n.span(),
341343
Self::TSStringKeyword(n) => n.span(),
342344
Self::TSBooleanKeyword(n) => n.span(),
@@ -520,6 +522,7 @@ impl<'a> AstNodes<'a> {
520522
Self::TSTupleType(n) => n.parent,
521523
Self::TSNamedTupleMember(n) => n.parent,
522524
Self::TSOptionalType(n) => n.parent,
525+
Self::TSRestType(n) => n.parent,
523526
Self::TSAnyKeyword(n) => n.parent,
524527
Self::TSStringKeyword(n) => n.parent,
525528
Self::TSBooleanKeyword(n) => n.parent,
@@ -703,6 +706,7 @@ impl<'a> AstNodes<'a> {
703706
Self::TSTupleType(_) => "TSTupleType",
704707
Self::TSNamedTupleMember(_) => "TSNamedTupleMember",
705708
Self::TSOptionalType(_) => "TSOptionalType",
709+
Self::TSRestType(_) => "TSRestType",
706710
Self::TSAnyKeyword(_) => "TSAnyKeyword",
707711
Self::TSStringKeyword(_) => "TSStringKeyword",
708712
Self::TSBooleanKeyword(_) => "TSBooleanKeyword",
@@ -6054,7 +6058,7 @@ impl<'a> AstNode<'a, TSRestType<'a>> {
60546058
self.allocator.alloc(AstNode {
60556059
inner: &self.inner.type_annotation,
60566060
allocator: self.allocator,
6057-
parent: self.parent,
6061+
parent: self.allocator.alloc(AstNodes::TSRestType(transmute_self(self))),
60586062
})
60596063
}
60606064
}
@@ -6071,11 +6075,11 @@ impl<'a> AstNode<'a, TSTupleElement<'a>> {
60716075
allocator: self.allocator,
60726076
}))
60736077
}
6074-
TSTupleElement::TSRestType(s) => {
6075-
panic!(
6076-
"No kind for current enum variant yet, please see `tasks/ast_tools/src/generators/ast_kind.rs`"
6077-
)
6078-
}
6078+
TSTupleElement::TSRestType(s) => AstNodes::TSRestType(self.allocator.alloc(AstNode {
6079+
inner: s.as_ref(),
6080+
parent,
6081+
allocator: self.allocator,
6082+
})),
60796083
it @ match_ts_type!(TSTupleElement) => {
60806084
return self
60816085
.allocator

crates/oxc_formatter/src/generated/format.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1564,7 +1564,10 @@ impl<'a> Format<'a> for AstNode<'a, TSOptionalType<'a>> {
15641564

15651565
impl<'a> Format<'a> for AstNode<'a, TSRestType<'a>> {
15661566
fn fmt(&self, f: &mut Formatter<'_, 'a>) -> FormatResult<()> {
1567-
self.write(f)
1567+
format_leading_comments(self.span().start).fmt(f)?;
1568+
let result = self.write(f);
1569+
format_trailing_comments(self.span().end).fmt(f)?;
1570+
result
15681571
}
15691572
}
15701573

crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaration/tuple-labelled-rest.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
3434
"flags": "ReferenceFlags(Type)",
3535
"id": 0,
3636
"name": "T",
37-
"node_id": 13
37+
"node_id": 14
3838
}
3939
]
4040
},

crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaration/tuple-rest.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
3434
"flags": "ReferenceFlags(Type)",
3535
"id": 0,
3636
"name": "T",
37-
"node_id": 10
37+
"node_id": 11
3838
}
3939
]
4040
},

tasks/ast_tools/src/generators/ast_kind.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const STRUCTS_BLACK_LIST: &[&str] = &[
3737
"BindingProperty",
3838
"AccessorProperty",
3939
"ImportAttribute",
40-
"TSRestType",
4140
"TSInterfaceBody",
4241
"TSIndexSignature",
4342
"TSFunctionType",

0 commit comments

Comments
 (0)