diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs index 9adff58d4b809..7853d64cf0ffe 100644 --- a/crates/oxc_ast/src/ast/js.rs +++ b/crates/oxc_ast/src/ast/js.rs @@ -403,7 +403,6 @@ pub enum PropertyKey<'a> { #[ast] #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)] -#[estree(rename_all = "camelCase")] pub enum PropertyKind { /// `a: 1` in `const obj = { a: 1 };` Init = 0, @@ -1136,7 +1135,6 @@ pub struct VariableDeclaration<'a> { #[ast] #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)] -#[estree(rename_all = "camelCase")] pub enum VariableDeclarationKind { Var = 0, Const = 1, @@ -1696,6 +1694,7 @@ pub struct Function<'a> { #[ast] #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)] +#[estree(no_rename_variants)] pub enum FunctionType { FunctionDeclaration = 0, FunctionExpression = 1, @@ -1736,6 +1735,7 @@ pub struct FormalParameter<'a> { #[ast] #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)] +#[estree(no_rename_variants)] pub enum FormalParameterKind { /// FormalParameter = 0, @@ -1868,6 +1868,7 @@ pub struct Class<'a> { #[ast] #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)] +#[estree(no_rename_variants)] pub enum ClassType { /// Class declaration statement /// ```ts @@ -1961,6 +1962,7 @@ pub struct MethodDefinition<'a> { #[ast] #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)] +#[estree(no_rename_variants)] pub enum MethodDefinitionType { MethodDefinition = 0, TSAbstractMethodDefinition = 1, @@ -2049,6 +2051,7 @@ pub struct PropertyDefinition<'a> { #[ast] #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)] +#[estree(no_rename_variants)] pub enum PropertyDefinitionType { PropertyDefinition = 0, TSAbstractPropertyDefinition = 1, @@ -2057,7 +2060,6 @@ pub enum PropertyDefinitionType { #[ast] #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)] -#[estree(rename_all = "camelCase")] pub enum MethodDefinitionKind { /// Class constructor Constructor = 0, @@ -2168,6 +2170,7 @@ pub use match_module_declaration; #[ast] #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)] +#[estree(no_rename_variants)] pub enum AccessorPropertyType { AccessorProperty = 0, TSAbstractAccessorProperty = 1, diff --git a/crates/oxc_ast/src/ast/ts.rs b/crates/oxc_ast/src/ast/ts.rs index 48575af57d77e..afc25197a1770 100644 --- a/crates/oxc_ast/src/ast/ts.rs +++ b/crates/oxc_ast/src/ast/ts.rs @@ -409,7 +409,6 @@ pub struct TSTypeOperator<'a> { #[ast] #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)] -#[estree(rename_all = "camelCase")] pub enum TSTypeOperatorOperator { Keyof = 0, Unique = 1, @@ -893,7 +892,6 @@ pub struct TSTypeAliasDeclaration<'a> { #[ast] #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)] -#[estree(rename_all = "camelCase")] pub enum TSAccessibility { Private = 0, Protected = 1, @@ -1043,7 +1041,6 @@ pub struct TSCallSignatureDeclaration<'a> { #[ast] #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)] -#[estree(rename_all = "camelCase")] pub enum TSMethodSignatureKind { Method = 0, Get = 1, @@ -1229,7 +1226,6 @@ pub struct TSModuleDeclaration<'a> { #[ast] #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)] -#[estree(rename_all = "camelCase")] pub enum TSModuleDeclarationKind { /// `declare global {}` Global = 0, @@ -1511,7 +1507,6 @@ pub struct TSMappedType<'a> { #[ast] #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)] -#[estree(rename_all = "camelCase")] pub enum TSMappedTypeModifierOperator { /// e.g. `?` in `{ [P in K]?: T }` True = 0, @@ -1708,7 +1703,6 @@ pub struct TSInstantiationExpression<'a> { #[ast] #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)] -#[estree(rename_all = "camelCase")] pub enum ImportOrExportKind { /// `import { foo } from './foo'`; Value = 0, diff --git a/crates/oxc_regular_expression/src/ast.rs b/crates/oxc_regular_expression/src/ast.rs index 2607a1d321777..ec0daa3d6dc52 100644 --- a/crates/oxc_regular_expression/src/ast.rs +++ b/crates/oxc_regular_expression/src/ast.rs @@ -88,7 +88,6 @@ pub struct BoundaryAssertion { #[ast] #[derive(Debug, Clone, PartialEq)] #[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)] -#[estree(rename_all = "camelCase")] pub enum BoundaryAssertionKind { Start = 0, End = 1, @@ -111,7 +110,6 @@ pub struct LookAroundAssertion<'a> { #[ast] #[derive(Debug, Clone, PartialEq)] #[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)] -#[estree(rename_all = "camelCase")] pub enum LookAroundAssertionKind { Lookahead = 0, NegativeLookahead = 1, @@ -150,7 +148,6 @@ pub struct Character { #[ast] #[derive(Debug, Clone, Copy, PartialEq)] #[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)] -#[estree(rename_all = "camelCase")] pub enum CharacterKind { ControlLetter = 0, HexadecimalEscape = 1, @@ -179,7 +176,6 @@ pub struct CharacterClassEscape { #[ast] #[derive(Debug, Clone, Copy, PartialEq)] #[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)] -#[estree(rename_all = "camelCase")] pub enum CharacterClassEscapeKind { D = 0, NegativeD = 1, @@ -233,7 +229,6 @@ pub struct CharacterClass<'a> { #[ast] #[derive(Debug, PartialEq)] #[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)] -#[estree(rename_all = "camelCase")] pub enum CharacterClassContentsKind { Union = 0, /// `UnicodeSetsMode` only. diff --git a/crates/oxc_span/src/source_type/mod.rs b/crates/oxc_span/src/source_type/mod.rs index 76049d02f70b2..c8d9f1e3b1f12 100644 --- a/crates/oxc_span/src/source_type/mod.rs +++ b/crates/oxc_span/src/source_type/mod.rs @@ -45,7 +45,6 @@ pub enum Language { #[ast] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[generate_derive(ESTree)] -#[estree(rename_all = "camelCase")] pub enum ModuleKind { /// Regular JS script or CommonJS file Script = 0, @@ -66,7 +65,6 @@ pub enum ModuleKind { #[ast] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[generate_derive(ESTree)] -#[estree(rename_all = "camelCase")] pub enum LanguageVariant { /// Standard JavaScript or TypeScript without any language extensions. Stage /// 3 proposals do not count as language extensions. diff --git a/crates/oxc_syntax/src/operator.rs b/crates/oxc_syntax/src/operator.rs index 7a47493eadbdc..9ccd9bab53156 100644 --- a/crates/oxc_syntax/src/operator.rs +++ b/crates/oxc_syntax/src/operator.rs @@ -18,7 +18,6 @@ use crate::precedence::{GetPrecedence, Precedence}; #[ast] #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)] -#[estree(rename_all = "camelCase")] pub enum AssignmentOperator { /// `=` #[estree(rename = "=")] @@ -125,7 +124,6 @@ impl AssignmentOperator { #[ast] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)] -#[estree(rename_all = "camelCase")] pub enum BinaryOperator { /// `==` #[estree(rename = "==")] @@ -356,7 +354,6 @@ impl GetPrecedence for BinaryOperator { #[ast] #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)] -#[estree(rename_all = "camelCase")] pub enum LogicalOperator { /// `||` #[estree(rename = "||")] @@ -410,7 +407,6 @@ impl GetPrecedence for LogicalOperator { #[ast] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)] -#[estree(rename_all = "camelCase")] pub enum UnaryOperator { /// `-` #[estree(rename = "-")] @@ -481,7 +477,6 @@ impl UnaryOperator { #[ast] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)] -#[estree(rename_all = "camelCase")] pub enum UpdateOperator { /// `++` #[estree(rename = "++")] diff --git a/tasks/ast_tools/src/markers.rs b/tasks/ast_tools/src/markers.rs index 74c0e71258910..6a58085a45733 100644 --- a/tasks/ast_tools/src/markers.rs +++ b/tasks/ast_tools/src/markers.rs @@ -124,25 +124,18 @@ impl Parse for ESTreeStructAttribute { /// A struct representing the `#[estree(...)]` attributes that we implement for enums. #[derive(Debug, Serialize, Default)] pub struct ESTreeEnumAttribute { - pub rename_all: Option, + pub no_rename_variants: bool, pub custom_ts_def: bool, } impl Parse for ESTreeEnumAttribute { fn parse(input: ParseStream) -> Result { - let mut rename_all = None; + let mut no_rename_variants = false; let mut custom_ts_def = false; loop { let ident = input.call(Ident::parse_any).unwrap().to_string(); match ident.as_str() { - "rename_all" => { - input.parse::()?; - assert!( - rename_all.replace(input.parse::()?.value()).is_none(), - "Duplicate estree(rename_all)" - ); - } "custom_ts_def" => { if custom_ts_def { panic!("Duplicate estree(custom_ts_def)"); @@ -150,6 +143,13 @@ impl Parse for ESTreeEnumAttribute { custom_ts_def = true; } } + "no_rename_variants" => { + if no_rename_variants { + panic!("Duplicate estree(no_rename_variants)"); + } else { + no_rename_variants = true; + } + } arg => panic!("Unsupported #[estree(...)] argument: {arg}"), } let comma = input.peek(Token![,]); @@ -159,7 +159,7 @@ impl Parse for ESTreeEnumAttribute { break; } } - Ok(Self { rename_all, custom_ts_def }) + Ok(Self { no_rename_variants, custom_ts_def }) } } diff --git a/tasks/ast_tools/src/schema/serialize.rs b/tasks/ast_tools/src/schema/serialize.rs index 3386d75318d5e..332f21c8742e7 100644 --- a/tasks/ast_tools/src/schema/serialize.rs +++ b/tasks/ast_tools/src/schema/serialize.rs @@ -7,13 +7,13 @@ use super::{EnumDef, StructDef, VariantDef}; pub fn enum_variant_name(var: &VariantDef, enm: &EnumDef) -> String { match var.markers.derive_attributes.estree.rename.as_ref() { Some(rename) => rename.to_string(), - None => match enm.markers.estree.rename_all.as_deref() { - Some("camelCase") => var.ident().to_string().to_case(Case::Camel), - Some(case) => { - panic!("Unsupported rename_all: {case} (on {})", enm.ident()) + None => { + if enm.markers.estree.no_rename_variants { + var.ident().to_string() + } else { + var.ident().to_string().to_case(Case::Camel) } - None => var.ident().to_string(), - }, + } } }