Skip to content

Commit 0cef370

Browse files
committed
refactor(ast): add AstKind::TemplateElement (#11955)
1 parent 114c4fb commit 0cef370

File tree

11 files changed

+211
-185
lines changed

11 files changed

+211
-185
lines changed

crates/oxc_ast/src/ast_kind_impl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ impl AstKind<'_> {
222222
t.quasi().map_or_else(|| "None".into(), |q| format!("Some({q})"))
223223
)
224224
.into(),
225+
Self::TemplateElement(_) => "TemplateElement".into(),
225226

226227
Self::MetaProperty(_) => "MetaProperty".into(),
227228
Self::Super(_) => "Super".into(),

crates/oxc_ast/src/generated/ast_kind.rs

Lines changed: 179 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -27,176 +27,177 @@ pub enum AstType {
2727
PropertyKey = 10,
2828
TemplateLiteral = 11,
2929
TaggedTemplateExpression = 12,
30-
ComputedMemberExpression = 13,
31-
StaticMemberExpression = 14,
32-
PrivateFieldExpression = 15,
33-
CallExpression = 16,
34-
NewExpression = 17,
35-
MetaProperty = 18,
36-
SpreadElement = 19,
37-
Argument = 20,
38-
UpdateExpression = 21,
39-
UnaryExpression = 22,
40-
BinaryExpression = 23,
41-
PrivateInExpression = 24,
42-
LogicalExpression = 25,
43-
ConditionalExpression = 26,
44-
AssignmentExpression = 27,
45-
AssignmentTarget = 28,
46-
SimpleAssignmentTarget = 29,
47-
AssignmentTargetPattern = 30,
48-
ArrayAssignmentTarget = 31,
49-
ObjectAssignmentTarget = 32,
50-
AssignmentTargetWithDefault = 33,
51-
SequenceExpression = 34,
52-
Super = 35,
53-
AwaitExpression = 36,
54-
ChainExpression = 37,
55-
ParenthesizedExpression = 38,
56-
Directive = 39,
57-
Hashbang = 40,
58-
BlockStatement = 41,
59-
VariableDeclaration = 42,
60-
VariableDeclarator = 43,
61-
EmptyStatement = 44,
62-
ExpressionStatement = 45,
63-
IfStatement = 46,
64-
DoWhileStatement = 47,
65-
WhileStatement = 48,
66-
ForStatement = 49,
67-
ForInStatement = 50,
68-
ForOfStatement = 51,
69-
ContinueStatement = 52,
70-
BreakStatement = 53,
71-
ReturnStatement = 54,
72-
WithStatement = 55,
73-
SwitchStatement = 56,
74-
SwitchCase = 57,
75-
LabeledStatement = 58,
76-
ThrowStatement = 59,
77-
TryStatement = 60,
78-
CatchClause = 61,
79-
CatchParameter = 62,
80-
DebuggerStatement = 63,
81-
AssignmentPattern = 64,
82-
ObjectPattern = 65,
83-
ArrayPattern = 66,
84-
BindingRestElement = 67,
85-
Function = 68,
86-
FormalParameters = 69,
87-
FormalParameter = 70,
88-
FunctionBody = 71,
89-
ArrowFunctionExpression = 72,
90-
YieldExpression = 73,
91-
Class = 74,
92-
ClassBody = 75,
93-
MethodDefinition = 76,
94-
PropertyDefinition = 77,
95-
PrivateIdentifier = 78,
96-
StaticBlock = 79,
97-
ModuleDeclaration = 80,
98-
AccessorProperty = 81,
99-
ImportExpression = 82,
100-
ImportDeclaration = 83,
101-
ImportSpecifier = 84,
102-
ImportDefaultSpecifier = 85,
103-
ImportNamespaceSpecifier = 86,
104-
WithClause = 87,
105-
ImportAttribute = 88,
106-
ExportNamedDeclaration = 89,
107-
ExportDefaultDeclaration = 90,
108-
ExportAllDeclaration = 91,
109-
ExportSpecifier = 92,
110-
V8IntrinsicExpression = 93,
111-
BooleanLiteral = 94,
112-
NullLiteral = 95,
113-
NumericLiteral = 96,
114-
StringLiteral = 97,
115-
BigIntLiteral = 98,
116-
RegExpLiteral = 99,
117-
JSXElement = 100,
118-
JSXOpeningElement = 101,
119-
JSXClosingElement = 102,
120-
JSXFragment = 103,
121-
JSXOpeningFragment = 104,
122-
JSXClosingFragment = 105,
123-
JSXNamespacedName = 106,
124-
JSXMemberExpression = 107,
125-
JSXExpressionContainer = 108,
126-
JSXEmptyExpression = 109,
127-
JSXAttribute = 110,
128-
JSXSpreadAttribute = 111,
129-
JSXIdentifier = 112,
130-
JSXSpreadChild = 113,
131-
JSXText = 114,
132-
TSThisParameter = 115,
133-
TSEnumDeclaration = 116,
134-
TSEnumBody = 117,
135-
TSEnumMember = 118,
136-
TSTypeAnnotation = 119,
137-
TSLiteralType = 120,
138-
TSConditionalType = 121,
139-
TSUnionType = 122,
140-
TSIntersectionType = 123,
141-
TSParenthesizedType = 124,
142-
TSTypeOperator = 125,
143-
TSArrayType = 126,
144-
TSIndexedAccessType = 127,
145-
TSTupleType = 128,
146-
TSNamedTupleMember = 129,
147-
TSOptionalType = 130,
148-
TSRestType = 131,
149-
TSAnyKeyword = 132,
150-
TSStringKeyword = 133,
151-
TSBooleanKeyword = 134,
152-
TSNumberKeyword = 135,
153-
TSNeverKeyword = 136,
154-
TSIntrinsicKeyword = 137,
155-
TSUnknownKeyword = 138,
156-
TSNullKeyword = 139,
157-
TSUndefinedKeyword = 140,
158-
TSVoidKeyword = 141,
159-
TSSymbolKeyword = 142,
160-
TSThisType = 143,
161-
TSObjectKeyword = 144,
162-
TSBigIntKeyword = 145,
163-
TSTypeReference = 146,
164-
TSTypeName = 147,
165-
TSQualifiedName = 148,
166-
TSTypeParameterInstantiation = 149,
167-
TSTypeParameter = 150,
168-
TSTypeParameterDeclaration = 151,
169-
TSTypeAliasDeclaration = 152,
170-
TSClassImplements = 153,
171-
TSInterfaceDeclaration = 154,
172-
TSPropertySignature = 155,
173-
TSCallSignatureDeclaration = 156,
174-
TSMethodSignature = 157,
175-
TSConstructSignatureDeclaration = 158,
176-
TSIndexSignatureName = 159,
177-
TSInterfaceHeritage = 160,
178-
TSTypePredicate = 161,
179-
TSModuleDeclaration = 162,
180-
TSModuleBlock = 163,
181-
TSTypeLiteral = 164,
182-
TSInferType = 165,
183-
TSTypeQuery = 166,
184-
TSImportType = 167,
185-
TSMappedType = 168,
186-
TSTemplateLiteralType = 169,
187-
TSAsExpression = 170,
188-
TSSatisfiesExpression = 171,
189-
TSTypeAssertion = 172,
190-
TSImportEqualsDeclaration = 173,
191-
TSExternalModuleReference = 174,
192-
TSNonNullExpression = 175,
193-
Decorator = 176,
194-
TSExportAssignment = 177,
195-
TSNamespaceExportDeclaration = 178,
196-
TSInstantiationExpression = 179,
197-
JSDocNullableType = 180,
198-
JSDocNonNullableType = 181,
199-
JSDocUnknownType = 182,
30+
TemplateElement = 13,
31+
ComputedMemberExpression = 14,
32+
StaticMemberExpression = 15,
33+
PrivateFieldExpression = 16,
34+
CallExpression = 17,
35+
NewExpression = 18,
36+
MetaProperty = 19,
37+
SpreadElement = 20,
38+
Argument = 21,
39+
UpdateExpression = 22,
40+
UnaryExpression = 23,
41+
BinaryExpression = 24,
42+
PrivateInExpression = 25,
43+
LogicalExpression = 26,
44+
ConditionalExpression = 27,
45+
AssignmentExpression = 28,
46+
AssignmentTarget = 29,
47+
SimpleAssignmentTarget = 30,
48+
AssignmentTargetPattern = 31,
49+
ArrayAssignmentTarget = 32,
50+
ObjectAssignmentTarget = 33,
51+
AssignmentTargetWithDefault = 34,
52+
SequenceExpression = 35,
53+
Super = 36,
54+
AwaitExpression = 37,
55+
ChainExpression = 38,
56+
ParenthesizedExpression = 39,
57+
Directive = 40,
58+
Hashbang = 41,
59+
BlockStatement = 42,
60+
VariableDeclaration = 43,
61+
VariableDeclarator = 44,
62+
EmptyStatement = 45,
63+
ExpressionStatement = 46,
64+
IfStatement = 47,
65+
DoWhileStatement = 48,
66+
WhileStatement = 49,
67+
ForStatement = 50,
68+
ForInStatement = 51,
69+
ForOfStatement = 52,
70+
ContinueStatement = 53,
71+
BreakStatement = 54,
72+
ReturnStatement = 55,
73+
WithStatement = 56,
74+
SwitchStatement = 57,
75+
SwitchCase = 58,
76+
LabeledStatement = 59,
77+
ThrowStatement = 60,
78+
TryStatement = 61,
79+
CatchClause = 62,
80+
CatchParameter = 63,
81+
DebuggerStatement = 64,
82+
AssignmentPattern = 65,
83+
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+
TSPropertySignature = 156,
174+
TSCallSignatureDeclaration = 157,
175+
TSMethodSignature = 158,
176+
TSConstructSignatureDeclaration = 159,
177+
TSIndexSignatureName = 160,
178+
TSInterfaceHeritage = 161,
179+
TSTypePredicate = 162,
180+
TSModuleDeclaration = 163,
181+
TSModuleBlock = 164,
182+
TSTypeLiteral = 165,
183+
TSInferType = 166,
184+
TSTypeQuery = 167,
185+
TSImportType = 168,
186+
TSMappedType = 169,
187+
TSTemplateLiteralType = 170,
188+
TSAsExpression = 171,
189+
TSSatisfiesExpression = 172,
190+
TSTypeAssertion = 173,
191+
TSImportEqualsDeclaration = 174,
192+
TSExternalModuleReference = 175,
193+
TSNonNullExpression = 176,
194+
Decorator = 177,
195+
TSExportAssignment = 178,
196+
TSNamespaceExportDeclaration = 179,
197+
TSInstantiationExpression = 180,
198+
JSDocNullableType = 181,
199+
JSDocNonNullableType = 182,
200+
JSDocUnknownType = 183,
200201
}
201202

