Skip to content

Source map line numbers are wrong when using typescript #5182

Closed
@fd0

Description

@fd0

Describe the bug
When using typescript within .svelte files, the generated source map references the wrong line number, it is too low.

To Reproduce

  • Checkout the template and install libraries:
npx degit sveltejs/template svelte-typescript-app
cd svelte-typescript-app
npm install
  • Modify the script in src/App.svelte like this:
<script>
    export let name;

    // test comment
    console.error("error logged from line five in App.svelte")
</script>
  • Run the app and visit it in a browser, the following message is in the JavaScript console:
error logged from line five in App.svelte     App.svelte:5
  • Now add TypeScript support according to the instructions in the blog:
node scripts/setupTypeScript.js
npm install
  • Mark the script in src/App.svelte as TypeScript:
<script lang="ts">
    export let name;

    // test comment
    console.error("error logged from line five in App.svelte")
</script>
  • Run the app, visit it again, find the following message in the browser console:
error logged from line five in App.svelte      App.svelte:3 
  • Clicking on the file name takes me to line 3 of App.svelte:
    svelte-error

I've published a reproduction repo here: https://github.com/fd0/svelte-bug-typescript-sourcemap (including package-lock.json).

Expected behavior

The error message should refer to the correct line in the source code (line 5 instead of line 3).

Information about your Svelte project:

  • Chrome 83.0.4103.116
  • Debian Buster
  • Svelte 3.24.0
  • Rollup 2.22.2

Severity

It's very annoying, but does not block me (or anybody else). Debugging takes much longer.

Additional context

Thank you very much for adding TypeScript to Svelte, I love it!

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