Skip to content

Commit a316b10

Browse files
committed
refactor(ast): rename #[estree(type)] attr on types to #[estree(rename)] (#8766)
To rename a type in ESTree AST, use `#[estree(rename = "Identifier")]` instead of `#[estree(type = "Identifier")]`. This aligns with `serde`'s attribute, and avoids using the keyword `type`, which makes the attributes simpler to parse.
1 parent 8781537 commit a316b10

File tree

4 files changed

+15
-21
lines changed

4 files changed

+15
-21
lines changed

crates/oxc_ast/src/ast/js.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ pub use match_expression;
202202
#[ast(visit)]
203203
#[derive(Debug, Clone)]
204204
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
205-
#[estree(type = "Identifier")]
205+
#[estree(rename = "Identifier")]
206206
pub struct IdentifierName<'a> {
207207
pub span: Span,
208208
pub name: Atom<'a>,
@@ -216,7 +216,7 @@ pub struct IdentifierName<'a> {
216216
#[ast(visit)]
217217
#[derive(Debug, Clone)]
218218
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
219-
#[estree(type = "Identifier")]
219+
#[estree(rename = "Identifier")]
220220
pub struct IdentifierReference<'a> {
221221
pub span: Span,
222222
/// The name of the identifier being referenced.
@@ -239,7 +239,7 @@ pub struct IdentifierReference<'a> {
239239
#[ast(visit)]
240240
#[derive(Debug, Clone)]
241241
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
242-
#[estree(type = "Identifier")]
242+
#[estree(rename = "Identifier")]
243243
pub struct BindingIdentifier<'a> {
244244
pub span: Span,
245245
/// The identifier name being bound.
@@ -263,7 +263,7 @@ pub struct BindingIdentifier<'a> {
263263
#[ast(visit)]
264264
#[derive(Debug, Clone)]
265265
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
266-
#[estree(type = "Identifier")]
266+
#[estree(rename = "Identifier")]
267267
pub struct LabelIdentifier<'a> {
268268
pub span: Span,
269269
pub name: Atom<'a>,
@@ -832,7 +832,7 @@ pub struct ObjectAssignmentTarget<'a> {
832832
#[ast(visit)]
833833
#[derive(Debug)]
834834
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
835-
#[estree(type = "RestElement")]
835+
#[estree(rename = "RestElement")]
836836
pub struct AssignmentTargetRest<'a> {
837837
pub span: Span,
838838
#[estree(rename = "argument")]
@@ -1520,7 +1520,7 @@ pub struct ArrayPattern<'a> {
15201520
#[ast(visit)]
15211521
#[derive(Debug)]
15221522
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
1523-
#[estree(type = "RestElement")]
1523+
#[estree(rename = "RestElement")]
15241524
pub struct BindingRestElement<'a> {
15251525
pub span: Span,
15261526
pub argument: BindingPattern<'a>,

crates/oxc_ast/src/ast/literal.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use oxc_syntax::number::{BigintBase, NumberBase};
2020
#[ast(visit)]
2121
#[derive(Debug, Clone)]
2222
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
23-
#[estree(type = "Literal", via = crate::serialize::ESTreeLiteral, add_ts = "raw: string | null")]
23+
#[estree(rename = "Literal", via = crate::serialize::ESTreeLiteral, add_ts = "raw: string | null")]
2424
pub struct BooleanLiteral {
2525
/// Node location in source code
2626
pub span: Span,
@@ -34,7 +34,7 @@ pub struct BooleanLiteral {
3434
#[ast(visit)]
3535
#[derive(Debug, Clone)]
3636
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
37-
#[estree(type = "Literal", via = crate::serialize::ESTreeLiteral, add_ts = "value: null, raw: \"null\" | null")]
37+
#[estree(rename = "Literal", via = crate::serialize::ESTreeLiteral, add_ts = "value: null, raw: \"null\" | null")]
3838
pub struct NullLiteral {
3939
/// Node location in source code
4040
pub span: Span,
@@ -46,7 +46,7 @@ pub struct NullLiteral {
4646
#[ast(visit)]
4747
#[derive(Debug, Clone)]
4848
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ESTree)]
49-
#[estree(type = "Literal", via = crate::serialize::ESTreeLiteral)]
49+
#[estree(rename = "Literal", via = crate::serialize::ESTreeLiteral)]
5050
pub struct NumericLiteral<'a> {
5151
/// Node location in source code
5252
pub span: Span,
@@ -67,7 +67,7 @@ pub struct NumericLiteral<'a> {
6767
#[ast(visit)]
6868
#[derive(Debug, Clone)]
6969
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ESTree)]
70-
#[estree(type = "Literal", via = crate::serialize::ESTreeLiteral)]
70+
#[estree(rename = "Literal", via = crate::serialize::ESTreeLiteral)]
7171
pub struct StringLiteral<'a> {
7272
/// Node location in source code
7373
pub span: Span,
@@ -86,7 +86,7 @@ pub struct StringLiteral<'a> {
8686
#[ast(visit)]
8787
#[derive(Debug, Clone)]
8888
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ESTree)]
89-
#[estree(type = "Literal", via = crate::serialize::ESTreeLiteral, add_ts = "value: null, bigint: string")]
89+
#[estree(rename = "Literal", via = crate::serialize::ESTreeLiteral, add_ts = "value: null, bigint: string")]
9090
pub struct BigIntLiteral<'a> {
9191
/// Node location in source code
9292
pub span: Span,
@@ -105,7 +105,7 @@ pub struct BigIntLiteral<'a> {
105105
#[derive(Debug)]
106106
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ESTree)]
107107
#[estree(
108-
type = "Literal",
108+
rename = "Literal",
109109
via = crate::serialize::ESTreeLiteral,
110110
add_ts = "value: {} | null, regex: { pattern: string, flags: string }"
111111
)]

crates/oxc_ast/src/ast/ts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ pub struct TSConstructSignatureDeclaration<'a> {
10421042
#[ast(visit)]
10431043
#[derive(Debug)]
10441044
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
1045-
#[estree(type = "Identifier")]
1045+
#[estree(rename = "Identifier")]
10461046
pub struct TSIndexSignatureName<'a> {
10471047
pub span: Span,
10481048
pub name: Atom<'a>,

tasks/ast_tools/src/markers.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,7 @@ impl Parse for ESTreeStructAttribute {
119119
let mut add_ts = None;
120120

121121
loop {
122-
let is_type = input.peek(Token![type]);
123-
let ident = if is_type {
124-
input.parse::<Token![type]>()?;
125-
"type".to_string()
126-
} else {
127-
input.call(Ident::parse_any).unwrap().to_string()
128-
};
122+
let ident = input.call(Ident::parse_any).unwrap().to_string();
129123
match ident.as_str() {
130124
"always_flatten" => {
131125
if always_flatten {
@@ -146,7 +140,7 @@ impl Parse for ESTreeStructAttribute {
146140
"Duplicate tag mode in #[estree(...)]"
147141
);
148142
}
149-
"type" => {
143+
"rename" => {
150144
input.parse::<Token![=]>()?;
151145
let value = input.parse::<LitStr>()?.value();
152146
assert!(

0 commit comments

Comments
 (0)