202203
/// Untyped AST Node Kind
@@ -217,6 +218,7 @@ pub enum AstKind<'a> {
217218
TemplateLiteral(&'a TemplateLiteral<'a>) = AstType::TemplateLiteral as u8,
218219
TaggedTemplateExpression(&'a TaggedTemplateExpression<'a>) =
219220
AstType::TaggedTemplateExpression as u8,
221+
TemplateElement(&'a TemplateElement<'a>) = AstType::TemplateElement as u8,
220222
ComputedMemberExpression(&'a ComputedMemberExpression<'a>) =
221223
AstType::ComputedMemberExpression as u8,
222224
StaticMemberExpression(&'a StaticMemberExpression<'a>) = AstType::StaticMemberExpression as u8,
@@ -432,6 +434,7 @@ impl GetSpan for AstKind<'_> {
432434
Self::PropertyKey(it) => it.span(),
433435
Self::TemplateLiteral(it) => it.span(),
434436
Self::TaggedTemplateExpression(it) => it.span(),
437+
Self::TemplateElement(it) => it.span(),
435438
Self::ComputedMemberExpression(it) => it.span(),
436439
Self::StaticMemberExpression(it) => it.span(),
437440
Self::PrivateFieldExpression(it) => it.span(),
@@ -622,6 +625,7 @@ impl GetAddress for AstKind<'_> {
622625
Self::PropertyKey(it) => it.address(),
623626
Self::TemplateLiteral(it) => Address::from_ptr(it),
624627
Self::TaggedTemplateExpression(it) => Address::from_ptr(it),
628+
Self::TemplateElement(it) => Address::from_ptr(it),
625629
Self::ComputedMemberExpression(it) => Address::from_ptr(it),
626630
Self::StaticMemberExpression(it) => Address::from_ptr(it),
627631
Self::PrivateFieldExpression(it) => Address::from_ptr(it),
@@ -862,6 +866,11 @@ impl<'a> AstKind<'a> {
862866
if let Self::TaggedTemplateExpression(v) = self { Some(v) } else { None }
863867
}
864868

869+
#[inline]
870+
pub fn as_template_element(self) -> Option<&'a TemplateElement<'a>> {
871+
if let Self::TemplateElement(v) = self { Some(v) } else { None }
872+
}
873+
865874
#[inline]
866875
pub fn as_computed_member_expression(self) -> Option<&'a ComputedMemberExpression<'a>> {
867876
if let Self::ComputedMemberExpression(v) = self { Some(v) } else { None }

0 commit comments

Comments
 (0)