Skip to content

Commit eb9db97

Browse files
feat(ast): Add AstKind to AccessorProperty node (#11764)
This PR is part of the ongoing work in #11490 Adds AstKind to AccessorProperty nodes by removing the entry from the list of exceptions in ast_tools.
1 parent 6feab7e commit eb9db97

File tree

7 files changed

+133
-111
lines changed

7 files changed

+133
-111
lines changed

crates/oxc_ast/src/ast_kind_impl.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ impl AstKind<'_> {
204204
Self::MetaProperty(_) => "MetaProperty".into(),
205205
Self::Super(_) => "Super".into(),
206206

207+
Self::AccessorProperty(_) => "AccessorProperty".into(),
208+
207209
Self::ArrayExpression(_) => "ArrayExpression".into(),
208210
Self::ArrowFunctionExpression(_) => "ArrowFunctionExpression".into(),
209211
Self::AssignmentExpression(_) => "AssignmentExpression".into(),

crates/oxc_ast/src/generated/ast_kind.rs

Lines changed: 108 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -92,106 +92,107 @@ pub enum AstType {
9292
PrivateIdentifier = 76,
9393
StaticBlock = 77,
9494
ModuleDeclaration = 78,
95-
ImportExpression = 79,
96-
ImportDeclaration = 80,
97-
ImportSpecifier = 81,
98-
ImportDefaultSpecifier = 82,
99-
ImportNamespaceSpecifier = 83,
100-
WithClause = 84,
101-
ExportNamedDeclaration = 85,
102-
ExportDefaultDeclaration = 86,
103-
ExportAllDeclaration = 87,
104-
ExportSpecifier = 88,
105-
V8IntrinsicExpression = 89,
106-
BooleanLiteral = 90,
107-
NullLiteral = 91,
108-
NumericLiteral = 92,
109-
StringLiteral = 93,
110-
BigIntLiteral = 94,
111-
RegExpLiteral = 95,
112-
JSXElement = 96,
113-
JSXOpeningElement = 97,
114-
JSXClosingElement = 98,
115-
JSXFragment = 99,
116-
JSXOpeningFragment = 100,
117-
JSXClosingFragment = 101,
118-
JSXNamespacedName = 102,
119-
JSXMemberExpression = 103,
120-
JSXExpressionContainer = 104,
121-
JSXEmptyExpression = 105,
122-
JSXAttribute = 106,
123-
JSXSpreadAttribute = 107,
124-
JSXIdentifier = 108,
125-
JSXSpreadChild = 109,
126-
JSXText = 110,
127-
TSThisParameter = 111,
128-
TSEnumDeclaration = 112,
129-
TSEnumBody = 113,
130-
TSEnumMember = 114,
131-
TSTypeAnnotation = 115,
132-
TSLiteralType = 116,
133-
TSConditionalType = 117,
134-
TSUnionType = 118,
135-
TSIntersectionType = 119,
136-
TSParenthesizedType = 120,
137-
TSTypeOperator = 121,
138-
TSArrayType = 122,
139-
TSIndexedAccessType = 123,
140-
TSTupleType = 124,
141-
TSNamedTupleMember = 125,
142-
TSOptionalType = 126,
143-
TSRestType = 127,
144-
TSAnyKeyword = 128,
145-
TSStringKeyword = 129,
146-
TSBooleanKeyword = 130,
147-
TSNumberKeyword = 131,
148-
TSNeverKeyword = 132,
149-
TSIntrinsicKeyword = 133,
150-
TSUnknownKeyword = 134,
151-
TSNullKeyword = 135,
152-
TSUndefinedKeyword = 136,
153-
TSVoidKeyword = 137,
154-
TSSymbolKeyword = 138,
155-
TSThisType = 139,
156-
TSObjectKeyword = 140,
157-
TSBigIntKeyword = 141,
158-
TSTypeReference = 142,
159-
TSTypeName = 143,
160-
TSQualifiedName = 144,
161-
TSTypeParameterInstantiation = 145,
162-
TSTypeParameter = 146,
163-
TSTypeParameterDeclaration = 147,
164-
TSTypeAliasDeclaration = 148,
165-
TSClassImplements = 149,
166-
TSInterfaceDeclaration = 150,
167-
TSPropertySignature = 151,
168-
TSCallSignatureDeclaration = 152,
169-
TSMethodSignature = 153,
170-
TSConstructSignatureDeclaration = 154,
171-
TSIndexSignatureName = 155,
172-
TSInterfaceHeritage = 156,
173-
TSTypePredicate = 157,
174-
TSModuleDeclaration = 158,
175-
TSModuleBlock = 159,
176-
TSTypeLiteral = 160,
177-
TSInferType = 161,
178-
TSTypeQuery = 162,
179-
TSImportType = 163,
180-
TSMappedType = 164,
181-
TSTemplateLiteralType = 165,
182-
TSAsExpression = 166,
183-
TSSatisfiesExpression = 167,
184-
TSTypeAssertion = 168,
185-
TSImportEqualsDeclaration = 169,
186-
TSExternalModuleReference = 170,
187-
TSNonNullExpression = 171,
188-
Decorator = 172,
189-
TSExportAssignment = 173,
190-
TSNamespaceExportDeclaration = 174,
191-
TSInstantiationExpression = 175,
192-
JSDocNullableType = 176,
193-
JSDocNonNullableType = 177,
194-
JSDocUnknownType = 178,
95+
AccessorProperty = 79,
96+
ImportExpression = 80,
97+
ImportDeclaration = 81,
98+
ImportSpecifier = 82,
99+
ImportDefaultSpecifier = 83,
100+
ImportNamespaceSpecifier = 84,
101+
WithClause = 85,
102+
ExportNamedDeclaration = 86,
103+
ExportDefaultDeclaration = 87,
104+
ExportAllDeclaration = 88,
105+
ExportSpecifier = 89,
106+
V8IntrinsicExpression = 90,
107+
BooleanLiteral = 91,
108+
NullLiteral = 92,
109+
NumericLiteral = 93,
110+
StringLiteral = 94,
111+
BigIntLiteral = 95,
112+
RegExpLiteral = 96,
113+
JSXElement = 97,
114+
JSXOpeningElement = 98,
115+
JSXClosingElement = 99,
116+
JSXFragment = 100,
117+
JSXOpeningFragment = 101,
118+
JSXClosingFragment = 102,
119+
JSXNamespacedName = 103,
120+
JSXMemberExpression = 104,
121+
JSXExpressionContainer = 105,
122+
JSXEmptyExpression = 106,
123+
JSXAttribute = 107,
124+
JSXSpreadAttribute = 108,
125+
JSXIdentifier = 109,
126+
JSXSpreadChild = 110,
127+
JSXText = 111,
128+
TSThisParameter = 112,
129+
TSEnumDeclaration = 113,
130+
TSEnumBody = 114,
131+
TSEnumMember = 115,
132+
TSTypeAnnotation = 116,
133+
TSLiteralType = 117,
134+
TSConditionalType = 118,
135+
TSUnionType = 119,
136+
TSIntersectionType = 120,
137+
TSParenthesizedType = 121,
138+
TSTypeOperator = 122,
139+
TSArrayType = 123,
140+
TSIndexedAccessType = 124,
141+
TSTupleType = 125,
142+
TSNamedTupleMember = 126,
143+
TSOptionalType = 127,
144+
TSRestType = 128,
145+
TSAnyKeyword = 129,
146+
TSStringKeyword = 130,
147+
TSBooleanKeyword = 131,
148+
TSNumberKeyword = 132,
149+
TSNeverKeyword = 133,
150+
TSIntrinsicKeyword = 134,
151+
TSUnknownKeyword = 135,
152+
TSNullKeyword = 136,
153+
TSUndefinedKeyword = 137,
154+
TSVoidKeyword = 138,
155+
TSSymbolKeyword = 139,
156+
TSThisType = 140,
157+
TSObjectKeyword = 141,
158+
TSBigIntKeyword = 142,
159+
TSTypeReference = 143,
160+
TSTypeName = 144,
161+
TSQualifiedName = 145,
162+
TSTypeParameterInstantiation = 146,
163+
TSTypeParameter = 147,
164+
TSTypeParameterDeclaration = 148,
165+
TSTypeAliasDeclaration = 149,
166+
TSClassImplements = 150,
167+
TSInterfaceDeclaration = 151,
168+
TSPropertySignature = 152,
169+
TSCallSignatureDeclaration = 153,
170+
TSMethodSignature = 154,
171+
TSConstructSignatureDeclaration = 155,
172+
TSIndexSignatureName = 156,
173+
TSInterfaceHeritage = 157,
174+
TSTypePredicate = 158,
175+
TSModuleDeclaration = 159,
176+
TSModuleBlock = 160,
177+
TSTypeLiteral = 161,
178+
TSInferType = 162,
179+
TSTypeQuery = 163,
180+
TSImportType = 164,
181+
TSMappedType = 165,
182+
TSTemplateLiteralType = 166,
183+
TSAsExpression = 167,
184+
TSSatisfiesExpression = 168,
185+
TSTypeAssertion = 169,
186+
TSImportEqualsDeclaration = 170,
187+
TSExternalModuleReference = 171,
188+
TSNonNullExpression = 172,
189+
Decorator = 173,
190+
TSExportAssignment = 174,
191+
TSNamespaceExportDeclaration = 175,
192+
TSInstantiationExpression = 176,
193+
JSDocNullableType = 177,
194+
JSDocNonNullableType = 178,
195+
JSDocUnknownType = 179,
195196
}
196197

197198
/// Untyped AST Node Kind
@@ -282,6 +283,7 @@ pub enum AstKind<'a> {
282283
PrivateIdentifier(&'a PrivateIdentifier<'a>) = AstType::PrivateIdentifier as u8,
283284
StaticBlock(&'a StaticBlock<'a>) = AstType::StaticBlock as u8,
284285
ModuleDeclaration(&'a ModuleDeclaration<'a>) = AstType::ModuleDeclaration as u8,
286+
AccessorProperty(&'a AccessorProperty<'a>) = AstType::AccessorProperty as u8,
285287
ImportExpression(&'a ImportExpression<'a>) = AstType::ImportExpression as u8,
286288
ImportDeclaration(&'a ImportDeclaration<'a>) = AstType::ImportDeclaration as u8,
287289
ImportSpecifier(&'a ImportSpecifier<'a>) = AstType::ImportSpecifier as u8,
@@ -488,6 +490,7 @@ impl GetSpan for AstKind<'_> {
488490
Self::PrivateIdentifier(it) => it.span(),
489491
Self::StaticBlock(it) => it.span(),
490492
Self::ModuleDeclaration(it) => it.span(),
493+
Self::AccessorProperty(it) => it.span(),
491494
Self::ImportExpression(it) => it.span(),
492495
Self::ImportDeclaration(it) => it.span(),
493496
Self::ImportSpecifier(it) => it.span(),
@@ -988,6 +991,11 @@ impl<'a> AstKind<'a> {
988991
if let Self::ModuleDeclaration(v) = self { Some(v) } else { None }
989992
}
990993

994+
#[inline]
995+
pub fn as_accessor_property(self) -> Option<&'a AccessorProperty<'a>> {
996+
if let Self::AccessorProperty(v) = self { Some(v) } else { None }
997+
}
998+
991999
#[inline]
9921000
pub fn as_import_expression(self) -> Option<&'a ImportExpression<'a>> {
9931001
if let Self::ImportExpression(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
@@ -2645,7 +2645,8 @@ pub mod walk {
26452645

26462646
#[inline]
26472647
pub fn walk_accessor_property<'a, V: Visit<'a>>(visitor: &mut V, it: &AccessorProperty<'a>) {
2648-
// No `AstKind` for this type
2648+
let kind = AstKind::AccessorProperty(visitor.alloc(it));
2649+
visitor.enter_node(kind);
26492650
visitor.visit_span(&it.span);
26502651
visitor.visit_decorators(&it.decorators);
26512652
visitor.visit_property_key(&it.key);
@@ -2655,6 +2656,7 @@ pub mod walk {
26552656
if let Some(value) = &it.value {
26562657
visitor.visit_expression(value);
26572658
}
2659+
visitor.leave_node(kind);
26582660
}
26592661

26602662
#[inline]

crates/oxc_ast_visit/src/generated/visit_mut.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2743,7 +2743,8 @@ pub mod walk_mut {
27432743
visitor: &mut V,
27442744
it: &mut AccessorProperty<'a>,
27452745
) {
2746-
// No `AstType` for this type
2746+
let kind = AstType::AccessorProperty;
2747+
visitor.enter_node(kind);
27472748
visitor.visit_span(&mut it.span);
27482749
visitor.visit_decorators(&mut it.decorators);
27492750
visitor.visit_property_key(&mut it.key);
@@ -2753,6 +2754,7 @@ pub mod walk_mut {
27532754
if let Some(value) = &mut it.value {
27542755
visitor.visit_expression(value);
27552756
}
2757+
visitor.leave_node(kind);
27562758
}
27572759

27582760
#[inline]

crates/oxc_formatter/src/generated/ast_nodes.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ pub enum AstNodes<'a> {
106106
PrivateIdentifier(&'a AstNode<'a, PrivateIdentifier<'a>>),
107107
StaticBlock(&'a AstNode<'a, StaticBlock<'a>>),
108108
ModuleDeclaration(&'a AstNode<'a, ModuleDeclaration<'a>>),
109+
AccessorProperty(&'a AstNode<'a, AccessorProperty<'a>>),
109110
ImportExpression(&'a AstNode<'a, ImportExpression<'a>>),
110111
ImportDeclaration(&'a AstNode<'a, ImportDeclaration<'a>>),
111112
ImportSpecifier(&'a AstNode<'a, ImportSpecifier<'a>>),
@@ -291,6 +292,7 @@ impl<'a> AstNodes<'a> {
291292
Self::PrivateIdentifier(n) => n.span(),
292293
Self::StaticBlock(n) => n.span(),
293294
Self::ModuleDeclaration(n) => n.span(),
295+
Self::AccessorProperty(n) => n.span(),
294296
Self::ImportExpression(n) => n.span(),
295297
Self::ImportDeclaration(n) => n.span(),
296298
Self::ImportSpecifier(n) => n.span(),
@@ -476,6 +478,7 @@ impl<'a> AstNodes<'a> {
476478
Self::PrivateIdentifier(n) => n.parent,
477479
Self::StaticBlock(n) => n.parent,
478480
Self::ModuleDeclaration(n) => n.parent,
481+
Self::AccessorProperty(n) => n.parent,
479482
Self::ImportExpression(n) => n.parent,
480483
Self::ImportDeclaration(n) => n.parent,
481484
Self::ImportSpecifier(n) => n.parent,
@@ -661,6 +664,7 @@ impl<'a> AstNodes<'a> {
661664
Self::PrivateIdentifier(_) => "PrivateIdentifier",
662665
Self::StaticBlock(_) => "StaticBlock",
663666
Self::ModuleDeclaration(_) => "ModuleDeclaration",
667+
Self::AccessorProperty(_) => "AccessorProperty",
664668
Self::ImportExpression(_) => "ImportExpression",
665669
Self::ImportDeclaration(_) => "ImportDeclaration",
666670
Self::ImportSpecifier(_) => "ImportSpecifier",
@@ -3881,9 +3885,11 @@ impl<'a> AstNode<'a, ClassElement<'a>> {
38813885
}))
38823886
}
38833887
ClassElement::AccessorProperty(s) => {
3884-
panic!(
3885-
"No kind for current enum variant yet, please see `tasks/ast_tools/src/generators/ast_kind.rs`"
3886-
)
3888+
AstNodes::AccessorProperty(self.allocator.alloc(AstNode {
3889+
inner: s.as_ref(),
3890+
parent,
3891+
allocator: self.allocator,
3892+
}))
38873893
}
38883894
ClassElement::TSIndexSignature(s) => {
38893895
panic!(
@@ -4161,7 +4167,7 @@ impl<'a> AstNode<'a, AccessorProperty<'a>> {
41614167
self.allocator.alloc(AstNode {
41624168
inner: &self.inner.decorators,
41634169
allocator: self.allocator,
4164-
parent: self.parent,
4170+
parent: self.allocator.alloc(AstNodes::AccessorProperty(transmute_self(self))),
41654171
})
41664172
}
41674173

@@ -4170,7 +4176,7 @@ impl<'a> AstNode<'a, AccessorProperty<'a>> {
41704176
self.allocator.alloc(AstNode {
41714177
inner: &self.inner.key,
41724178
allocator: self.allocator,
4173-
parent: self.parent,
4179+
parent: self.allocator.alloc(AstNodes::AccessorProperty(transmute_self(self))),
41744180
})
41754181
}
41764182

@@ -4180,7 +4186,7 @@ impl<'a> AstNode<'a, AccessorProperty<'a>> {
41804186
.alloc(self.inner.type_annotation.as_ref().map(|inner| AstNode {
41814187
inner: inner.as_ref(),
41824188
allocator: self.allocator,
4183-
parent: self.parent,
4189+
parent: self.allocator.alloc(AstNodes::AccessorProperty(transmute_self(self))),
41844190
}))
41854191
.as_ref()
41864192
}
@@ -4191,7 +4197,7 @@ impl<'a> AstNode<'a, AccessorProperty<'a>> {
41914197
.alloc(self.inner.value.as_ref().map(|inner| AstNode {
41924198
inner,
41934199
allocator: self.allocator,
4194-
parent: self.parent,
4200+
parent: self.allocator.alloc(AstNodes::AccessorProperty(transmute_self(self))),
41954201
}))
41964202
.as_ref()
41974203
}

crates/oxc_formatter/src/generated/format.rs

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

995995
impl<'a> Format<'a> for AstNode<'a, AccessorProperty<'a>> {
996996
fn fmt(&self, f: &mut Formatter<'_, 'a>) -> FormatResult<()> {
997-
self.write(f)
997+
format_leading_comments(self.span().start).fmt(f)?;
998+
let result = self.write(f);
999+
format_trailing_comments(self.span().end).fmt(f)?;
1000+
result
9981001
}
9991002
}
10001003

tasks/ast_tools/src/generators/ast_kind.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const STRUCTS_BLACK_LIST: &[&str] = &[
3535
"AssignmentTargetPropertyProperty",
3636
"BindingPattern",
3737
"BindingProperty",
38-
"AccessorProperty",
3938
"ImportAttribute",
4039
"TSInterfaceBody",
4140
"TSIndexSignature",

0 commit comments

Comments
 (0)