Skip to content

Commit a1cf307

Browse files
committed
refactor(ast): add AstKind for BindingProperty
1 parent 8e45e28 commit a1cf307

File tree

18 files changed

+179
-146
lines changed

18 files changed

+179
-146
lines changed

crates/oxc_ast/src/ast_kind_impl.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ impl AstKind<'_> {
229229

230230
Self::AccessorProperty(_) => "AccessorProperty".into(),
231231

232+
Self::BindingProperty(_) => "BindingProperty".into(),
233+
232234
Self::ArrayExpression(_) => "ArrayExpression".into(),
233235
Self::ArrowFunctionExpression(_) => "ArrowFunctionExpression".into(),
234236
Self::AssignmentExpression(_) => "AssignmentExpression".into(),

crates/oxc_ast/src/generated/ast_kind.rs

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

206207
/// Untyped AST Node Kind
@@ -279,6 +280,7 @@ pub enum AstKind<'a> {
279280
DebuggerStatement(&'a DebuggerStatement) = AstType::DebuggerStatement as u8,
280281
AssignmentPattern(&'a AssignmentPattern<'a>) = AstType::AssignmentPattern as u8,
281282
ObjectPattern(&'a ObjectPattern<'a>) = AstType::ObjectPattern as u8,
283+
BindingProperty(&'a BindingProperty<'a>) = AstType::BindingProperty as u8,
282284
ArrayPattern(&'a ArrayPattern<'a>) = AstType::ArrayPattern as u8,
283285
BindingRestElement(&'a BindingRestElement<'a>) = AstType::BindingRestElement as u8,
284286
Function(&'a Function<'a>) = AstType::Function as u8,
@@ -494,6 +496,7 @@ impl GetSpan for AstKind<'_> {
494496
Self::DebuggerStatement(it) => it.span(),
495497
Self::AssignmentPattern(it) => it.span(),
496498
Self::ObjectPattern(it) => it.span(),
499+
Self::BindingProperty(it) => it.span(),
497500
Self::ArrayPattern(it) => it.span(),
498501
Self::BindingRestElement(it) => it.span(),
499502
Self::Function(it) => it.span(),
@@ -688,6 +691,7 @@ impl GetAddress for AstKind<'_> {
688691
Self::DebuggerStatement(it) => Address::from_ptr(it),
689692
Self::AssignmentPattern(it) => Address::from_ptr(it),
690693
Self::ObjectPattern(it) => Address::from_ptr(it),
694+
Self::BindingProperty(it) => Address::from_ptr(it),
691695
Self::ArrayPattern(it) => Address::from_ptr(it),
692696
Self::BindingRestElement(it) => Address::from_ptr(it),
693697
Self::Function(it) => Address::from_ptr(it),
@@ -1148,6 +1152,11 @@ impl<'a> AstKind<'a> {
11481152
if let Self::ObjectPattern(v) = self { Some(v) } else { None }
11491153
}
11501154

1155+
#[inline]
1156+
pub fn as_binding_property(self) -> Option<&'a BindingProperty<'a>> {
1157+
if let Self::BindingProperty(v) = self { Some(v) } else { None }
1158+
}
1159+
11511160
#[inline]
11521161
pub fn as_array_pattern(self) -> Option<&'a ArrayPattern<'a>> {
11531162
if let Self::ArrayPattern(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
@@ -2388,10 +2388,12 @@ pub mod walk {
23882388

23892389
#[inline]
23902390
pub fn walk_binding_property<'a, V: Visit<'a>>(visitor: &mut V, it: &BindingProperty<'a>) {
2391-
// No `AstKind` for this type
2391+
let kind = AstKind::BindingProperty(visitor.alloc(it));
2392+
visitor.enter_node(kind);
23922393
visitor.visit_span(&it.span);
23932394
visitor.visit_property_key(&it.key);
23942395
visitor.visit_binding_pattern(&it.value);
2396+
visitor.leave_node(kind);
23952397
}
23962398

23972399
#[inline]

crates/oxc_ast_visit/src/generated/visit_mut.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2461,10 +2461,12 @@ pub mod walk_mut {
24612461
visitor: &mut V,
24622462
it: &mut BindingProperty<'a>,
24632463
) {
2464-
// No `AstType` for this type
2464+
let kind = AstType::BindingProperty;
2465+
visitor.enter_node(kind);
24652466
visitor.visit_span(&mut it.span);
24662467
visitor.visit_property_key(&mut it.key);
24672468
visitor.visit_binding_pattern(&mut it.value);
2469+
visitor.leave_node(kind);
24682470
}
24692471

24702472
#[inline]

crates/oxc_formatter/src/generated/ast_nodes.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ pub enum AstNodes<'a> {
9494
DebuggerStatement(&'a AstNode<'a, DebuggerStatement>),
9595
AssignmentPattern(&'a AstNode<'a, AssignmentPattern<'a>>),
9696
ObjectPattern(&'a AstNode<'a, ObjectPattern<'a>>),
97+
BindingProperty(&'a AstNode<'a, BindingProperty<'a>>),
9798
ArrayPattern(&'a AstNode<'a, ArrayPattern<'a>>),
9899
BindingRestElement(&'a AstNode<'a, BindingRestElement<'a>>),
99100
Function(&'a AstNode<'a, Function<'a>>),
@@ -2381,6 +2382,7 @@ impl<'a> AstNodes<'a> {
23812382
Self::DebuggerStatement(n) => n.span(),
23822383
Self::AssignmentPattern(n) => n.span(),
23832384
Self::ObjectPattern(n) => n.span(),
2385+
Self::BindingProperty(n) => n.span(),
23842386
Self::ArrayPattern(n) => n.span(),
23852387
Self::BindingRestElement(n) => n.span(),
23862388
Self::Function(n) => n.span(),
@@ -2574,6 +2576,7 @@ impl<'a> AstNodes<'a> {
25742576
Self::DebuggerStatement(n) => n.parent,
25752577
Self::AssignmentPattern(n) => n.parent,
25762578
Self::ObjectPattern(n) => n.parent,
2579+
Self::BindingProperty(n) => n.parent,
25772580
Self::ArrayPattern(n) => n.parent,
25782581
Self::BindingRestElement(n) => n.parent,
25792582
Self::Function(n) => n.parent,
@@ -2767,6 +2770,7 @@ impl<'a> AstNodes<'a> {
27672770
Self::DebuggerStatement(n) => SiblingNode::from(n.inner),
27682771
Self::AssignmentPattern(n) => SiblingNode::from(n.inner),
27692772
Self::ObjectPattern(n) => SiblingNode::from(n.inner),
2773+
Self::BindingProperty(n) => SiblingNode::from(n.inner),
27702774
Self::ArrayPattern(n) => SiblingNode::from(n.inner),
27712775
Self::BindingRestElement(n) => SiblingNode::from(n.inner),
27722776
Self::Function(n) => SiblingNode::from(n.inner),
@@ -2960,6 +2964,7 @@ impl<'a> AstNodes<'a> {
29602964
Self::DebuggerStatement(_) => "DebuggerStatement",
29612965
Self::AssignmentPattern(_) => "AssignmentPattern",
29622966
Self::ObjectPattern(_) => "ObjectPattern",
2967+
Self::BindingProperty(_) => "BindingProperty",
29632968
Self::ArrayPattern(_) => "ArrayPattern",
29642969
Self::BindingRestElement(_) => "BindingRestElement",
29652970
Self::Function(_) => "Function",
@@ -6177,7 +6182,7 @@ impl<'a> AstNode<'a, BindingProperty<'a>> {
61776182
self.allocator.alloc(AstNode {
61786183
inner: &self.inner.key,
61796184
allocator: self.allocator,
6180-
parent: self.parent,
6185+
parent: self.allocator.alloc(AstNodes::BindingProperty(transmute_self(self))),
61816186
following_node,
61826187
})
61836188
}
@@ -6188,7 +6193,7 @@ impl<'a> AstNode<'a, BindingProperty<'a>> {
61886193
self.allocator.alloc(AstNode {
61896194
inner: &self.inner.value,
61906195
allocator: self.allocator,
6191-
parent: self.parent,
6196+
parent: self.allocator.alloc(AstNodes::BindingProperty(transmute_self(self))),
61926197
following_node,
61936198
})
61946199
}

crates/oxc_formatter/src/generated/format.rs

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

11521152
impl<'a> Format<'a> for AstNode<'a, BindingProperty<'a>> {
11531153
fn fmt(&self, f: &mut Formatter<'_, 'a>) -> FormatResult<()> {
1154-
self.write(f)
1154+
format_leading_comments(self.span).fmt(f)?;
1155+
let result = self.write(f);
1156+
format_trailing_comments(
1157+
&self.parent.as_sibling_node(),
1158+
&SiblingNode::from(self.inner),
1159+
self.following_node.as_ref(),
1160+
)
1161+
.fmt(f)?;
1162+
result
11551163
}
11561164
}
11571165

0 commit comments

Comments
 (0)