Skip to content

Commit fadbd93

Browse files
author
Cameron McHenry
committed
refactor(ast): remove AstKind for TSTypeName
1 parent f7a2ae4 commit fadbd93

File tree

130 files changed

+266
-277
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+266
-277
lines changed

crates/oxc_ast/src/ast_kind_impl.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,6 @@ impl AstKind<'_> {
382382
Self::TSNamespaceExportDeclaration(_) => "TSNamespaceExportDeclaration".into(),
383383
Self::TSImportEqualsDeclaration(_) => "TSImportEqualsDeclaration".into(),
384384
Self::TSCallSignatureDeclaration(_) => "TSCallSignatureDeclaration".into(),
385-
Self::TSTypeName(n) => format!("TSTypeName({n})").into(),
386385
Self::TSExternalModuleReference(_) => "TSExternalModuleReference".into(),
387386
Self::TSQualifiedName(n) => format!("TSQualifiedName({n})").into(),
388387
Self::TSInterfaceDeclaration(_) => "TSInterfaceDeclaration".into(),

crates/oxc_ast/src/generated/ast_kind.rs

Lines changed: 38 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -166,45 +166,44 @@ pub enum AstType {
166166
TSObjectKeyword = 149,
167167
TSBigIntKeyword = 150,
168168
TSTypeReference = 151,
169-
TSTypeName = 152,
170-
TSQualifiedName = 153,
171-
TSTypeParameterInstantiation = 154,
172-
TSTypeParameter = 155,
173-
TSTypeParameterDeclaration = 156,
174-
TSTypeAliasDeclaration = 157,
175-
TSClassImplements = 158,
176-
TSInterfaceDeclaration = 159,
177-
TSInterfaceBody = 160,
178-
TSPropertySignature = 161,
179-
TSIndexSignature = 162,
180-
TSCallSignatureDeclaration = 163,
181-
TSMethodSignature = 164,
182-
TSConstructSignatureDeclaration = 165,
183-
TSIndexSignatureName = 166,
184-
TSInterfaceHeritage = 167,
185-
TSTypePredicate = 168,
186-
TSModuleDeclaration = 169,
187-
TSModuleBlock = 170,
188-
TSTypeLiteral = 171,
189-
TSInferType = 172,
190-
TSTypeQuery = 173,
191-
TSImportType = 174,
192-
TSConstructorType = 175,
193-
TSMappedType = 176,
194-
TSTemplateLiteralType = 177,
195-
TSAsExpression = 178,
196-
TSSatisfiesExpression = 179,
197-
TSTypeAssertion = 180,
198-
TSImportEqualsDeclaration = 181,
199-
TSExternalModuleReference = 182,
200-
TSNonNullExpression = 183,
201-
Decorator = 184,
202-
TSExportAssignment = 185,
203-
TSNamespaceExportDeclaration = 186,
204-
TSInstantiationExpression = 187,
205-
JSDocNullableType = 188,
206-
JSDocNonNullableType = 189,
207-
JSDocUnknownType = 190,
169+
TSQualifiedName = 152,
170+
TSTypeParameterInstantiation = 153,
171+
TSTypeParameter = 154,
172+
TSTypeParameterDeclaration = 155,
173+
TSTypeAliasDeclaration = 156,
174+
TSClassImplements = 157,
175+
TSInterfaceDeclaration = 158,
176+
TSInterfaceBody = 159,
177+
TSPropertySignature = 160,
178+
TSIndexSignature = 161,
179+
TSCallSignatureDeclaration = 162,
180+
TSMethodSignature = 163,
181+
TSConstructSignatureDeclaration = 164,
182+
TSIndexSignatureName = 165,
183+
TSInterfaceHeritage = 166,
184+
TSTypePredicate = 167,
185+
TSModuleDeclaration = 168,
186+
TSModuleBlock = 169,
187+
TSTypeLiteral = 170,
188+
TSInferType = 171,
189+
TSTypeQuery = 172,
190+
TSImportType = 173,
191+
TSConstructorType = 174,
192+
TSMappedType = 175,
193+
TSTemplateLiteralType = 176,
194+
TSAsExpression = 177,
195+
TSSatisfiesExpression = 178,
196+
TSTypeAssertion = 179,
197+
TSImportEqualsDeclaration = 180,
198+
TSExternalModuleReference = 181,
199+
TSNonNullExpression = 182,
200+
Decorator = 183,
201+
TSExportAssignment = 184,
202+
TSNamespaceExportDeclaration = 185,
203+
TSInstantiationExpression = 186,
204+
JSDocNullableType = 187,
205+
JSDocNonNullableType = 188,
206+
JSDocUnknownType = 189,
208207
}
209208

