Bending Svelte using Preprocessors
summary
Builds a Svelte preprocessor that extracts the children of a <SourceCode> inline component by reading node.children start/end offsets from the AST, slices the original file and injects a new source prop while escaping backticks, and preserves accurate sourcemaps. Uses MagicString for edits and map generation and svelte/compiler parse+walk to find nodes, relying on index math and appendLeft to insert attributes. A working demo and tests run in the provided playground.
AI-written summary · about
chapters (8)
- 0:00Introduction and goals
- 2:08Project setup overview
- 4:32Planning with AST Explorer
- 6:58Technical approach design
- 12:00Initializing magic string
- 14:16AST parsing and traversal
- 18:18Implementing property injection
- 21:13Verification and finalization








