-
- Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
This originally broke source maps with SvelteKit. A workaround was added to Vite, but we still don't get source maps for static files.
Svelte generates a segment-less sourcemap when there's no dynamic content in the template. Appears it's coming from the use of code-red to print out the AST tree: https://github.com/Rich-Harris/code-red/blob/3b32d2ef5bd954cb85a0d005f3a328bae57c6a97/src/print/index.ts#L60-L86
Normally, the AST being printed would contain loc objects that point into the original code. But when Svelte is processing a file without any dynamic code, it doesn't attach any locs (though it does add start and end). I think this is a bad behavior, Svelte should be associating source location for static code as well. Eg, something like the following:
<h1>decoded-sourcemap</h1> <div>replace me</div>
The h1
should be associated with { start: { line: 1, column: 2 } }
, the decoded-sourcemap with { start: { line: 1, column: 5 } }
, etc. With the AST given the correct loc associations, code-red's printer will make a sourcemap with valid segments, and the bug will disappear.