What problem does it solve?
Writing Rolldown transform plugins requires correctly pairing the read-only Oxc AST with MagicString edits, and mistakes like mutating the AST, misplacing transforms in renderChunk, or missing native MagicString configuration silently break builds or source maps.
Core Features & Use Cases
- AST-guided source edits: Walk the Oxc AST with oxc-walker and apply offset-based edits through meta.magicString so changes stay precise and source maps compose automatically.
- Correct hook placement: Guidance on keeping module-oriented edits in transform and reserving renderChunk for edits that depend on final generated code or chunk metadata.
- Host configuration: Instructions for enabling experimental.nativeMagicString in Rolldown and tsdown configs, plus adapting transforms for Vite, which does not forward AST or MagicString metadata.
- Use Case: Rename every $compile() call in a codebase by filtering modules with a cheap code.includes guard, locating call expressions via meta.ast, overwriting callee ranges with meta.magicString, and validating the result in a real Rolldown build.
Quick Start
Write a Rolldown transform plugin that renames all $compile() calls to compile() using the Oxc AST and native MagicString, then verify it in a real build.