Repository navigation
fix(magic-string): return UTF-16 code units from length() - #10295
Conversation
How to use the Graphite Merge QueueAdd the label graphite: merge-when-ready to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
✅ Deploy Preview for rolldown-rs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Merging this PR will not alter performance
Comparing Footnotes
|
9478f65 to
ed4dc95
Compare
ed4dc95 to
1ddc91a
Compare
Merge activity
|
1ddc91a to
1134d65
Compare
### What this solves
`RolldownMagicString.length()` returns the UTF-8 **byte** count instead of the UTF-16 code unit count that JavaScript — and `magic-string` — report. Any non-ASCII source over-reports:
| input | `length()` before | `magic-string` |
| --- | --- | --- |
| `"abc"` | 3 | 3 |
| `"é"` | **2** | 1 |
| `"🤷"` | **4** | 2 |
| `"中文"` | **6** | 2 |
| `"abc™def"` | **9** | 7 |
There is no panic and no warning — just a silently wrong number, so a plugin doing arithmetic on `length()` (bounds checks, slicing decisions) quietly misbehaves on any file containing an accented character, CJK text, or an emoji.
### Root cause
`MagicString::len()` sums `&str::len()` over the chunk fragments, which is UTF-8 bytes. The binding returned it unconverted:
```rust
pub fn length(&self) -> u32 {
self.inner.len() as u32
}
```
`length()` was the only index-based method that skipped the `Utf16ToByteMapper` the binding already builds for every other position API (`appendLeft`, `overwrite`, `slice`, …), so the UTF-16 boundary was handled everywhere except here.
### The fix
Add `MagicString::len_utf16`, covering exactly the same span as `len` — chunk content only, global `prepend`/`append` intro/outro excluded, matching `magic-string`'s `length()` — and use it from the binding. `len()` keeps its byte semantics for Rust callers and now documents that explicitly.
### Why this wasn't caught
The vendored upstream conformance suite (`packages/rolldown/tests/magic-string/MagicString.test.ts`) exercises `length` only with ASCII, where bytes and code units coincide. The new tests live next to the other hand-written binding cases in `rolldown-magic-string.test.ts`, which is where the UTF-16↔UTF-8 boundary coverage already sits.
### Tests
Three cases in `packages/rolldown/tests/magic-string/rolldown-magic-string.test.ts`: the non-ASCII table above, `length()` after an edit that inserts a surrogate pair (asserted against `toString().length`), and a guard that the global intro/outro stays excluded. All three fail on `main` and pass here.
---
### Follow-up: positional inserts at index 0 on an empty source (thanks @hyfdev)
A second, pre-existing hole in `length()`, found in review:
```js
const s = new RolldownMagicString('');
s.appendLeft(0, 'é');
s.toString(); // 'é'
s.length(); // was 0; magic-string returns 1
s.isEmpty(); // was true; magic-string returns false
```
All four positional methods reproduced it (an emoji returned `0` instead of `2`), and it hit `isEmpty()` as well.
**Cause.** `by_start_mut` and `by_end_mut` short-circuited *before* consulting the chunk maps:
```rust
fn by_start_mut(...) { if text_index as usize == self.source.len() { Ok(None) } ... }
fn by_end_mut(...) { if text_index == 0 { Ok(None) } ... }
```
Those approximate "no chunk at this index", which is true for a non-empty source — nothing ends at 0, nothing starts at `len`. But an empty source's sole `[0, 0)` chunk both starts *and* ends at 0, and the constructor registers it under `chunk_by_start[0]` *and* `chunk_by_end[0]`. The guard fired first, so the content went to the global intro/outro, where `length()` cannot see it. `magic-string` has no such special case — it does a plain `byStart[index]` / `byEnd[index]` lookup.
**Fix.** Delete both short-circuits and let the map answer. That is correct for both cases: on `'abc'`, `chunk_by_end.get(0)` returns `None` anyway.
**Tests.** Eight more cases. Five fail without this change (the four positional methods, plus the emoji UTF-16 case). The other three are the contrast @hyfdev asked for — `append`/`prepend` stay excluded, and non-empty out-of-range inserts stay excluded. Those three pass either way by design: the tempting alternative fix is to make `len_utf16()` count the global intro/outro, which would satisfy all five failing tests while breaking exactly these three.
Verified against `[email protected]`: **0 divergences** across all 11 probed cases (`toString`, `length`, `isEmpty`), down from 5. The 199-test upstream conformance suite still passes.
1134d65 to
cbef0b2
Compare
cbef0b2 to
59806ff
Compare
### What this solves
`RolldownMagicString.length()` returns the UTF-8 **byte** count instead of the UTF-16 code unit count that JavaScript — and `magic-string` — report. Any non-ASCII source over-reports:
| input | `length()` before | `magic-string` |
| --- | --- | --- |
| `"abc"` | 3 | 3 |
| `"é"` | **2** | 1 |
| `"🤷"` | **4** | 2 |
| `"中文"` | **6** | 2 |
| `"abc™def"` | **9** | 7 |
There is no panic and no warning — just a silently wrong number, so a plugin doing arithmetic on `length()` (bounds checks, slicing decisions) quietly misbehaves on any file containing an accented character, CJK text, or an emoji.
### Root cause
`MagicString::len()` sums `&str::len()` over the chunk fragments, which is UTF-8 bytes. The binding returned it unconverted:
```rust
pub fn length(&self) -> u32 {
self.inner.len() as u32
}
```
`length()` was the only index-based method that skipped the `Utf16ToByteMapper` the binding already builds for every other position API (`appendLeft`, `overwrite`, `slice`, …), so the UTF-16 boundary was handled everywhere except here.
### The fix
Add `MagicString::len_utf16`, covering exactly the same span as `len` — chunk content only, global `prepend`/`append` intro/outro excluded, matching `magic-string`'s `length()` — and use it from the binding. `len()` keeps its byte semantics for Rust callers and now documents that explicitly.
### Why this wasn't caught
The vendored upstream conformance suite (`packages/rolldown/tests/magic-string/MagicString.test.ts`) exercises `length` only with ASCII, where bytes and code units coincide. The new tests live next to the other hand-written binding cases in `rolldown-magic-string.test.ts`, which is where the UTF-16↔UTF-8 boundary coverage already sits.
### Tests
Three cases in `packages/rolldown/tests/magic-string/rolldown-magic-string.test.ts`: the non-ASCII table above, `length()` after an edit that inserts a surrogate pair (asserted against `toString().length`), and a guard that the global intro/outro stays excluded. All three fail on `main` and pass here.
59806ff to
87eb372
Compare
…urce
`by_start_mut` and `by_end_mut` short-circuited before consulting the chunk maps:
fn by_start_mut(..) { if text_index as usize == self.source.len() { Ok(None) } .. }
fn by_end_mut(..) { if text_index == 0 { Ok(None) } .. }
Those approximate "no chunk at this index". That holds for a non-empty source —
nothing ends at 0, nothing starts at `len` — but an empty source's sole `[0, 0)`
chunk both starts *and* ends at 0, and the constructor registers it under
`chunk_by_start[0]` and `chunk_by_end[0]` alike. The guard answered `None` before
the map was ever asked, so the content went to the global intro/outro, which
`length()` and `isEmpty()` do not count:
const s = new RolldownMagicString('');
s.appendLeft(0, 'é');
s.toString(); // 'é'
s.length(); // 0, magic-string returns 1
s.isEmpty(); // true, magic-string returns false
All four positional methods reproduce it; an emoji returns 0 instead of 2.
Drop both short-circuits and let the map lookup answer, which is correct for
both cases — on "abc", `chunk_by_end.get(0)` returns `None` anyway — and is what
magic-string does, a plain `byStart[index]` / `byEnd[index]` lookup.
Stacked on the UTF-16 `length()` fix rather than folded into it: the cause is
unrelated (chunk placement, not unit conversion) and this also moves `isEmpty()`,
so it deserves its own entry in the history. It cannot go below that fix, though
— on its own the chunk would hold 'é' and `len()` would count its 2 bytes, so the
correct answer of 1 only appears with both.
Five of the eight tests fail without this change. The other three are the
contrast @hyfdev asked for: `append`/`prepend` stay excluded, and non-empty
out-of-range inserts stay excluded. They pass either way by design — the tempting
alternative fix is to make `len_utf16` count the global intro/outro, which would
satisfy the five while breaking exactly these three.
Reported-by: @hyfdev in #10295
…urce
`by_start_mut` and `by_end_mut` short-circuited before consulting the chunk maps:
fn by_start_mut(..) { if text_index as usize == self.source.len() { Ok(None) } .. }
fn by_end_mut(..) { if text_index == 0 { Ok(None) } .. }
Those approximate "no chunk at this index". That holds for a non-empty source —
nothing ends at 0, nothing starts at `len` — but an empty source's sole `[0, 0)`
chunk both starts *and* ends at 0, and the constructor registers it under
`chunk_by_start[0]` and `chunk_by_end[0]` alike. The guard answered `None` before
the map was ever asked, so the content went to the global intro/outro, which
`length()` and `isEmpty()` do not count:
const s = new RolldownMagicString('');
s.appendLeft(0, 'é');
s.toString(); // 'é'
s.length(); // 0, magic-string returns 1
s.isEmpty(); // true, magic-string returns false
All four positional methods reproduce it; an emoji returns 0 instead of 2.
Drop both short-circuits and let the map lookup answer, which is correct for
both cases — on "abc", `chunk_by_end.get(0)` returns `None` anyway — and is what
magic-string does, a plain `byStart[index]` / `byEnd[index]` lookup.
Stacked on the UTF-16 `length()` fix rather than folded into it: the cause is
unrelated (chunk placement, not unit conversion) and this also moves `isEmpty()`,
so it deserves its own entry in the history. It cannot go below that fix, though
— on its own the chunk would hold 'é' and `len()` would count its 2 bytes, so the
correct answer of 1 only appears with both.
Five of the eight tests fail without this change. The other three are the
contrast @hyfdev asked for: `append`/`prepend` stay excluded, and non-empty
out-of-range inserts stay excluded. They pass either way by design — the tempting
alternative fix is to make `len_utf16` count the global intro/outro, which would
satisfy the five while breaking exactly these three.
Reported-by: @hyfdev in #10295
…urce (#10306) > Stacked on #10295 — review that first; this PR's diff is just the second commit. > > Reported by @hyfdev in #10295 (comment). Split out of #10295 rather than folded into it: the cause is unrelated (chunk placement, not unit conversion) and it also changes `isEmpty()`, so it deserves its own entry in the history. It can't sit *below* #10295 though — see "Why it stacks here". ### What this solves A positional insert at index 0 on an **empty** source is not counted: ```js const s = new RolldownMagicString(''); s.appendLeft(0, 'é'); s.toString(); // 'é' s.length(); // 0 — magic-string returns 1 s.isEmpty(); // true — magic-string returns false ``` All four positional methods reproduce it, and an emoji returns `0` instead of `2`. Pre-existing: `main` returns `0` here too, since `length()` there also walks chunks only. ### Root cause `by_start_mut` and `by_end_mut` answered *before* consulting the chunk maps: ```rust fn by_start_mut(..) { if text_index as usize == self.source.len() { Ok(None) } .. } fn by_end_mut(..) { if text_index == 0 { Ok(None) } .. } ``` Both are shortcuts for "no chunk at this index". That holds for a non-empty source — nothing ends at 0, nothing starts at `len`. It is false for an empty source: its sole `[0, 0)` chunk both **starts and ends at 0**, and the constructor registers it under `chunk_by_start[0]` *and* `chunk_by_end[0]`. The guard fired first, so the content was routed to the global intro/outro, which `length()` and `isEmpty()` deliberately exclude. `magic-string` has no such special case — `appendLeft` is a plain `byEnd[index]` lookup, `appendRight` a plain `byStart[index]` lookup, and on an empty source both hit the zero-length chunk. ### The fix Delete both shortcuts and let the map answer. Correct for both cases — on `'abc'`, `chunk_by_end.get(0)` returns `None` anyway, so out-of-chunk-range inserts still go to the global intro/outro exactly as before. ### Why it stacks here and not below #10295 On its own this fix would still be wrong. With the guards gone but no UTF-16 change, `''` + `appendLeft(0, 'é')` puts `é` on the chunk and `len()` counts its **2 bytes** — so `length()` returns 2, not 1. The correct answer only appears with both changes, which is why this sits directly on top of the `length()` UTF-16 fix. ### Tests Eight cases. **Five fail without this change**: the four positional methods at index 0, plus the emoji UTF-16 case. The other three are the contrast @hyfdev asked for, and they pass either way by design: - `append('é')` / `prepend('é')` on an empty source stay **excluded** (`length() === 0`) — they are not positional, so they belong in the global intro/outro. - Non-empty out-of-range inserts (`'abc'` + `appendLeft(0, 'X')` / `appendRight(3, 'X')`) stay **excluded**. They earn their place: the tempting alternative fix is to make `len_utf16` count the global intro/outro, which would satisfy all five failing tests while breaking exactly these three. ### Verification Differential run against `[email protected]` over 11 cases (`toString`, `length`, `isEmpty`): **0 divergences**, down from 5 before this change. The 199-test vendored upstream conformance suite still passes.
> Stacked on #10295 — review that first; this PR's diff is just the second commit. ### What this solves `hasChanged()` reports `true` for edits that cancel out, i.e. when the generated output is byte-identical to the source: ```js const s = new RolldownMagicString('abc'); s.remove(0, 1); s.prepend('a'); s.toString(); // 'abc' — identical to the original s.hasChanged(); // true — magic-string says false ``` Plugins commonly gate on `hasChanged()` to decide whether to hand back a transformed result and a sourcemap at all, so a false positive means pointless downstream work for a module that wasn't really touched. ### Root cause ```rust self.source.len() != self.len() || self.source.as_ref() != self.to_string() ``` The first clause is meant to be a cheap "definitely changed" fast path for the string comparison after it — but the two measure different spans. `len()` counts **only chunk content**, while `to_string()` also includes the global intro/outro from `prepend`/`append`. So any edit that shifts bytes between the chunks and the global intro/outro trips the fast path even when the two sides balance out. Above: `remove(0, 1)` drops a byte from the chunks (`len()` 3 → 2) and `prepend("a")` puts it back in the intro, which `len()` cannot see — `3 != 2` short-circuits to `true`. `magic-string` has no fast path at all; it is just `original !== toString()`. ### The fix Compare the whole output — global intro/outro included — so the fast path covers the same span as the comparison it short-circuits. Kept as a length check rather than dropped entirely, since it still avoids the `to_string()` allocation in the common "definitely changed" case. ### Tests Three cases, one per branch of the resulting condition: | case | branch exercised | | --- | --- | | `remove(0,1)` + `prepend("a")` → `false` | lengths match, strings match — **the bug** | | `overwrite(0,3,"XYZ")` → `true` | lengths match, falls through to the string comparison | | `prepend("x")` → `true` | the fast path itself fires (output longer than source) | Only the first fails without this change. The two `is true` cases are deliberate: this PR *removes* a fast path, and a suite pinning only the bug case would equally accept a `has_changed()` that always returns `false` — I verified that by mutation, and those two are what catch it.
…its an edited chunk (#10301) > Stacked on #10299 → #10295 — review those first; this PR's diff is just the third commit. ### What this solves Four `MagicString` methods abort the process instead of throwing. Three lines of plugin code are enough: ```js const s = new RolldownMagicString('abcdef'); s.overwrite(0, 6, 'XYZ'); s.appendLeft(3, '!'); // Rolldown panicked. This is a bug in Rolldown, not your code. ``` ``` thread '<unnamed>' panicked at crates/string_wizard/src/magic_string/append.rs:23:39: Cannot split a chunk that has already been edited ``` This is not a recoverable error — a Rust panic across the FFI boundary takes the whole process down. A vitest worker running the repro dies outright, and there is nothing a plugin author can catch. `magic-string` throws a plain `Error` for the same input. ### Root cause `append_left`, `append_right`, `prepend_left` and `prepend_right` each called `.expect(...)` on the result of `by_end_mut`/`by_start_mut`: ```rust // Note: by_end_mut only errors when splitting an already-edited chunk, // but append operations don't require splitting edited chunks in practice. // We use expect here as this is an internal invariant. match self.by_end_mut(text_index).expect("append_left: unexpected split error") { ``` The comment is simply wrong. `by_end_mut` calls `split_at`, which calls `Chunk::split`, which genuinely returns `Err("Cannot split a chunk that has already been edited")` — and appending *inside* a range that was previously overwritten reaches it directly. The repo already knew, in a way: the conformance skip list carries `'split point', // split point errors cause panic` and `'should replace then remove', // causes split chunk panic`. ### The fix Return `Result` from the four methods and propagate. This cascades: - `indent_with` calls `prepend_right`, so it propagates too. Indentation only ever splits *unedited* chunks (the call sits in the `edited_content.is_none()` branch), so the error is unreachable there — but threading it through beats asserting an invariant that this very change shows can be wrong. It also makes the crate uniform: `update`, `remove`, `relocate`, `snip`, `reset` and `slice` already return `Result`. - The binding maps each to `napi::Error`. No TypeScript surface change — napi maps `Result<T>` to `T` and throws on `Err`. - Existing `string_wizard` tests gain `.unwrap()`; no behaviour change there. Also replaces the `unwrap` on the chunk walk in `update_with` with an explicit error. Not reachable today (the binding bounds-checks first), but that function already returns `Result`, so propagating costs nothing. ### Scope note I probed every other `unwrap`/`expect` reachable from the binding rather than converting them wholesale. Only these four are reachable; `update.rs` and `movement.rs` are already guarded by the binding's bounds checks and the split-point check, and return clean errors (`Invalid start character index`, `Cannot move a selection inside itself`). Converting a panic to an error is only safe where the function has not already mutated shared state — so the remaining sites are handled deliberately, not swept. ### Tests Five cases in `rolldown-magic-string.test.ts`. **Each one aborts the test worker on the parent commit**, so they have to be run one per process to see it — a batch run just reports the file as crashed. | test | panic site it covers | | --- | --- | | `appendLeft() throws instead of panicking` | `append.rs:23` | | `appendRight() throws instead of panicking` | `append.rs:46` | | `prependLeft() throws instead of panicking` | `prepend.rs:15` | | `prependRight() throws instead of panicking` | `prepend.rs:26` | | `leaves the instance usable after the error` | asserts `toString()` still works afterwards | The four look near-identical but each covers a distinct call site. The fifth pins that the failed operation left the instance intact — a different property, and the one that would catch "propagates the error but corrupts state".
## [1.2.1] - 2026-07-29 ### 🚀 Features - dev: support `hotUpdate` hook (#10305) by @h-a-n-a - dev: expose `disableWatcher` through the dev engine bindings (#10474) by @shulaoda - plugin: surface output-option callbacks in [PLUGIN_TIMINGS] (#10411) by @IWANABETHATGUY - `import.meta.ROLLDOWN_FILE_URL_<referenceId>_<urlId>` support to pass context to `resolveFileUrl` hook (#10297) by @sapphi-red - dev: skip the HMR update when a module's rebuilt output is unchanged (#10333) by @h-a-n-a - code-splitting: wrap strict execution order modules on demand (#10104) by @hyfdev - support `import.meta.ROLLDOWN_FILE_URL_*` (#10296) by @sapphi-red - implement `resolveFileUrl` plugin hook (#10291) by @sapphi-red - magic-string: support storeName on overwrite/update (#10312) by @IWANABETHATGUY ### 🐛 Bug Fixes - external: keep `__toESM` when the importing module is tree-shaken (#10516) by @IWANABETHATGUY - dev: resolve re-exports from externals through a real import (#10489) by @tbvjaos510 - code-splitting: route CJS barrel initialization per consumer (#10488) by @hyfdev - error: align filename-pattern diagnostics with Rollup's wording (#10501) by @IWANABETHATGUY - plugin: validate emitted prebuilt-chunk file names (#10399) by @IWANABETHATGUY - code-splitting: point a two-argument dynamic import at the chunk that holds the module (#10479) by @hyfdev - common: align is_path_fragment with Rollup's isPathFragment (#10398) by @IWANABETHATGUY - code-splitting: never name an internal chunk export `then` (#10480) by @hyfdev - code-splitting: avoid creating call-site-triggered entry facades (#10485) by @hyfdev - code-splitting: collect top-level eager order reasons in every strict build (#10463) by @hyfdev - code-splitting: let a cross-chunk dynamic importer carry the order trigger (#10456) by @hyfdev - code-splitting: avoid the dynamic-entry facade when the same-chunk collapse carries the trigger (#10433) by @hyfdev - binding: forward resolveId options.kind to callable builtin plugins (#10440) by @martijnwalraven - dev: keep the export name of `export * as ns from` (#10476) by @tbvjaos510 - code-splitting: only split an entry facade when something else can load its chunk (#10441) by @hyfdev - code-splitting: fold the runtime chunk back after order lowering (#10414) by @hyfdev - runtime: don't leave default undefined for cjs that fakes __esModule (#10453) by @IWANABETHATGUY - import-glob: escape generated string literals (#10438) by @shantanuraj - preserve-modules: don't assume every chunk mirrors a module (#10442) by @hyfdev - filter: treat missing hook inputs as non-matches, not panics (#10443) by @IWANABETHATGUY - code-splitting: keep CommonJS modules wrapped under strict execution order (#10405) by @hyfdev - code-splitting: align dynamicImports metadata with the rewritten import() specifier (#10430) by @hyfdev - dev: skip user plugin hooks for ?rolldown-lazy proxy modules (#10426) by @unknownjedi - treeshake: preserve side-effect-free spread arguments in manual-pure chains (#10432) by @IWANABETHATGUY - treeshake: preserve eagerly evaluated child effects of manual pure chains (#10427) by @Nic-Polumeyv - code-splitting: initialize pure definers behind star re-export barrels under strict execution order (#10409) by @hyfdev - resolveId: reject string `id` filters (must be a RegExp) (#10412) by @IWANABETHATGUY - code-splitting: collect eager order reasons for on-demand wrapping (#10387) by @hyfdev - rolldown: apply output.paths to CJS export-star of external modules (#10406) by @IWANABETHATGUY - dev: sourcemaps of lazily compiled chunks (#10386) by @tbvjaos510 - plugin: validate emitted file names at emitFile time (#10377) by @Nic-Polumeyv - guarantee tokio runtime release when close rejects (#10381) by @shulaoda - code-splitting: make strict transitive init registration deterministic and constant-time (#10320) by @hyfdev - pair tokio runtime acquire and release on wasm to prevent premature shutdown (#10363) by @shulaoda - don't body-demand modules from simulated facade chunk includes (#10351) by @IWANABETHATGUY - tracing: invalid RD_LOG filter and RD_LOG_OUTPUT=json no longer panic (#10343) by @Brooooooklyn - code-splitting: treat class definition-time global reads as order-sensitive (#10322) by @hyfdev - code-splitting: deconflict force-included runtime helper statements (#10336) by @hyfdev - binding: forward all missing parallel JS plugin hooks (#10345) by @Brooooooklyn - code-splitting: re-derive chunk exec order after the runtime sweep (#10334) by @hyfdev - types: add undefined to ExistingRawSourceMap optional properties (#10355) by @ocavue - magic-string: validate relocate ranges before rewiring (#10327) by @IWANABETHATGUY - add EMPTY_IMPORT_META warning for non-node CJS output (#10222) by @sapphi-red - call `resolveFileUrl` in a deterministic order (#10330) by @sapphi-red - magic-string: refuse repeated sendMagicString on a consumed instance (#10331) by @IWANABETHATGUY - magic-string: refuse to use a MagicString after sendMagicString consumed it (#10326) by @IWANABETHATGUY - magic-string: reject non-contiguous moves before rewiring the chunk list (#10311) by @IWANABETHATGUY - handle `./foo/bar` glob pattern the same as `foo/bar` (#10313) by @sapphi-red - magic-string: throw instead of panicking when append/prepend splits an edited chunk (#10301) by @IWANABETHATGUY - output: skip separator for empty hoisted functions (#10310) by @hyfdev - magic-string: don't report a change when edits cancel out (#10299) by @IWANABETHATGUY - sourcemap: map wrapped imported callees (#10288) by @hyfdev - magic-string: count positional inserts at index 0 on an empty source (#10306) by @IWANABETHATGUY - magic-string: return UTF-16 code units from length() (#10295) by @IWANABETHATGUY - output: skip separator for empty import prelude (#10289) by @hyfdev ### 🚜 Refactor - dev: make it easier to customize the runtime (#10338) by @sapphi-red - code-splitting: declare CJS carrier namespaces initializer-free (#10513) by @hyfdev - rollup-tests: avoid relying on `NODE_PATH` env var resolution (#10496) by @sapphi-red - code-splitting: derive symbol chunk ownership as pass-local link data (#10449) by @hyfdev - plugin: share asset emission helpers between copy_module and asset_module (#10450) by @Nic-Polumeyv - plugin: dedupe hook binding boilerplate (#10428) by @Nic-Polumeyv - plugin: share the oxc parse preamble between import-glob and dynamic-import-vars (#10452) by @Nic-Polumeyv - implement `GetAstBuilder` on visitor/pass types (#10424) by @overlookmotel - pass arrays to AST builder methods (#10419) by @overlookmotel - shorten AST builder code (#10418) by @overlookmotel - centralize final ESM init metadata (#10376) by @hyfdev - descriptor-based parallel-plugin detection (getParallelPluginInfo) (#10349) by @Brooooooklyn - remove AstFactory in favor of new_* construction traits (#10353) by @Boshen - enable oxc_ast's `disable_old_builder` feature (#10316) by @Boshen ### 📚 Documentation - development-guide: update config.json link line reference (#10523) by @dogledogle - clarify slash normalization for id hook filter (#10511) by @sapphi-red - code-splitting: record the thenable-namespace rule (#10502) by @hyfdev - clarify that `esmExternalRequirePlugin` must own its externals (#10439) by @TheAlexLichter - add troubleshooting entry for the @rolldown/binding-... resolution error (#10390) by @Nic-Polumeyv - add Code Splitting API reference category (#10382) by @vittorioexp ### ⚡ Performance - use VisitJsMut in JavaScript-only AST passes (#10507) by @Boshen - cache the resolved glob matcher for Id/ImporterId filters (#10410) by @IWANABETHATGUY - scope_hoisting: remove `alloc` field from `ScopeHoistingFinalizer` (#10425) by @overlookmotel - reduce string allocations (#10423) by @overlookmotel - hmr: remove unnecessary string allocations (#10422) by @overlookmotel - avoid allocating static strings via custom builder methods (#10421) by @overlookmotel - pass string literals to AST builder methods (#10420) by @overlookmotel - use VisitJs in JavaScript-only AST passes (#10396) by @Boshen - plugin: shrink erased plugin debug vtables (#10370) by @Boshen - reuse normalized path buffers (#10315) by @hyfdev ### 🧪 Testing - code-splitting: pin CJS barrel fallback triggers and flag-off equivalence (#10514) by @hyfdev - plugin: cover chunk fileName, absolute chunk name, and Windows drive names (#10400) by @IWANABETHATGUY - code-splitting: cover a single-chunk dynamic import of a wrapped module (#10505) by @hyfdev - file: remove the unused .dynamic_import fixture (#10481) by @hyfdev - treeshake: reduce manual-pure fixture to a minimal smoke test, move matrix to unit tests (#10436) by @IWANABETHATGUY - dev: run vite playgrounds under bundled dev (test-serve-bundled) (#10434) by @h-a-n-a - stop snapshots from silently hiding user code inside the runtime region (#10431) by @hyfdev - wasi: add tokio runtime lifecycle regression test (#10379) by @shulaoda - dev: expect preserved hot.data in hmr-whole-chain-dispose (#10380) by @h-a-n-a - code-splitting: pin flag-off wrapped-esm init emission (#10324) by @hyfdev - sourcemap: fix Windows-only failures in composition fixtures (#10368) by @shulaoda - generated-code: mark assert external in symbols_ns2 for deterministic output (#10339) by @hyfdev - code-splitting: cover entries-aware strict init cycle (#10307) by @hyfdev - make `just setup-vite` the only entry point that touches `vite/` (#10332) by @shulaoda - vite-tests: reuse the shared root vite checkout (#10325) by @shulaoda - test-dev-server: drop the vite submodule, track rolldown-canary (#10319) by @shulaoda - vite-tests: track the latest rolldown-canary rebased onto vite main (#10318) by @shulaoda - unify Vite in vite-test and test-dev-server (#10293) by @h-a-n-a ### ⚙️ Miscellaneous Tasks - scope the binding artifact download to `bindings-*` (#10525) by @shulaoda - deps: update napi (#10506) by @renovate[bot] - deps: update rollup submodule for tests to v4.62.3 (#10494) by @rolldown-guard[bot] - deps: upgrade oxc to 0.142.0 (#10497) by @shulaoda - deps: update test262 submodule for tests (#10495) by @rolldown-guard[bot] - deps: update github actions (#10460) by @renovate[bot] - deps: update rust crates (#10462) by @renovate[bot] - deps: update npm packages (#10461) by @renovate[bot] - metric: alert Discord when the metric workflow fails (#10447) by @IWANABETHATGUY - metric: mint a short-lived GitHub App token instead of a PAT (#10446) by @IWANABETHATGUY - repo: repair dangling CLAUDE.md symlink (#10451) by @hanayashiki - publint/package-metadata fixes and small correctness fixes (#10344) by @Brooooooklyn - deps: update dependency vite-plus to v0.2.6 (#10404) by @renovate[bot] - add Semgrep scan workflow (#10395) by @Boshen - enable Windows CI with a PR label (#10375) by @hyfdev - deps: upgrade oxc to 0.141.0 (#10373) by @camc314 - deps: update napi (#10369) by @renovate[bot] - deps: update test262 submodule for tests (#10367) by @rolldown-guard[bot] - deps: update taiki-e/install-action action to v2.83.3 (#10358) by @renovate[bot] - deps: update rust crates (#10357) by @renovate[bot] - deps: update npm packages (#10359) by @renovate[bot] - deps: update rust crate syn to v3 (#10362) by @renovate[bot] - deps: update rust crate oxc_sourcemap to v8.1.2 (#10356) by @renovate[bot] - deps: update dependency vite-plus to v0.2.5 (#10329) by @renovate[bot] - docs: migrate Netlify redirects to Void config (#10282) by @tux-tn - deps: update dependency rust to v1.97.1 (#10317) by @renovate[bot] - runtime: remove unused `runtime/index.js` (#10302) by @IWANABETHATGUY ### ❤️ New Contributors * @dogledogle made their first contribution in [#10523](#10523) * @tbvjaos510 made their first contribution in [#10489](#10489) * @martijnwalraven made their first contribution in [#10440](#10440) * @shantanuraj made their first contribution in [#10438](#10438) * @Nic-Polumeyv made their first contribution in [#10450](#10450) * @hanayashiki made their first contribution in [#10451](#10451) * @unknownjedi made their first contribution in [#10426](#10426) * @vittorioexp made their first contribution in [#10382](#10382) * @tux-tn made their first contribution in [#10282](#10282) Co-authored-by: shulaoda <[email protected]>

What this solves
RolldownMagicString.length()returns the UTF-8 byte count instead of the UTF-16 code unit count that JavaScript — andmagic-string— report. Any non-ASCII source over-reports:length()beforemagic-string"abc""é""🤷""中文""abc™def"There is no panic and no warning — just a silently wrong number, so a plugin doing arithmetic on
length()(bounds checks, slicing decisions) quietly misbehaves on any file containing an accented character, CJK text, or an emoji.Root cause
MagicString::len()sums&str::len()over the chunk fragments, which is UTF-8 bytes. The binding returned it unconverted:length()was the only index-based method that skipped theUtf16ToByteMapperthe binding already builds for every other position API (appendLeft,overwrite,slice, …), so the UTF-16 boundary was handled everywhere except here.The fix
Add
MagicString::len_utf16, covering exactly the same span aslen— chunk content only, globalprepend/appendintro/outro excluded, matchingmagic-string'slength()— and use it from the binding.len()keeps its byte semantics for Rust callers and now documents that explicitly.Why this wasn't caught
The vendored upstream conformance suite (
packages/rolldown/tests/magic-string/MagicString.test.ts) exerciseslengthonly with ASCII, where bytes and code units coincide. The new tests live next to the other hand-written binding cases inrolldown-magic-string.test.ts, which is where the UTF-16↔UTF-8 boundary coverage already sits.Tests
Three cases in
packages/rolldown/tests/magic-string/rolldown-magic-string.test.ts: the non-ASCII table above,length()after an edit that inserts a surrogate pair (asserted againsttoString().length), and a guard that the global intro/outro stays excluded. All three fail onmainand pass here.