Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(transformer/arrow-function): handle unicode when capitalizing property name #7311

Merged
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
20 changes: 14 additions & 6 deletions crates/oxc_transformer/src/common/arrow_function_converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,13 +812,21 @@ impl<'a> ArrowFunctionConverter<'a> {
name.push_str("get");
}

// Capitalize the first letter of the property name.
if let Some(first_byte) = property.as_bytes().first() {
name.push(first_byte.to_ascii_uppercase() as char);
}
if property.len() > 1 {
name.push_str(&property[1..]);
// Capitalize the first letter of the property name
if let Some(&first_byte) = property.as_bytes().first() {
if first_byte.is_ascii() {
name.push(first_byte.to_ascii_uppercase() as char);
if property.len() > 1 {
name.push_str(&property[1..]);
}
} else {
let mut chars = property.chars();
let first_char = chars.next().unwrap();
name.extend(first_char.to_uppercase());
name.push_str(chars.as_str());
}
}

ctx.ast.atom(name.into_bump_str())
}

Expand Down
Loading