Skip to content

Commit 8e45e28

Browse files
committed
refactor(ast): add astkind for TSInterfaceBody
1 parent cbbc20b commit 8e45e28

File tree

17 files changed

+77
-51
lines changed

17 files changed

+77
-51
lines changed

crates/oxc_ast/src/ast_kind_impl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ impl AstKind<'_> {
405405
Self::TSConstructSignatureDeclaration(_) => "TSConstructSignatureDeclaration".into(),
406406
Self::TSExportAssignment(_) => "TSExportAssignment".into(),
407407
Self::TSConstructorType(_) => "TSConstructorType".into(),
408+
Self::TSInterfaceBody(_) => "TSInterfaceBody".into(),
408409
Self::TSIndexSignature(_) => "TSIndexSignature".into(),
409410
Self::V8IntrinsicExpression(_) => "V8IntrinsicExpression".into(),
410411

crates/oxc_ast/src/generated/ast_kind.rs

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -170,36 +170,37 @@ pub enum AstType {
170170
TSTypeAliasDeclaration = 153,
171171
TSClassImplements = 154,
172172
TSInterfaceDeclaration = 155,
173-
TSPropertySignature = 156,
174-
TSIndexSignature = 157,
175-
TSCallSignatureDeclaration = 158,
176-
TSMethodSignature = 159,
177-
TSConstructSignatureDeclaration = 160,
178-
TSIndexSignatureName = 161,
179-
TSInterfaceHeritage = 162,
180-
TSTypePredicate = 163,
181-
TSModuleDeclaration = 164,
182-
TSModuleBlock = 165,
183-
TSTypeLiteral = 166,
184-
TSInferType = 167,
185-
TSTypeQuery = 168,
186-
TSImportType = 169,
187-
TSConstructorType = 170,
188-
TSMappedType = 171,
189-
TSTemplateLiteralType = 172,
190-
TSAsExpression = 173,
191-
TSSatisfiesExpression = 174,
192-
TSTypeAssertion = 175,
193-
TSImportEqualsDeclaration = 176,
194-
TSExternalModuleReference = 177,
195-
TSNonNullExpression = 178,
196-
Decorator = 179,
197-
TSExportAssignment = 180,
198-
TSNamespaceExportDeclaration = 181,
199-
TSInstantiationExpression = 182,
200-
JSDocNullableType = 183,
201-
JSDocNonNullableType = 184,
202-
JSDocUnknownType = 185,
173+
TSInterfaceBody = 156,
174+
TSPropertySignature = 157,
175+
TSIndexSignature = 158,
176+
TSCallSignatureDeclaration = 159,
177+
TSMethodSignature = 160,
178+
TSConstructSignatureDeclaration = 161,
179+
TSIndexSignatureName = 162,
180+
TSInterfaceHeritage = 163,
181+
TSTypePredicate = 164,
182+
TSModuleDeclaration = 165,
183+
TSModuleBlock = 166,
184+
TSTypeLiteral = 167,
185+
TSInferType = 168,
186+
TSTypeQuery = 169,
187+
TSImportType = 170,
188+
TSConstructorType = 171,
189+
TSMappedType = 172,
190+
TSTemplateLiteralType = 173,
191+
TSAsExpression = 174,
192+
TSSatisfiesExpression = 175,
193+
TSTypeAssertion = 176,
194+
TSImportEqualsDeclaration = 177,
195+
TSExternalModuleReference = 178,
196+
TSNonNullExpression = 179,
197+
Decorator = 180,
198+
TSExportAssignment = 181,
199+
TSNamespaceExportDeclaration = 182,
200+
TSInstantiationExpression = 183,
201+
JSDocNullableType = 184,
202+
JSDocNonNullableType = 185,
203+
JSDocUnknownType = 186,
203204
}
204205

