[rust-compiler] Fix non-ASCII panic in is_ref_like_name

Merged
LA
1mo ago
+76-1

Summary

is_ref_like_name checked the first character with object_name[..1], which slices one byte. When a *Ref name starts with a multi-byte character like 한글Ref, that byte cuts into the character and the compiler panics on .current access. Reading the first char with .chars().next() fixes it, and those names now return false like the TS regex does.

Fixes #38023

How did you test this change?

Added repro-ref-like-name-non-ascii.js. It panicked before this change and compiles cleanly after:

bash scripts/test-rust-port.sh InferTypes packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-ref-like-name-non-ascii.js

yarn snap (1844 passed), yarn snap --rust (1844 passed), scripts/test-rust-port.sh (1843 passed) and cargo fmt --check are all green locally.