Skip to content

Commit 4fbe4b1

Browse files
refactor(ast): Remove AstKind from TSModuleReference node (#11732)
This PR is part of the ongoing work in #11490 Removes AstKind from `TSModuleReference` nodes by removing the entry from the list of enum exceptions in ast_tools.
1 parent d74c4af commit 4fbe4b1

File tree

10 files changed

+15
-33
lines changed

10 files changed

+15
-33
lines changed

crates/oxc_ast/src/ast_kind_impl.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,6 @@ impl AstKind<'_> {
368368
Self::TSConditionalType(_) => "TSConditionalType".into(),
369369
Self::TSMappedType(_) => "TSMappedType".into(),
370370
Self::TSConstructSignatureDeclaration(_) => "TSConstructSignatureDeclaration".into(),
371-
Self::TSModuleReference(_) => "TSModuleReference".into(),
372371
Self::TSExportAssignment(_) => "TSExportAssignment".into(),
373372
Self::V8IntrinsicExpression(_) => "V8IntrinsicExpression".into(),
374373

crates/oxc_ast/src/generated/ast_kind.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,14 @@ pub enum AstType {
178178
TSSatisfiesExpression = 162,
179179
TSTypeAssertion = 163,
180180
TSImportEqualsDeclaration = 164,
181-
TSModuleReference = 165,
182-
TSExternalModuleReference = 166,
183-
TSNonNullExpression = 167,
184-
Decorator = 168,
185-
TSExportAssignment = 169,
186-
TSInstantiationExpression = 170,
187-
JSDocNullableType = 171,
188-
JSDocNonNullableType = 172,
189-
JSDocUnknownType = 173,
181+
TSExternalModuleReference = 165,
182+
TSNonNullExpression = 166,
183+
Decorator = 167,
184+
TSExportAssignment = 168,
185+
TSInstantiationExpression = 169,
186+
JSDocNullableType = 170,
187+
JSDocNonNullableType = 171,
188+
JSDocUnknownType = 172,
190189
}
191190

192191
/// Untyped AST Node Kind
@@ -370,7 +369,6 @@ pub enum AstKind<'a> {
370369
TSTypeAssertion(&'a TSTypeAssertion<'a>) = AstType::TSTypeAssertion as u8,
371370
TSImportEqualsDeclaration(&'a TSImportEqualsDeclaration<'a>) =
372371
AstType::TSImportEqualsDeclaration as u8,
373-
TSModuleReference(&'a TSModuleReference<'a>) = AstType::TSModuleReference as u8,
374372
TSExternalModuleReference(&'a TSExternalModuleReference<'a>) =
375373
AstType::TSExternalModuleReference as u8,
376374
TSNonNullExpression(&'a TSNonNullExpression<'a>) = AstType::TSNonNullExpression as u8,
@@ -563,7 +561,6 @@ impl GetSpan for AstKind<'_> {
563561
Self::TSSatisfiesExpression(it) => it.span(),
564562
Self::TSTypeAssertion(it) => it.span(),
565563
Self::TSImportEqualsDeclaration(it) => it.span(),
566-
Self::TSModuleReference(it) => it.span(),
567564
Self::TSExternalModuleReference(it) => it.span(),
568565
Self::TSNonNullExpression(it) => it.span(),
569566
Self::Decorator(it) => it.span(),
@@ -1406,11 +1403,6 @@ impl<'a> AstKind<'a> {
14061403
if let Self::TSImportEqualsDeclaration(v) = self { Some(v) } else { None }
14071404
}
14081405

1409-
#[inline]
1410-
pub fn as_ts_module_reference(self) -> Option<&'a TSModuleReference<'a>> {
1411-
if let Self::TSModuleReference(v) = self { Some(v) } else { None }
1412-
}
1413-
14141406
#[inline]
14151407
pub fn as_ts_external_module_reference(self) -> Option<&'a TSExternalModuleReference<'a>> {
14161408
if let Self::TSExternalModuleReference(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
@@ -4021,8 +4021,7 @@ pub mod walk {
40214021

40224022
#[inline]
40234023
pub fn walk_ts_module_reference<'a, V: Visit<'a>>(visitor: &mut V, it: &TSModuleReference<'a>) {
4024-
let kind = AstKind::TSModuleReference(visitor.alloc(it));
4025-
visitor.enter_node(kind);
4024+
// No `AstKind` for this type
40264025
match it {
40274026
TSModuleReference::ExternalModuleReference(it) => {
40284027
visitor.visit_ts_external_module_reference(it)
@@ -4031,7 +4030,6 @@ pub mod walk {
40314030
visitor.visit_ts_type_name(it.to_ts_type_name())
40324031
}
40334032
}
4034-
visitor.leave_node(kind);
40354033
}
40364034

40374035
#[inline]

crates/oxc_ast_visit/src/generated/visit_mut.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4245,8 +4245,7 @@ pub mod walk_mut {
42454245
visitor: &mut V,
42464246
it: &mut TSModuleReference<'a>,
42474247
) {
4248-
let kind = AstType::TSModuleReference;
4249-
visitor.enter_node(kind);
4248+
// No `AstType` for this type
42504249
match it {
42514250
TSModuleReference::ExternalModuleReference(it) => {
42524251
visitor.visit_ts_external_module_reference(it)
@@ -4255,7 +4254,6 @@ pub mod walk_mut {
42554254
visitor.visit_ts_type_name(it.to_ts_type_name_mut())
42564255
}
42574256
}
4258-
visitor.leave_node(kind);
42594257
}
42604258

42614259
#[inline]

crates/oxc_formatter/src/generated/ast_nodes.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ pub enum AstNodes<'a> {
192192
TSSatisfiesExpression(&'a AstNode<'a, TSSatisfiesExpression<'a>>),
193193
TSTypeAssertion(&'a AstNode<'a, TSTypeAssertion<'a>>),
194194
TSImportEqualsDeclaration(&'a AstNode<'a, TSImportEqualsDeclaration<'a>>),
195-
TSModuleReference(&'a AstNode<'a, TSModuleReference<'a>>),
196195
TSExternalModuleReference(&'a AstNode<'a, TSExternalModuleReference<'a>>),
197196
TSNonNullExpression(&'a AstNode<'a, TSNonNullExpression<'a>>),
198197
Decorator(&'a AstNode<'a, Decorator<'a>>),
@@ -372,7 +371,6 @@ impl<'a> AstNodes<'a> {
372371
Self::TSSatisfiesExpression(n) => n.span(),
373372
Self::TSTypeAssertion(n) => n.span(),
374373
Self::TSImportEqualsDeclaration(n) => n.span(),
375-
Self::TSModuleReference(n) => n.span(),
376374
Self::TSExternalModuleReference(n) => n.span(),
377375
Self::TSNonNullExpression(n) => n.span(),
378376
Self::Decorator(n) => n.span(),
@@ -552,7 +550,6 @@ impl<'a> AstNodes<'a> {
552550
Self::TSSatisfiesExpression(n) => n.parent,
553551
Self::TSTypeAssertion(n) => n.parent,
554552
Self::TSImportEqualsDeclaration(n) => n.parent,
555-
Self::TSModuleReference(n) => n.parent,
556553
Self::TSExternalModuleReference(n) => n.parent,
557554
Self::TSNonNullExpression(n) => n.parent,
558555
Self::Decorator(n) => n.parent,
@@ -732,7 +729,6 @@ impl<'a> AstNodes<'a> {
732729
Self::TSSatisfiesExpression(_) => "TSSatisfiesExpression",
733730
Self::TSTypeAssertion(_) => "TSTypeAssertion",
734731
Self::TSImportEqualsDeclaration(_) => "TSImportEqualsDeclaration",
735-
Self::TSModuleReference(_) => "TSModuleReference",
736732
Self::TSExternalModuleReference(_) => "TSExternalModuleReference",
737733
Self::TSNonNullExpression(_) => "TSNonNullExpression",
738734
Self::Decorator(_) => "Decorator",
@@ -7391,7 +7387,7 @@ impl<'a> AstNode<'a, TSImportEqualsDeclaration<'a>> {
73917387
impl<'a> AstNode<'a, TSModuleReference<'a>> {
73927388
#[inline]
73937389
pub fn as_ast_nodes(&self) -> &AstNodes<'a> {
7394-
let parent = self.allocator.alloc(AstNodes::TSModuleReference(transmute_self(self)));
7390+
let parent = self.parent;
73957391
let node = match self.inner {
73967392
TSModuleReference::ExternalModuleReference(s) => {
73977393
AstNodes::TSExternalModuleReference(self.allocator.alloc(AstNode {

crates/oxc_formatter/src/generated/format_write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ impl<'a> FormatWrite<'a> for AstNode<'a, TSModuleReference<'a>> {
10951095
#[inline]
10961096
fn write(&self, f: &mut Formatter<'_, 'a>) -> FormatResult<()> {
10971097
let allocator = self.allocator;
1098-
let parent = allocator.alloc(AstNodes::TSModuleReference(transmute_self(self)));
1098+
let parent = self.parent;
10991099
match self.inner {
11001100
TSModuleReference::ExternalModuleReference(inner) => allocator
11011101
.alloc(AstNode::<TSExternalModuleReference> { inner, parent, allocator })

crates/oxc_semantic/src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2041,7 +2041,7 @@ impl<'a> SemanticBuilder<'a> {
20412041
Some(
20422042
// import A = a;
20432043
// ^
2044-
AstKind::TSModuleReference(_),
2044+
AstKind::TSImportEqualsDeclaration(_),
20452045
) => {
20462046
self.current_reference_flags = ReferenceFlags::Read;
20472047
}

crates/oxc_semantic/tests/fixtures/typescript-eslint/import/equals1.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/import/equals1.
1919
"flags": "ReferenceFlags(Read)",
2020
"id": 0,
2121
"name": "foo",
22-
"node_id": 7
22+
"node_id": 6
2323
}
2424
]
2525
}

crates/oxc_semantic/tests/fixtures/typescript-eslint/import/equals2.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/import/equals2.
1919
"flags": "ReferenceFlags(Read)",
2020
"id": 0,
2121
"name": "x",
22-
"node_id": 9
22+
"node_id": 8
2323
}
2424
]
2525
},

tasks/ast_tools/src/generators/ast_kind.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ const ENUMS_WHITE_LIST: &[&str] = &[
6262
"AssignmentTargetPattern",
6363
"ModuleDeclaration",
6464
"TSTypeName",
65-
"TSModuleReference",
6665
];
6766

6867
/// Generator for `AstKind`, `AstType`, and related code.

0 commit comments

Comments
 (0)