205206
/// Untyped AST Node Kind
@@ -372,6 +373,7 @@ pub enum AstKind<'a> {
372373
TSTypeAliasDeclaration(&'a TSTypeAliasDeclaration<'a>) = AstType::TSTypeAliasDeclaration as u8,
373374
TSClassImplements(&'a TSClassImplements<'a>) = AstType::TSClassImplements as u8,
374375
TSInterfaceDeclaration(&'a TSInterfaceDeclaration<'a>) = AstType::TSInterfaceDeclaration as u8,
376+
TSInterfaceBody(&'a TSInterfaceBody<'a>) = AstType::TSInterfaceBody as u8,
375377
TSPropertySignature(&'a TSPropertySignature<'a>) = AstType::TSPropertySignature as u8,
376378
TSIndexSignature(&'a TSIndexSignature<'a>) = AstType::TSIndexSignature as u8,
377379
TSCallSignatureDeclaration(&'a TSCallSignatureDeclaration<'a>) =
@@ -581,6 +583,7 @@ impl GetSpan for AstKind<'_> {
581583
Self::TSTypeAliasDeclaration(it) => it.span(),
582584
Self::TSClassImplements(it) => it.span(),
583585
Self::TSInterfaceDeclaration(it) => it.span(),
586+
Self::TSInterfaceBody(it) => it.span(),
584587
Self::TSPropertySignature(it) => it.span(),
585588
Self::TSIndexSignature(it) => it.span(),
586589
Self::TSCallSignatureDeclaration(it) => it.span(),
@@ -774,6 +777,7 @@ impl GetAddress for AstKind<'_> {
774777
Self::TSTypeAliasDeclaration(it) => Address::from_ptr(it),
775778
Self::TSClassImplements(it) => Address::from_ptr(it),
776779
Self::TSInterfaceDeclaration(it) => Address::from_ptr(it),
780+
Self::TSInterfaceBody(it) => Address::from_ptr(it),
777781
Self::TSPropertySignature(it) => Address::from_ptr(it),
778782
Self::TSIndexSignature(it) => Address::from_ptr(it),
779783
Self::TSCallSignatureDeclaration(it) => Address::from_ptr(it),
@@ -1591,6 +1595,11 @@ impl<'a> AstKind<'a> {
15911595
if let Self::TSInterfaceDeclaration(v) = self { Some(v) } else { None }
15921596
}
15931597

