Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source maps include preprocessed source instead of original #171

Closed
ghost opened this issue Mar 17, 2021 · 8 comments · Fixed by #172
Closed

Source maps include preprocessed source instead of original #171

ghost opened this issue Mar 17, 2021 · 8 comments · Fixed by #172

Comments

@ghost
Copy link

ghost commented Mar 17, 2021

Describe the bug
I am using Svelte, TypeScript and Webpack. As far as I understand the source map feature implemented in sveltejs/svelte#5584, Svelte should transform the source map generated by TypeScript (via svelte-preprocess) into the final source map. This is not the case, apparently the source map contains the preprocessed JavaScript output. For example, the following Svelte component:

<script lang="ts">
  let name: string = 'world';

  console.log("This is App.svelte, line 4!");
</script>

<main>
  Hello {name}!
</main>

results in the following content in the sourcemap:

<script lang="ts">let name = 'world';
console.log("This is App.svelte, line 4!");
</script>

<main>
  Hello {name}!
</main>

Logs
The log line in the developer console reads This is App.svelte, line 4! [...] App.svelte:2:8.

To Reproduce
Clone this repository: https://github.com/baileyherbert/svelte-webpack-starter
Update to the latest Svelte version (npm update) and run the server npm run dev. View the source content in the browser console.

Expected behavior
I would expect the original TypeScript source to be contained in the source map. The line/col mappings should refer to the original locations in App.svelte.

Information about your Svelte project:

  • Firefox 78.8.0esr
  • Debian Linux 10
  • Svelte version 3.35.0
  • svelte-preprocess 4.6.9
  • svelte-loader 3.0.0
  • TypeScript 4.2.3
  • Webpack 5.26.2

Severity
Severity: Only annoying.

@dummdidumm
Copy link
Member

I think the problem is that the source map from preprocessing is not passed into the compiler by svelte-loader. At least I don't see anything in there that hints at this.

@benmccann benmccann transferred this issue from sveltejs/svelte Mar 17, 2021
@benmccann
Copy link
Member

Thanks! Yes, I missed Webpack in the original description. I've transferred this to the svelte-loader repo because I think you're right that the support added to rollup-plugin-svelte was never added to svelte-loader

@non25
Copy link
Contributor

non25 commented Mar 20, 2021

@rtpt-jonaslieb Can you test a fix and tell me if that worked out for you?

yarn add -D svelte-loader@sveltejs/svelte-loader
# or
npm i -D sveltejs/svelte-loader

@ghost
Copy link
Author

ghost commented Apr 1, 2021

@non25 Sorry, I just got around to thoroughly test the new feature.
The line mapping seems to be correct now.

There is a regression however: Previously, the preprocessed sourcesContent was included in the source map, now the source map does not include any sourcesContent for Svelte files (or rather: the corresponding entry in sourcesContent is null).
It appears that the issue can be fixed by setting

js.map.sourcesContent = [ source ]

some time after the compilation, as far as I can tell from a minimal project.

Anyways, the line mapping is really helpful, so thanks for the swift implementation.

@dummdidumm
Copy link
Member

This sounds like ampproject/remapping#116 , which is used in Svelte core to merge the preprocessed source map and the resulting map. If the preprocessed source map is empty, it happens.

@non25
Copy link
Contributor

non25 commented Apr 1, 2021

Should we fix it in svelte-loader with js.map.sourcesContent = [ source ]?
Or it should be fixed upstream?

@dummdidumm
Copy link
Member

There is a draf PR for it upstream in Svelte core sveltejs/svelte#6089 . Does the current behavior cause problems or is it just a "I noticed this" thing?

@ghost
Copy link
Author

ghost commented Apr 1, 2021

For my use case, this means that I always need to jump back to the editor to see the actual Svelte code. Ideally, I'd have all of that directly in the browser...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants