Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
/// <https://tc39.es/ecma262/#prod-FormalParameters>
FormalParameter = 0,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions crates/oxc_ast/src/ast/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 0 additions & 5 deletions crates/oxc_regular_expression/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions crates/oxc_span/src/source_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down
5 changes: 0 additions & 5 deletions crates/oxc_syntax/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "=")]
Expand Down Expand Up @@ -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 = "==")]
Expand Down Expand Up @@ -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 = "||")]
Expand Down Expand Up @@ -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 = "-")]
Expand Down Expand Up @@ -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 = "++")]
Expand Down
20 changes: 10 additions & 10 deletions tasks/ast_tools/src/markers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,32 +124,32 @@ 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<String>,
pub no_rename_variants: bool,
pub custom_ts_def: bool,
}

impl Parse for ESTreeEnumAttribute {
fn parse(input: ParseStream) -> Result<Self, syn::Error> {
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::<Token![=]>()?;
assert!(
rename_all.replace(input.parse::<LitStr>()?.value()).is_none(),
"Duplicate estree(rename_all)"
);
}
"custom_ts_def" => {
if custom_ts_def {
panic!("Duplicate estree(custom_ts_def)");
} else {
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![,]);
Expand All @@ -159,7 +159,7 @@ impl Parse for ESTreeEnumAttribute {
break;
}
}
Ok(Self { rename_all, custom_ts_def })
Ok(Self { no_rename_variants, custom_ts_def })
}
}

Expand Down
12 changes: 6 additions & 6 deletions tasks/ast_tools/src/schema/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
}
}
}

Expand Down