mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-07 08:33:50 +08:00
s.replace(re, fn) and replaceAll boxed a typed callback into a dyn function and called it through the dyn ABI: per match, a dyn argument array, a dyn node per capture and for the offset, the box's argument checks back to typed values, and a dyn result converted to a string. When every parameter the callback declares receives a value of its declared kind in each match, the box is unobservable (the runtime only calls it, with `this` undefined), so the backend passes the closure to scr_regex_replace_fn, which collects the matches as before and calls the closure through its own ABI. That holds for callbacks returning a string that take the match string alone, or, with a regex literal whose captures the compiled-matcher parser reads, captures every match sets (strings), then the offset (a number) and the subject (a string). Callbacks with optional, union or rest parameters, `arguments`, or captures some match leaves unset keep the dyn path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>