Commit f8be84a
committed
fix: correct UTF-16 index handling in native MagicString (#8693)
## Summary
- Fix `CharToByteMapper` to index by UTF-16 code unit position (matching JS string indices) instead of Rust char position, and accumulate UTF-8 byte offsets instead of UTF-16 lengths
- When `slice` indices fall mid-surrogate-pair, emit lone surrogates via `napi_create_string_utf16` to match original magic-string behavior exactly
- Add comprehensive unicode test suite covering emoji, CJK, mixed scripts, negative indices, and surrogate pair boundary slicing
Fixes #8685
## Test plan
- [x] New `magic-string-unicode.test.ts` covers emoji slice/overwrite/remove, CJK, mixed scripts, negative indices, and lone surrogate emission
- [x] All 157 existing magic-string tests continue to pass
- [x] Exact repro from issue (`slice` on `"some 🤷♂️ string"`) no longer panics
🤖 Generated with [Claude Code](https://claude.com/claude-code)1 parent 03e35b3 commit f8be84a
File tree
3 files changed
+277
-78
lines changed- crates/rolldown_binding/src/types
- packages/rolldown
- src
- tests/magic-string
3 files changed
+277
-78
lines changed
0 commit comments