210209
/// Untyped AST Node Kind
@@ -373,7 +372,6 @@ pub enum AstKind<'a> {
373372
TSObjectKeyword(&'a TSObjectKeyword) = AstType::TSObjectKeyword as u8,
374373
TSBigIntKeyword(&'a TSBigIntKeyword) = AstType::TSBigIntKeyword as u8,
375374
TSTypeReference(&'a TSTypeReference<'a>) = AstType::TSTypeReference as u8,
376-
TSTypeName(&'a TSTypeName<'a>) = AstType::TSTypeName as u8,
377375
TSQualifiedName(&'a TSQualifiedName<'a>) = AstType::TSQualifiedName as u8,
378376
TSTypeParameterInstantiation(&'a TSTypeParameterInstantiation<'a>) =
379377
AstType::TSTypeParameterInstantiation as u8,
@@ -589,7 +587,6 @@ impl GetSpan for AstKind<'_> {
589587
Self::TSObjectKeyword(it) => it.span(),
590588
Self::TSBigIntKeyword(it) => it.span(),
591589
Self::TSTypeReference(it) => it.span(),
592-
Self::TSTypeName(it) => it.span(),
593590
Self::TSQualifiedName(it) => it.span(),
594591
Self::TSTypeParameterInstantiation(it) => it.span(),
595592
Self::TSTypeParameter(it) => it.span(),
@@ -787,7 +784,6 @@ impl GetAddress for AstKind<'_> {
787784
Self::TSObjectKeyword(it) => Address::from_ptr(it),
788785
Self::TSBigIntKeyword(it) => Address::from_ptr(it),
789786
Self::TSTypeReference(it) => Address::from_ptr(it),
790-
Self::TSTypeName(it) => it.address(),
791787
Self::TSQualifiedName(it) => Address::from_ptr(it),
792788
Self::TSTypeParameterInstantiation(it) => Address::from_ptr(it),
793789
Self::TSTypeParameter(it) => Address::from_ptr(it),
@@ -1595,11 +1591,6 @@ impl<'a> AstKind<'a> {
15951591
if let Self::TSTypeReference(v) = self { Some(v) } else { None }
15961592
}
15971593

1598-
#[inline]
1599-
pub fn as_ts_type_name(self) -> Option<&'a TSTypeName<'a>> {
1600-
if let Self::TSTypeName(v) = self { Some(v) } else { None }
1601-
}
1602-
16031594
#[inline]
16041595
pub fn as_ts_qualified_name(self) -> Option<&'a TSQualifiedName<'a>> {
16051596
if let Self::TSQualifiedName(v) = self { Some(v) } else { None }

crates/oxc_ast_visit/src/generated/visit.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3555,13 +3555,11 @@ pub mod walk {
35553555

35563556
#[inline]
35573557
pub fn walk_ts_type_name<'a, V: Visit<'a>>(visitor: &mut V, it: &TSTypeName<'a>) {
3558-
let kind = AstKind::TSTypeName(visitor.alloc(it));
3559-
visitor.enter_node(kind);
3558+
// No `AstKind` for this type
35603559
match it {
35613560
TSTypeName::IdentifierReference(it) => visitor.visit_identifier_reference(it),
35623561
TSTypeName::QualifiedName(it) => visitor.visit_ts_qualified_name(it),
35633562
}
3564-
visitor.leave_node(kind);
35653563
}
35663564

35673565
#[inline]

crates/oxc_ast_visit/src/generated/visit_mut.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3743,13 +3743,11 @@ pub mod walk_mut {
37433743

37443744
#[inline]
37453745
pub fn walk_ts_type_name<'a, V: VisitMut<'a>>(visitor: &mut V, it: &mut TSTypeName<'a>) {
3746-
let kind = AstType::TSTypeName;
3747-
visitor.enter_node(kind);
3746+
// No `AstType` for this type
37483747
match it {
37493748
TSTypeName::IdentifierReference(it) => visitor.visit_identifier_reference(it),
37503749
TSTypeName::QualifiedName(it) => visitor.visit_ts_qualified_name(it),
37513750
}
3752-
visitor.leave_node(kind);
37533751
}
37543752

37553753
#[inline]

crates/oxc_formatter/src/generated/ast_nodes.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ pub enum AstNodes<'a> {
179179
TSObjectKeyword(&'a AstNode<'a, TSObjectKeyword>),
180180
TSBigIntKeyword(&'a AstNode<'a, TSBigIntKeyword>),
181181
TSTypeReference(&'a AstNode<'a, TSTypeReference<'a>>),
182-
TSTypeName(&'a AstNode<'a, TSTypeName<'a>>),
183182
TSQualifiedName(&'a AstNode<'a, TSQualifiedName<'a>>),
184183
TSTypeParameterInstantiation(&'a AstNode<'a, TSTypeParameterInstantiation<'a>>),
185184
TSTypeParameter(&'a AstNode<'a, TSTypeParameter<'a>>),
@@ -2470,7 +2469,6 @@ impl<'a> AstNodes<'a> {
24702469
Self::TSObjectKeyword(n) => n.span(),
24712470
Self::TSBigIntKeyword(n) => n.span(),
24722471
Self::TSTypeReference(n) => n.span(),
2473-
Self::TSTypeName(n) => n.span(),
24742472
Self::TSQualifiedName(n) => n.span(),
24752473
Self::TSTypeParameterInstantiation(n) => n.span(),
24762474
Self::TSTypeParameter(n) => n.span(),
@@ -2667,7 +2665,6 @@ impl<'a> AstNodes<'a> {
26672665
Self::TSObjectKeyword(n) => n.parent,
26682666
Self::TSBigIntKeyword(n) => n.parent,
26692667
Self::TSTypeReference(n) => n.parent,
2670-
Self::TSTypeName(n) => n.parent,
26712668
Self::TSQualifiedName(n) => n.parent,
26722669
Self::TSTypeParameterInstantiation(n) => n.parent,
26732670
Self::TSTypeParameter(n) => n.parent,
@@ -2864,7 +2861,6 @@ impl<'a> AstNodes<'a> {
28642861
Self::TSObjectKeyword(n) => SiblingNode::from(n.inner),
28652862
Self::TSBigIntKeyword(n) => SiblingNode::from(n.inner),
28662863
Self::TSTypeReference(n) => SiblingNode::from(n.inner),
2867-
Self::TSTypeName(n) => n.parent.as_sibling_node(),
28682864
Self::TSQualifiedName(n) => SiblingNode::from(n.inner),
28692865
Self::TSTypeParameterInstantiation(n) => SiblingNode::from(n.inner),
28702866
Self::TSTypeParameter(n) => SiblingNode::from(n.inner),
@@ -3061,7 +3057,6 @@ impl<'a> AstNodes<'a> {
30613057
Self::TSObjectKeyword(_) => "TSObjectKeyword",
30623058
Self::TSBigIntKeyword(_) => "TSBigIntKeyword",
30633059
Self::TSTypeReference(_) => "TSTypeReference",
3064-
Self::TSTypeName(_) => "TSTypeName",
30653060
Self::TSQualifiedName(_) => "TSQualifiedName",
30663061
Self::TSTypeParameterInstantiation(_) => "TSTypeParameterInstantiation",
30673062
Self::TSTypeParameter(_) => "TSTypeParameter",
@@ -9586,7 +9581,7 @@ impl<'a> AstNode<'a, TSTypeReference<'a>> {
95869581
impl<'a> AstNode<'a, TSTypeName<'a>> {
95879582
#[inline]
95889583
pub fn as_ast_nodes(&self) -> &AstNodes<'a> {
9589-
let parent = self.allocator.alloc(AstNodes::TSTypeName(transmute_self(self)));
9584+
let parent = self.parent;
95909585
let node = match self.inner {
95919586
TSTypeName::IdentifierReference(s) => {
95929587
AstNodes::IdentifierReference(self.allocator.alloc(AstNode {
@@ -10645,12 +10640,15 @@ impl<'a> AstNode<'a, TSTypeQueryExprName<'a>> {
1064510640
}))
1064610641
}
1064710642
it @ match_ts_type_name!(TSTypeQueryExprName) => {
10648-
AstNodes::TSTypeName(self.allocator.alloc(AstNode {
10649-
inner: it.to_ts_type_name(),
10650-
parent,
10651-
allocator: self.allocator,
10652-
following_node: self.following_node,
10653-
}))
10643+
return self
10644+
.allocator
10645+
.alloc(AstNode {
10646+
inner: it.to_ts_type_name(),
10647+
parent,
10648+
allocator: self.allocator,
10649+
following_node: self.following_node,
10650+
})
10651+
.as_ast_nodes();
1065410652
}
1065510653
};
1065610654
self.allocator.alloc(node)
@@ -11074,12 +11072,15 @@ impl<'a> AstNode<'a, TSModuleReference<'a>> {
1107411072
}))
1107511073
}
1107611074
it @ match_ts_type_name!(TSModuleReference) => {
11077-
AstNodes::TSTypeName(self.allocator.alloc(AstNode {
11078-
inner: it.to_ts_type_name(),
11079-
parent,
11080-
allocator: self.allocator,
11081-
following_node: self.following_node,
11082-
}))
11075+
return self
11076+
.allocator
11077+
.alloc(AstNode {
11078+
inner: it.to_ts_type_name(),
11079+
parent,
11080+
allocator: self.allocator,
11081+
following_node: self.following_node,
11082+
})
11083+
.as_ast_nodes();
1108311084
}
1108411085
};
1108511086
self.allocator.alloc(node)

crates/oxc_formatter/src/generated/format_write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2030,7 +2030,7 @@ impl<'a> FormatWrite<'a> for AstNode<'a, TSTypeName<'a>> {
20302030
#[inline]
20312031
fn write(&self, f: &mut Formatter<'_, 'a>) -> FormatResult<()> {
20322032
let allocator = self.allocator;
2033-
let parent = allocator.alloc(AstNodes::TSTypeName(transmute_self(self)));
2033+
let parent = self.parent;
20342034
match self.inner {
20352035
TSTypeName::IdentifierReference(inner) => allocator
20362036
.alloc(AstNode::<IdentifierReference> {

crates/oxc_linter/src/rules/eslint/no_unused_vars/usage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ impl<'a> Symbol<'_, 'a> {
847847
loop {
848848
node = match node.kind() {
849849
AstKind::TSTypeQuery(_) => return true,
850-
AstKind::TSQualifiedName(_) | AstKind::TSTypeName(_) => {
850+
AstKind::TSQualifiedName(_) | AstKind::IdentifierReference(_) => {
851851
if let Some(parent) = self.nodes().parent_node(node.id()) {
852852
parent
853853
} else {

crates/oxc_semantic/src/builder.rs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,28 +2034,28 @@ impl<'a> SemanticBuilder<'a> {
20342034
// ^^^ avoid treat T as a value and TSTypeQuery
20352035
self.current_reference_flags -= ReferenceFlags::ValueAsType;
20362036
}
2037-
AstKind::TSTypeName(_) => {
2038-
match self.nodes.parent_kind(self.current_node_id) {
2039-
Some(
2040-
// import A = a;
2041-
// ^
2042-
AstKind::TSImportEqualsDeclaration(_),
2043-
) => {
2044-
self.current_reference_flags = ReferenceFlags::Read;
2045-
}
2046-
Some(AstKind::TSQualifiedName(_)) => {
2047-
// import A = a.b
2048-
// ^^^ Keep the current reference flag
2049-
}
2050-
_ => {
2051-
// Handled in `AstKind::PropertySignature` or `AstKind::TSTypeQuery`
2052-
if !self.current_reference_flags.is_value_as_type() {
2053-
self.current_reference_flags = ReferenceFlags::Type;
2054-
}
2055-
}
2037+
AstKind::TSClassImplements(_) | AstKind::TSTypeReference(_) => {
2038+
// type X = SomeType;
2039+
// ^^^^^^^^
2040+
//
2041+
// class A implements B {}
2042+
// ^^^^^^^^^^^^
2043+
//
2044+
// let X: import('module').Y;
2045+
// ^^^^^^^^^^^^^^^^
2046+
if !self.current_reference_flags.is_value_as_type() {
2047+
self.current_reference_flags = ReferenceFlags::Type;
20562048
}
20572049
}
20582050
AstKind::IdentifierReference(ident) => {
2051+
if let Some(AstKind::TSImportType(_)) = self.nodes.parent_kind(self.current_node_id)
2052+
{
2053+
// let X: import('module').X
2054+
// ^
2055+
// We don't want to treat this as a value reference.
2056+
self.current_reference_flags = ReferenceFlags::Type;
2057+
}
2058+
20592059
self.reference_identifier(ident);
20602060
}
20612061
AstKind::LabeledStatement(stmt) => {
@@ -2093,8 +2093,11 @@ impl<'a> SemanticBuilder<'a> {
20932093
AstKind::CatchParameter(_) => {
20942094
self.resolve_references_for_current_scope();
20952095
}
2096-
AstKind::TSTypeName(_) => {
2097-
self.current_reference_flags -= ReferenceFlags::Type;
2096+
AstKind::IdentifierReference(_) | AstKind::TSQualifiedName(_) => {
2097+
if matches!(self.nodes.parent_kind(self.current_node_id), Some(AstKind::TSImportType(_) | AstKind::TSTypeReference(_) | AstKind::TSClassImplements(_))) {
2098+
// Clear the type reference flags that were set in `enter_kind` for these kinds.
2099+
self.current_reference_flags -= ReferenceFlags::Type;
2100+
}
20982101
}
20992102
AstKind::TSTypeQuery(_)
21002103
// Clear the reference flags that are set in AstKind::PropertySignature

crates/oxc_semantic/tests/fixtures/oxc/ts/functions/return-type.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ input_file: crates/oxc_semantic/tests/fixtures/oxc/ts/functions/return-type.ts
7373
"flags": "ReferenceFlags(Type)",
7474
"id": 0,
7575
"name": "T",
76-
"node_id": 12
76+
"node_id": 11
7777
},
7878
{
7979
"flags": "ReferenceFlags(Type)",
8080
"id": 1,
8181
"name": "T",
82-
"node_id": 27
82+
"node_id": 25
8383
}
8484
]
8585
},

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ input_file: crates/oxc_semantic/tests/fixtures/oxc/ts/interfaces/property-with-t
4747
"flags": "ReferenceFlags(Type)",
4848
"id": 2,
4949
"name": "X",
50-
"node_id": 29
50+
"node_id": 28
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": 20
64+
"node_id": 19
6565
},
6666
{
6767
"flags": "ReferenceFlags(Type)",
6868
"id": 3,
6969
"name": "B",
70-
"node_id": 34
70+
"node_id": 32
7171
}
7272
]
7373
},

0 commit comments

Comments
 (0)