Skip to content

Commit f6b3ee3

Browse files
author
Cameron McHenry
committed
refactor(ast): add AstKind for TSTupleType
1 parent 71db85b commit f6b3ee3

File tree

13 files changed

+87
-68
lines changed

13 files changed

+87
-68
lines changed

crates/oxc_ast/src/ast_kind_impl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ impl AstKind<'_> {
333333
Self::TSTemplateLiteralType(_) => "TSTemplateLiteralType".into(),
334334
Self::TSArrayType(_) => "TSArrayType".into(),
335335
Self::TSTypeOperator(_) => "TSTypeOperator".into(),
336+
Self::TSTupleType(_) => "TSTupleType".into(),
336337

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

crates/oxc_ast/src/generated/ast_kind.rs

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

193194
/// Untyped AST Node Kind
@@ -325,6 +326,7 @@ pub enum AstKind<'a> {
325326
TSTypeOperator(&'a TSTypeOperator<'a>) = AstType::TSTypeOperator as u8,
326327
TSArrayType(&'a TSArrayType<'a>) = AstType::TSArrayType as u8,
327328
TSIndexedAccessType(&'a TSIndexedAccessType<'a>) = AstType::TSIndexedAccessType as u8,
329+
TSTupleType(&'a TSTupleType<'a>) = AstType::TSTupleType as u8,
328330
TSNamedTupleMember(&'a TSNamedTupleMember<'a>) = AstType::TSNamedTupleMember as u8,
329331
TSAnyKeyword(&'a TSAnyKeyword) = AstType::TSAnyKeyword as u8,
330332
TSStringKeyword(&'a TSStringKeyword) = AstType::TSStringKeyword as u8,
@@ -524,6 +526,7 @@ impl GetSpan for AstKind<'_> {
524526
Self::TSTypeOperator(it) => it.span(),
525527
Self::TSArrayType(it) => it.span(),
526528
Self::TSIndexedAccessType(it) => it.span(),
529+
Self::TSTupleType(it) => it.span(),
527530
Self::TSNamedTupleMember(it) => it.span(),
528531
Self::TSAnyKeyword(it) => it.span(),
529532
Self::TSStringKeyword(it) => it.span(),
@@ -1200,6 +1203,11 @@ impl<'a> AstKind<'a> {
12001203
if let Self::TSIndexedAccessType(v) = self { Some(v) } else { None }
12011204
}
12021205

1206+
#[inline]
1207+
pub fn as_ts_tuple_type(self) -> Option<&'a TSTupleType<'a>> {
1208+
if let Self::TSTupleType(v) = self { Some(v) } else { None }
1209+
}
1210+
12031211
#[inline]
12041212
pub fn as_ts_named_tuple_member(self) -> Option<&'a TSNamedTupleMember<'a>> {
12051213
if let Self::TSNamedTupleMember(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
@@ -3363,9 +3363,11 @@ pub mod walk {
33633363

33643364
#[inline]
33653365
pub fn walk_ts_tuple_type<'a, V: Visit<'a>>(visitor: &mut V, it: &TSTupleType<'a>) {
3366-
// No `AstKind` for this type
3366+
let kind = AstKind::TSTupleType(visitor.alloc(it));
3367+
visitor.enter_node(kind);
33673368
visitor.visit_span(&it.span);
33683369
visitor.visit_ts_tuple_elements(&it.element_types);
3370+
visitor.leave_node(kind);
33693371
}
33703372

33713373
#[inline]

crates/oxc_ast_visit/src/generated/visit_mut.rs

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

35313531
#[inline]
35323532
pub fn walk_ts_tuple_type<'a, V: VisitMut<'a>>(visitor: &mut V, it: &mut TSTupleType<'a>) {
3533-
// No `AstType` for this type
3533+
let kind = AstType::TSTupleType;
3534+
visitor.enter_node(kind);
35343535
visitor.visit_span(&mut it.span);
35353536
visitor.visit_ts_tuple_elements(&mut it.element_types);
3537+
visitor.leave_node(kind);
35363538
}
35373539

35383540
#[inline]

crates/oxc_formatter/src/generated/ast_nodes.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ pub enum AstNodes<'a> {
151151
TSTypeOperator(&'a AstNode<'a, TSTypeOperator<'a>>),
152152
TSArrayType(&'a AstNode<'a, TSArrayType<'a>>),
153153
TSIndexedAccessType(&'a AstNode<'a, TSIndexedAccessType<'a>>),
154+
TSTupleType(&'a AstNode<'a, TSTupleType<'a>>),
154155
TSNamedTupleMember(&'a AstNode<'a, TSNamedTupleMember<'a>>),
155156
TSAnyKeyword(&'a AstNode<'a, TSAnyKeyword>),
156157
TSStringKeyword(&'a AstNode<'a, TSStringKeyword>),
@@ -332,6 +333,7 @@ impl<'a> AstNodes<'a> {
332333
Self::TSTypeOperator(n) => n.span(),
333334
Self::TSArrayType(n) => n.span(),
334335
Self::TSIndexedAccessType(n) => n.span(),
336+
Self::TSTupleType(n) => n.span(),
335337
Self::TSNamedTupleMember(n) => n.span(),
336338
Self::TSAnyKeyword(n) => n.span(),
337339
Self::TSStringKeyword(n) => n.span(),
@@ -513,6 +515,7 @@ impl<'a> AstNodes<'a> {
513515
Self::TSTypeOperator(n) => n.parent,
514516
Self::TSArrayType(n) => n.parent,
515517
Self::TSIndexedAccessType(n) => n.parent,
518+
Self::TSTupleType(n) => n.parent,
516519
Self::TSNamedTupleMember(n) => n.parent,
517520
Self::TSAnyKeyword(n) => n.parent,
518521
Self::TSStringKeyword(n) => n.parent,
@@ -694,6 +697,7 @@ impl<'a> AstNodes<'a> {
694697
Self::TSTypeOperator(_) => "TSTypeOperator",
695698
Self::TSArrayType(_) => "TSArrayType",
696699
Self::TSIndexedAccessType(_) => "TSIndexedAccessType",
700+
Self::TSTupleType(_) => "TSTupleType",
697701
Self::TSNamedTupleMember(_) => "TSNamedTupleMember",
698702
Self::TSAnyKeyword(_) => "TSAnyKeyword",
699703
Self::TSStringKeyword(_) => "TSStringKeyword",
@@ -5750,11 +5754,11 @@ impl<'a> AstNode<'a, TSType<'a>> {
57505754
parent,
57515755
allocator: self.allocator,
57525756
})),
5753-
TSType::TSTupleType(s) => {
5754-
panic!(
5755-
"No kind for current enum variant yet, please see `tasks/ast_tools/src/generators/ast_kind.rs`"
5756-
)
5757-
}
5757+
TSType::TSTupleType(s) => AstNodes::TSTupleType(self.allocator.alloc(AstNode {
5758+
inner: s.as_ref(),
5759+
parent,
5760+
allocator: self.allocator,
5761+
})),
57585762
TSType::TSTypeLiteral(s) => AstNodes::TSTypeLiteral(self.allocator.alloc(AstNode {
57595763
inner: s.as_ref(),
57605764
parent,
@@ -5987,7 +5991,7 @@ impl<'a> AstNode<'a, TSTupleType<'a>> {
59875991
self.allocator.alloc(AstNode {
59885992
inner: &self.inner.element_types,
59895993
allocator: self.allocator,
5990-
parent: self.parent,
5994+
parent: self.allocator.alloc(AstNodes::TSTupleType(transmute_self(self))),
59915995
})
59925996
}
59935997
}

crates/oxc_formatter/src/generated/format.rs

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

15381538
impl<'a> Format<'a> for AstNode<'a, TSTupleType<'a>> {
15391539
fn fmt(&self, f: &mut Formatter<'_, 'a>) -> FormatResult<()> {
1540-
self.write(f)
1540+
format_leading_comments(self.span().start).fmt(f)?;
1541+
let result = self.write(f);
1542+
format_trailing_comments(self.span().end).fmt(f)?;
1543+
result
15411544
}
15421545
}
15431546

crates/oxc_semantic/tests/fixtures/typescript-eslint/type-annotation/parameter-array-destructure.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-annotation
4242
"flags": "ReferenceFlags(Type)",
4343
"id": 0,
4444
"name": "T",
45-
"node_id": 12
45+
"node_id": 13
4646
}
4747
]
4848
},

crates/oxc_semantic/tests/fixtures/typescript-eslint/type-annotation/variable-array-destructure.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-annotation
2727
"flags": "ReferenceFlags(Type)",
2828
"id": 0,
2929
"name": "T",
30-
"node_id": 10
30+
"node_id": 11
3131
}
3232
]
3333
},

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": 12
37+
"node_id": 13
3838
}
3939
]
4040
},

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
4141
"flags": "ReferenceFlags(Type)",
4242
"id": 0,
4343
"name": "T1",
44-
"node_id": 15
44+
"node_id": 16
4545
}
4646
]
4747
},
@@ -55,7 +55,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
5555
"flags": "ReferenceFlags(Type)",
5656
"id": 1,
5757
"name": "T2",
58-
"node_id": 20
58+
"node_id": 21
5959
}
6060
]
6161
},

0 commit comments

Comments
 (0)