Description
Describe the bug
Enabling typescript preprocess breaks __svelte_meta.loc
reporting on elements, since the script
tag is being processed and the amount of lines and columns no longer relates to the original file.
Unfortunately this renders any debugging tools useless.
Logs
No error logs
To Reproduce
I have prepared two identical components, one written with lang="ts"
, the other one in plain JS.
- Clone
https://github.com/FluffyDiscord/svelte-preprocess-offset-bug
- Run
yarn install
ornpm install
- Run
yarn dev
ornpm run dev
- Open browser at
http://localhost:5173/
or the specified Vite url found in console - Left click on the svelte inspector helper in top right corner
- Hover over
shifted location
element, it will report that thespan
is on the sixth line, which is wrong - Now hover over
correct location
element, it will report that thespan
is on the seventh line, which is correct
Invalid reported position, Svelte thinks the span
starts at line 6 column 5, because of the preprocess.
Correctly reported position of the span
at line 7, column 5.
In this simple example case the difference is just a single line. In larger Svelte components with longer script
tags with more TS definitions the difference can be as much as few dozen lines and columns (function parameter types, interface/type definitions, inline variable/property types).
Expected behavior
The preprocess does not shift or change the line or column size. It should fill up the removed lines with empty line character \n
and fill up removed columns with empty space character
or JS comments /* */
in DEV
mode. This is not required for PROD and maybe even preferable to be that way to confuse lurkers :)
Stacktraces
None needed
Information about your project:
None needed
Additional context
This might also apply to other tags like style
or module
(not tested, since I don't use module
and I put style
at the bottom)
There is a workaround and that is to put script
tag at the bottom of the svelte
file. But that goes against the Svelte idea. I don't want to have move hundreds of script
tags in my files down to bottom, it should not be required to do so.