mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
fix(ast): fix name of AstBuilder method for Expression::V8IntrinsicExpression (#23766)
`ast_tools` codegen handles of converting types names to snake case. It ensures that `V8IntrinsicExpression` is converted to `v8_intrinsic_expression` not `v_8_intrinsic_expression`. However, this special case was missed out when converting enum variant names. Fix this, which results in `AstBuilder::expression_v_8_intrinsic` being corrected to `expression_v8_intrinsic`.
This commit is contained in:
1 parent
a4676dba29
commit
7537c582e0
5 files changed
+32
-31
No files matched your search
@@ -1203,7 +1203,7 @@ impl<'a> AstBuilder<'a> {
|
||||
/// * `name`
|
||||
/// * `arguments`
|
||||
#[inline]
|
||||
pub fn expression_v_8_intrinsic(
|
||||
pub fn expression_v8_intrinsic(
|
||||
self,
|
||||
span: Span,
|
||||
name: IdentifierName<'a>,
|
||||
|
||||
@@ -699,7 +699,7 @@ impl<'a, C: Config> ParserImpl<'a, C> {
|
||||
)
|
||||
});
|
||||
self.expect(Kind::RParen);
|
||||
self.ast.expression_v_8_intrinsic(self.end_span(span), name, arguments)
|
||||
self.ast.expression_v8_intrinsic(self.end_span(span), name, arguments)
|
||||
}
|
||||
|
||||
fn parse_v8_intrinsic_argument(&mut self) -> Argument<'a> {
|
||||
|
||||
@@ -5,7 +5,7 @@ use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::Ident;
|
||||
|
||||
use crate::utils::{create_ident, pluralize};
|
||||
use crate::utils::{create_ident, pluralize, snake_case};
|
||||
|
||||
use super::{
|
||||
Containers, Def, Derives, File, FileId, Schema, TypeDef, TypeId, Visibility,
|
||||
@@ -201,7 +201,7 @@ impl VariantDef {
|
||||
|
||||
/// Get variant name in snake case.
|
||||
pub fn snake_name(&self) -> String {
|
||||
self.name().to_case(Case::Snake)
|
||||
snake_case(self.name())
|
||||
}
|
||||
|
||||
/// Get variant name in camel case.
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use convert_case::{Case, Casing};
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::Ident;
|
||||
@@ -6,7 +5,7 @@ use syn::Ident;
|
||||
use crate::{
|
||||
codegen::DeriveId,
|
||||
schema::{File, Schema},
|
||||
utils::create_ident,
|
||||
utils::{create_ident, snake_case},
|
||||
};
|
||||
|
||||
use super::{Derives, FileId, TypeId, extensions};
|
||||
@@ -50,11 +49,8 @@ pub trait Def {
|
||||
fn has_lifetime(&self, schema: &Schema) -> bool;
|
||||
|
||||
/// Get type name in snake case.
|
||||
///
|
||||
/// `convert_case` splits `V8` into `v` + `8`, producing `v_8_intrinsic_expression`.
|
||||
/// We fix this to `v8_intrinsic_expression` to match the conventional naming.
|
||||
fn snake_name(&self) -> String {
|
||||
fix_snake_case(&self.name().to_case(Case::Snake))
|
||||
snake_case(self.name())
|
||||
}
|
||||
|
||||
/// Get type name as an [`Ident`].
|
||||
@@ -120,27 +116,6 @@ pub trait Def {
|
||||
}
|
||||
}
|
||||
|
||||
/// Fix `convert_case`'s snake_case output which inserts underscores between letters and digits.
|
||||
///
|
||||
/// e.g. `v_8_intrinsic_expression` -> `v8_intrinsic_expression`.
|
||||
fn fix_snake_case(s: &str) -> String {
|
||||
let bytes = s.as_bytes();
|
||||
let mut result = String::with_capacity(s.len());
|
||||
for (i, &byte) in bytes.iter().enumerate() {
|
||||
// Skip underscores between a letter and a digit
|
||||
if byte == b'_'
|
||||
&& i > 0
|
||||
&& i + 1 < bytes.len()
|
||||
&& bytes[i - 1].is_ascii_alphabetic()
|
||||
&& bytes[i + 1].is_ascii_digit()
|
||||
{
|
||||
continue;
|
||||
}
|
||||
result.push(byte as char);
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
/// IDs of container types containing a type.
|
||||
///
|
||||
/// e.g. If `Option<Expression>` exists in AST, `Containers::option_id` for `Expression` type def
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use convert_case::{Case, Casing};
|
||||
use indexmap::{IndexMap, IndexSet};
|
||||
use phf::{Set as PhfSet, phf_set};
|
||||
use proc_macro2::{Span, TokenStream};
|
||||
@@ -104,6 +105,31 @@ pub fn upper_case_first(s: &str) -> Cow<'_, str> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert type name to snake case.
|
||||
///
|
||||
/// e.g. `ExpressionStatement` -> `expression_statement`.
|
||||
///
|
||||
/// Fixup `convert_case`'s output which inserts underscores between letters and digits.
|
||||
/// e.g. `v_8_intrinsic_expression` -> `v8_intrinsic_expression`.
|
||||
pub fn snake_case(s: &str) -> String {
|
||||
let s = s.to_case(Case::Snake);
|
||||
let bytes = s.as_bytes();
|
||||
let mut result = String::with_capacity(s.len());
|
||||
for (i, &byte) in bytes.iter().enumerate() {
|
||||
// Skip underscores between a letter and a digit
|
||||
if byte == b'_'
|
||||
&& i > 0
|
||||
&& i + 1 < bytes.len()
|
||||
&& bytes[i - 1].is_ascii_alphabetic()
|
||||
&& bytes[i + 1].is_ascii_digit()
|
||||
{
|
||||
continue;
|
||||
}
|
||||
result.push(byte as char);
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
/// Macro to `format!` arguments, and wrap the formatted string in a `Cow::Owned`.
|
||||
macro_rules! format_cow {
|
||||
($($tokens:tt)+) => {
|
||||
|
||||
Reference in new issue
Block a user