From ddbe9354ee803c5839351a62bd375061c217ce72 Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Sat, 16 Nov 2024 14:26:11 +0000 Subject: [PATCH] fix(transformer/arrow-function): handle unicode when capitalizing property name --- .../src/common/arrow_function_converter.rs | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/crates/oxc_transformer/src/common/arrow_function_converter.rs b/crates/oxc_transformer/src/common/arrow_function_converter.rs index ef7391ab28c48a..3eb9ac3a9668eb 100644 --- a/crates/oxc_transformer/src/common/arrow_function_converter.rs +++ b/crates/oxc_transformer/src/common/arrow_function_converter.rs @@ -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()) }