Skip to content

Commit 866470a

Browse files
feat(ast): Add AstKind to TSIndexSignature node (#11724)
This PR is part of the ongoing work in #11490. Adds AstKind to `TSIndexSignature` nodes by removing the entry from the list of exceptions in ast_tools.
1 parent 37d4c9a commit 866470a

File tree

11 files changed

+51
-32
lines changed

11 files changed

+51
-32
lines changed

crates/oxc_ast/src/ast_kind_impl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ impl AstKind<'_> {
362362
Self::TSNamedTupleMember(_) => "TSNamedTupleMember".into(),
363363

364364
Self::TSPropertySignature(_) => "TSPropertySignature".into(),
365+
Self::TSIndexSignatureName(_) => "TSIndexSignatureName".into(),
365366
Self::TSConditionalType(_) => "TSConditionalType".into(),
366367
Self::TSMappedType(_) => "TSMappedType".into(),
367368
Self::TSConstructSignatureDeclaration(_) => "TSConstructSignatureDeclaration".into(),

crates/oxc_ast/src/generated/ast_kind.rs

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -162,28 +162,29 @@ pub enum AstType {
162162
TSPropertySignature = 146,
163163
TSMethodSignature = 147,
164164
TSConstructSignatureDeclaration = 148,
165-
TSInterfaceHeritage = 149,
166-
TSModuleDeclaration = 150,
167-
TSModuleBlock = 151,
168-
TSTypeLiteral = 152,
169-
TSInferType = 153,
170-
TSTypeQuery = 154,
171-
TSImportType = 155,
172-
TSMappedType = 156,
173-
TSTemplateLiteralType = 157,
174-
TSAsExpression = 158,
175-
TSSatisfiesExpression = 159,
176-
TSTypeAssertion = 160,
177-
TSImportEqualsDeclaration = 161,
178-
TSModuleReference = 162,
179-
TSExternalModuleReference = 163,
180-
TSNonNullExpression = 164,
181-
Decorator = 165,
182-
TSExportAssignment = 166,
183-
TSInstantiationExpression = 167,
184-
JSDocNullableType = 168,
185-
JSDocNonNullableType = 169,
186-
JSDocUnknownType = 170,
165+
TSIndexSignatureName = 149,
166+
TSInterfaceHeritage = 150,
167+
TSModuleDeclaration = 151,
168+
TSModuleBlock = 152,
169+
TSTypeLiteral = 153,
170+
TSInferType = 154,
171+
TSTypeQuery = 155,
172+
TSImportType = 156,
173+
TSMappedType = 157,
174+
TSTemplateLiteralType = 158,
175+
TSAsExpression = 159,
176+
TSSatisfiesExpression = 160,
177+
TSTypeAssertion = 161,
178+
TSImportEqualsDeclaration = 162,
179+
TSModuleReference = 163,
180+
TSExternalModuleReference = 164,
181+
TSNonNullExpression = 165,
182+
Decorator = 166,
183+
TSExportAssignment = 167,
184+
TSInstantiationExpression = 168,
185+
JSDocNullableType = 169,
186+
JSDocNonNullableType = 170,
187+
JSDocUnknownType = 171,
187188
}
188189

189190
/// Untyped AST Node Kind
@@ -349,6 +350,7 @@ pub enum AstKind<'a> {
349350
TSMethodSignature(&'a TSMethodSignature<'a>) = AstType::TSMethodSignature as u8,
350351
TSConstructSignatureDeclaration(&'a TSConstructSignatureDeclaration<'a>) =
351352
AstType::TSConstructSignatureDeclaration as u8,
353+
TSIndexSignatureName(&'a TSIndexSignatureName<'a>) = AstType::TSIndexSignatureName as u8,
352354
TSInterfaceHeritage(&'a TSInterfaceHeritage<'a>) = AstType::TSInterfaceHeritage as u8,
353355
TSModuleDeclaration(&'a TSModuleDeclaration<'a>) = AstType::TSModuleDeclaration as u8,
354356
TSModuleBlock(&'a TSModuleBlock<'a>) = AstType::TSModuleBlock as u8,
@@ -540,6 +542,7 @@ impl GetSpan for AstKind<'_> {
540542
Self::TSPropertySignature(it) => it.span(),
541543
Self::TSMethodSignature(it) => it.span(),
542544
Self::TSConstructSignatureDeclaration(it) => it.span(),
545+
Self::TSIndexSignatureName(it) => it.span(),
543546
Self::TSInterfaceHeritage(it) => it.span(),
544547
Self::TSModuleDeclaration(it) => it.span(),
545548
Self::TSModuleBlock(it) => it.span(),
@@ -1316,6 +1319,11 @@ impl<'a> AstKind<'a> {
13161319
if let Self::TSConstructSignatureDeclaration(v) = self { Some(v) } else { None }
13171320
}
13181321

1322+
#[inline]
1323+
pub fn as_ts_index_signature_name(self) -> Option<&'a TSIndexSignatureName<'a>> {
1324+
if let Self::TSIndexSignatureName(v) = self { Some(v) } else { None }
1325+
}
1326+
13191327
#[inline]
13201328
pub fn as_ts_interface_heritage(self) -> Option<&'a TSInterfaceHeritage<'a>> {
13211329
if let Self::TSInterfaceHeritage(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
@@ -3744,9 +3744,11 @@ pub mod walk {
37443744
visitor: &mut V,
37453745
it: &TSIndexSignatureName<'a>,
37463746
) {
3747-
// No `AstKind` for this type
3747+
let kind = AstKind::TSIndexSignatureName(visitor.alloc(it));
3748+
visitor.enter_node(kind);
37483749
visitor.visit_span(&it.span);
37493750
visitor.visit_ts_type_annotation(&it.type_annotation);
3751+
visitor.leave_node(kind);
37503752
}
37513753

37523754
#[inline]

crates/oxc_ast_visit/src/generated/visit_mut.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3950,9 +3950,11 @@ pub mod walk_mut {
39503950
visitor: &mut V,
39513951
it: &mut TSIndexSignatureName<'a>,
39523952
) {
3953-
// No `AstType` for this type
3953+
let kind = AstType::TSIndexSignatureName;
3954+
visitor.enter_node(kind);
39543955
visitor.visit_span(&mut it.span);
39553956
visitor.visit_ts_type_annotation(&mut it.type_annotation);
3957+
visitor.leave_node(kind);
39563958
}
39573959

39583960
#[inline]

crates/oxc_formatter/src/generated/ast_nodes.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ pub enum AstNodes<'a> {
176176
TSPropertySignature(&'a AstNode<'a, TSPropertySignature<'a>>),
177177
TSMethodSignature(&'a AstNode<'a, TSMethodSignature<'a>>),
178178
TSConstructSignatureDeclaration(&'a AstNode<'a, TSConstructSignatureDeclaration<'a>>),
179+
TSIndexSignatureName(&'a AstNode<'a, TSIndexSignatureName<'a>>),
179180
TSInterfaceHeritage(&'a AstNode<'a, TSInterfaceHeritage<'a>>),
180181
TSModuleDeclaration(&'a AstNode<'a, TSModuleDeclaration<'a>>),
181182
TSModuleBlock(&'a AstNode<'a, TSModuleBlock<'a>>),
@@ -353,6 +354,7 @@ impl<'a> AstNodes<'a> {
353354
Self::TSPropertySignature(n) => n.span(),
354355
Self::TSMethodSignature(n) => n.span(),
355356
Self::TSConstructSignatureDeclaration(n) => n.span(),
357+
Self::TSIndexSignatureName(n) => n.span(),
356358
Self::TSInterfaceHeritage(n) => n.span(),
357359
Self::TSModuleDeclaration(n) => n.span(),
358360
Self::TSModuleBlock(n) => n.span(),
@@ -530,6 +532,7 @@ impl<'a> AstNodes<'a> {
530532
Self::TSPropertySignature(n) => n.parent,
531533
Self::TSMethodSignature(n) => n.parent,
532534
Self::TSConstructSignatureDeclaration(n) => n.parent,
535+
Self::TSIndexSignatureName(n) => n.parent,
533536
Self::TSInterfaceHeritage(n) => n.parent,
534537
Self::TSModuleDeclaration(n) => n.parent,
535538
Self::TSModuleBlock(n) => n.parent,
@@ -707,6 +710,7 @@ impl<'a> AstNodes<'a> {
707710
Self::TSPropertySignature(_) => "TSPropertySignature",
708711
Self::TSMethodSignature(_) => "TSMethodSignature",
709712
Self::TSConstructSignatureDeclaration(_) => "TSConstructSignatureDeclaration",
713+
Self::TSIndexSignatureName(_) => "TSIndexSignatureName",
710714
Self::TSInterfaceHeritage(_) => "TSInterfaceHeritage",
711715
Self::TSModuleDeclaration(_) => "TSModuleDeclaration",
712716
Self::TSModuleBlock(_) => "TSModuleBlock",
@@ -6752,7 +6756,7 @@ impl<'a> AstNode<'a, TSIndexSignatureName<'a>> {
67526756
self.allocator.alloc(AstNode {
67536757
inner: self.inner.type_annotation.as_ref(),
67546758
allocator: self.allocator,
6755-
parent: self.parent,
6759+
parent: self.allocator.alloc(AstNodes::TSIndexSignatureName(transmute_self(self))),
67566760
})
67576761
}
67586762
}

crates/oxc_formatter/src/generated/format.rs

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

18201820
impl<'a> Format<'a> for AstNode<'a, TSIndexSignatureName<'a>> {
18211821
fn fmt(&self, f: &mut Formatter<'_, 'a>) -> FormatResult<()> {
1822-
self.write(f)
1822+
format_leading_comments(self.span().start).fmt(f)?;
1823+
let result = self.write(f);
1824+
format_trailing_comments(self.span().end).fmt(f)?;
1825+
result
18231826
}
18241827
}
18251828

crates/oxc_semantic/tests/fixtures/typescript-eslint/class/declaration/index-signature.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/class/declarati
3434
"flags": "ReferenceFlags(Type)",
3535
"id": 0,
3636
"name": "Bar",
37-
"node_id": 14
37+
"node_id": 16
3838
}
3939
]
4040
},
@@ -48,7 +48,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/class/declarati
4848
"flags": "ReferenceFlags(Type)",
4949
"id": 1,
5050
"name": "Foo",
51-
"node_id": 22
51+
"node_id": 25
5252
}
5353
]
5454
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
2323
"flags": "ReferenceFlags(Type)",
2424
"id": 1,
2525
"name": "I",
26-
"node_id": 19
26+
"node_id": 20
2727
}
2828
]
2929
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
3939
"flags": "ReferenceFlags(Type)",
4040
"id": 1,
4141
"name": "I",
42-
"node_id": 31
42+
"node_id": 32
4343
}
4444
]
4545
}

crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaration/signatures/index-sig.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
},

0 commit comments

Comments
 (0)