1598+
#[inline]
1599+
pub fn as_ts_interface_body(self) -> Option<&'a TSInterfaceBody<'a>> {
1600+
if let Self::TSInterfaceBody(v) = self { Some(v) } else { None }
1601+
}
1602+
15941603
#[inline]
15951604
pub fn as_ts_property_signature(self) -> Option<&'a TSPropertySignature<'a>> {
15961605
if let Self::TSPropertySignature(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
@@ -3656,9 +3656,11 @@ pub mod walk {
36563656

36573657
#[inline]
36583658
pub fn walk_ts_interface_body<'a, V: Visit<'a>>(visitor: &mut V, it: &TSInterfaceBody<'a>) {
3659-
// No `AstKind` for this type
3659+
let kind = AstKind::TSInterfaceBody(visitor.alloc(it));
3660+
visitor.enter_node(kind);
36603661
visitor.visit_span(&it.span);
36613662
visitor.visit_ts_signatures(&it.body);
3663+
visitor.leave_node(kind);
36623664
}
36633665

36643666
#[inline]

crates/oxc_ast_visit/src/generated/visit_mut.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3856,9 +3856,11 @@ pub mod walk_mut {
38563856
visitor: &mut V,
38573857
it: &mut TSInterfaceBody<'a>,
38583858
) {
3859-
// No `AstType` for this type
3859+
let kind = AstType::TSInterfaceBody;
3860+
visitor.enter_node(kind);
38603861
visitor.visit_span(&mut it.span);
38613862
visitor.visit_ts_signatures(&mut it.body);
3863+
visitor.leave_node(kind);
38623864
}
38633865

38643866
#[inline]

crates/oxc_formatter/src/generated/ast_nodes.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ pub enum AstNodes<'a> {
183183
TSTypeAliasDeclaration(&'a AstNode<'a, TSTypeAliasDeclaration<'a>>),
184184
TSClassImplements(&'a AstNode<'a, TSClassImplements<'a>>),
185185
TSInterfaceDeclaration(&'a AstNode<'a, TSInterfaceDeclaration<'a>>),
186+
TSInterfaceBody(&'a AstNode<'a, TSInterfaceBody<'a>>),
186187
TSPropertySignature(&'a AstNode<'a, TSPropertySignature<'a>>),
187188
TSIndexSignature(&'a AstNode<'a, TSIndexSignature<'a>>),
188189
TSCallSignatureDeclaration(&'a AstNode<'a, TSCallSignatureDeclaration<'a>>),
@@ -2469,6 +2470,7 @@ impl<'a> AstNodes<'a> {
24692470
Self::TSTypeAliasDeclaration(n) => n.span(),
24702471
Self::TSClassImplements(n) => n.span(),
24712472
Self::TSInterfaceDeclaration(n) => n.span(),
2473+
Self::TSInterfaceBody(n) => n.span(),
24722474
Self::TSPropertySignature(n) => n.span(),
24732475
Self::TSIndexSignature(n) => n.span(),
24742476
Self::TSCallSignatureDeclaration(n) => n.span(),
@@ -2661,6 +2663,7 @@ impl<'a> AstNodes<'a> {
26612663
Self::TSTypeAliasDeclaration(n) => n.parent,
26622664
Self::TSClassImplements(n) => n.parent,
26632665
Self::TSInterfaceDeclaration(n) => n.parent,
2666+
Self::TSInterfaceBody(n) => n.parent,
26642667
Self::TSPropertySignature(n) => n.parent,
26652668
Self::TSIndexSignature(n) => n.parent,
26662669
Self::TSCallSignatureDeclaration(n) => n.parent,
@@ -2853,6 +2856,7 @@ impl<'a> AstNodes<'a> {
28532856
Self::TSTypeAliasDeclaration(n) => SiblingNode::from(n.inner),
28542857
Self::TSClassImplements(n) => SiblingNode::from(n.inner),
28552858
Self::TSInterfaceDeclaration(n) => SiblingNode::from(n.inner),
2859+
Self::TSInterfaceBody(n) => SiblingNode::from(n.inner),
28562860
Self::TSPropertySignature(n) => SiblingNode::from(n.inner),
28572861
Self::TSIndexSignature(n) => SiblingNode::from(n.inner),
28582862
Self::TSCallSignatureDeclaration(n) => SiblingNode::from(n.inner),
@@ -3045,6 +3049,7 @@ impl<'a> AstNodes<'a> {
30453049
Self::TSTypeAliasDeclaration(_) => "TSTypeAliasDeclaration",
30463050
Self::TSClassImplements(_) => "TSClassImplements",
30473051
Self::TSInterfaceDeclaration(_) => "TSInterfaceDeclaration",
3052+
Self::TSInterfaceBody(_) => "TSInterfaceBody",
30483053
Self::TSPropertySignature(_) => "TSPropertySignature",
30493054
Self::TSIndexSignature(_) => "TSIndexSignature",
30503055
Self::TSCallSignatureDeclaration(_) => "TSCallSignatureDeclaration",
@@ -9879,7 +9884,7 @@ impl<'a> AstNode<'a, TSInterfaceBody<'a>> {
98799884
self.allocator.alloc(AstNode {
98809885
inner: &self.inner.body,
98819886
allocator: self.allocator,
9882-
parent: self.parent,
9887+
parent: self.allocator.alloc(AstNodes::TSInterfaceBody(transmute_self(self))),
98839888
following_node,
98849889
})
98859890
}

crates/oxc_formatter/src/generated/format.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2553,7 +2553,15 @@ impl<'a> Format<'a> for AstNode<'a, TSInterfaceDeclaration<'a>> {
25532553

25542554
impl<'a> Format<'a> for AstNode<'a, TSInterfaceBody<'a>> {
25552555
fn fmt(&self, f: &mut Formatter<'_, 'a>) -> FormatResult<()> {
2556-
self.write(f)
2556+
format_leading_comments(self.span).fmt(f)?;
2557+
let result = self.write(f);
2558+
format_trailing_comments(
2559+
&self.parent.as_sibling_node(),
2560+
&SiblingNode::from(self.inner),
2561+
self.following_node.as_ref(),
2562+
)
2563+
.fmt(f)?;
2564+
result
25572565
}
25582566
}
25592567

crates/oxc_semantic/tests/fixtures/oxc/ts/exports/named/interface-heritage.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/oxc/ts/exports/named/interface-he
2727
"flags": "ReferenceFlags(Read)",
2828
"id": 1,
2929
"name": "forwardRef",
30-
"node_id": 19
30+
"node_id": 20
3131
}
3232
]
3333
},

crates/oxc_semantic/tests/fixtures/oxc/ts/interfaces/property-with-type-import.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ input_file: crates/oxc_semantic/tests/fixtures/oxc/ts/interfaces/property-with-t
4141
"flags": "ReferenceFlags(Type)",
4242
"id": 0,
4343
"name": "X",
44-
"node_id": 15
44+
"node_id": 16
4545
},
4646
{
4747
"flags": "ReferenceFlags(Type)",
4848
"id": 2,
4949
"name": "X",
50-
"node_id": 27
50+
"node_id": 29
5151
}
5252
]
5353
},
@@ -61,13 +61,13 @@ input_file: crates/oxc_semantic/tests/fixtures/oxc/ts/interfaces/property-with-t
6161
"flags": "ReferenceFlags(Type)",
6262
"id": 1,
6363
"name": "B",
64-
"node_id": 19
64+
"node_id": 20
6565
},
6666
{
6767
"flags": "ReferenceFlags(Type)",
6868
"id": 3,
6969
"name": "B",
70-
"node_id": 32
70+
"node_id": 34
7171
}
7272
]
7373
},

crates/oxc_semantic/tests/fixtures/typescript-eslint/class/declaration/implements-generic.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/class/declarati
4949
"flags": "ReferenceFlags(Type)",
5050
"id": 0,
5151
"name": "A",
52-
"node_id": 13
52+
"node_id": 14
5353
}
5454
]
5555
},
@@ -63,7 +63,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/class/declarati
6363
"flags": "ReferenceFlags(Type)",
6464
"id": 1,
6565
"name": "T",
66-
"node_id": 17
66+
"node_id": 18
6767
}
6868
]
6969
},

crates/oxc_semantic/tests/fixtures/typescript-eslint/class/declaration/implements.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/class/declarati
3434
"flags": "ReferenceFlags(Type)",
3535
"id": 0,
3636
"name": "A",
37-
"node_id": 7
37+
"node_id": 8
3838
}
3939
]
4040
},

0 commit comments

Comments
 (0)