mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 04:42:10 +00:00
fix(transformer/arrow-function): handle unicode when capitalizing property name (#7311)
Previously was assuming property name starts with an ASCII character. If it started with a multi-byte unicode char, `&property[1..]` would panic.
This commit is contained in:
parent
5cfe0b623e
commit
389b84e4ff
1 changed files with 14 additions and 6 deletions
|
|
@ -812,13 +812,21 @@ impl<'a> ArrowFunctionConverter<'a> {
|
||||||
name.push_str("get");
|
name.push_str("get");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Capitalize the first letter of the property name.
|
// Capitalize the first letter of the property name
|
||||||
if let Some(first_byte) = property.as_bytes().first() {
|
if let Some(&first_byte) = property.as_bytes().first() {
|
||||||
name.push(first_byte.to_ascii_uppercase() as char);
|
if first_byte.is_ascii() {
|
||||||
}
|
name.push(first_byte.to_ascii_uppercase() as char);
|
||||||
if property.len() > 1 {
|
if property.len() > 1 {
|
||||||
name.push_str(&property[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())
|
ctx.ast.atom(name.into_bump_str())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue