Skip to content

With typescript: true the __svelte_meta.loc reports invalid location because script tag is changing number of lines/columns #8360

Closed
@FluffyDiscord

Description

@FluffyDiscord

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.

  1. Clone https://github.com/FluffyDiscord/svelte-preprocess-offset-bug
  2. Run yarn install or npm install
  3. Run yarn dev or npm run dev
  4. Open browser at http://localhost:5173/ or the specified Vite url found in console
  5. Left click on the svelte inspector helper in top right corner
  6. Hover over shifted location element, it will report that the span is on the sixth line, which is wrong
  7. Now hover over correct location element, it will report that the span 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.
image

Correctly reported position of the span at line 7, column 5.
image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions