-
Notifications
You must be signed in to change notification settings - Fork 150
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
Sourcemaps offset #286
Comments
@milahu I know you had done some investigation into this in sveltejs/svelte#5584 (comment). Not sure if it's something you'll be able to take a look at, but if so I'd be happy to help review |
thanks for the bug : ) a minimal reproduction is: add this to every svelte and js file console.log('this is file.xyz line 10'); // TODO keep line number in sync and then look at the JS console with with same result with older versions of svelte, 3.0.1 for example still not sure where exactly the problem is .. @dummdidumm do you know more? |
No I don't know more, but I think it's inside Svelte because inside language-tools we are able to map the warnings correctly. |
small bug in svelte-preprocess: the regex for these work as expected in svelte: async function preprocess_tag_content(tag_name: 'style' | 'script', preprocessor: Preprocessor) {
const get_location = getLocator(source);
const tag_regex = tag_name === 'style'
? /<!--[^]*?-->|<style(\s[^]*?)?(?:>([^]*?)<\/style>|\/>)/gi
: /<!--[^]*?-->|<script(\s[^]*?)?(?:>([^]*?)<\/script>|\/>)/gi; also, |
edit: nope possible cause: <!-- This file is generated by Sapper — do not edit it! --> is added on top of every *.svelte file that is passed to svelte.compile edit: no, this comes from to debug, i patched function compile(source, options = {}) {
+console.log('compile source >>>>'+source+'<<<<'); injecting that comment without changing lines / columns good night ; ) |
new suspect: <style>
h2 {
font-size: 15px;
}
</style> becomes this <style>
h2 {
font-size: 15px;
}
/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW....4iXX0= */</style> before the backtrace:
so .. blame postcss! postcss/postcss#1486 a quickfix could be made with https://github.com/ds300/patch-package case closed : ) |
This happens for me when I use a TS preprocessor only so that can't be it. Also the PostCSS issue should have been fixed ( #251 ). |
should be the same problem sourcemaps are injected at end-of-file |
I'm not sure that's true. If I throw an error inside the script, that error has the wrong line. If the sourceMap-stuff is added inline, then it's added to the end of the script tag, so it should not affect things before that. For reference, here is how language-tools does the sourcemapping:
When an original position is requested, find out if it's inside script/style.
|
fixed the postcss bug in postcss/postcss#1487 problem was: |
@milahu In some cases lines are not offset N-1 lines, it actually seems to depend on the complexity of the style tag |
postcss adds one 'bad' line for every preprocessor an easier solution is sveltejs/svelte#5754 |
I updated my example repo to the newest version including that sourcemap pr. |
found the problem the preprocessor returns sourcemap not in
this magic comment is currently ignored by svelte, but its parsed by the browser solution: in svelte, detect if preprocessor added the magic-comment-line at end-of-file, @dmitrage do you wanna fix this? |
Or should we fix the preprocessor instead to return the map in |
its a de-facto-standard, so id say we make svelte more tolerant. im working on it, the only challenge is parsing multiple attachments, and eventually merging them with |
What do you mean by "multiple attachments" and "time-order is unclear"? The order in which script/style/markup is preprocessed is fixed at the moment. |
a preprocessor can return sourcemaps in multiple attachments: var code = 'here';
/*# sourceMappingURL=data:application/json;base64,....map1.... */
/*# sourceMappingURL=data:application/json;base64,....map2.... */ edit: too complicated. now focussing on the simple cases |
@Maggi64 can you test my patch in https://github.com/milahu/svelte/tree/parse-attached-sourcemap? edit: done, problem solved : ) |
@milahu sorry, will be almost off in the next few days.
I'd vote for keeping this direction. Edge cases with multiple/mixed inline/external maps are rare enough and preprocessor side has more context of how to deal with them. Adding api sugar for such seems excess and increasing maintenance burden. In contrast, extracting map from single inline comment with no external returned is unambiguous, easy to implement and sounds common. |
I'm noticing this also with a Here you can see the error for |
@milahu thanks for helping me out with this issue. 👍 Tried your branch, it indeed works for the example repo and seemed to fix the sourcemap for most cases. But when i turn on scss preprocessing it is offset again sadly. Also updated my example repo. |
Not sure if this will be coming from the same issue (this discussion seems to revolve around the style block), but sourcemaps for TS script blocks also aren't correct, with or without a style block in the same component. Reproducing is as easy as cloning the template repo, running that |
where can i see that? i dont see any sourcemaps at all in the css files (sorry im new to sapper) not
when i run
looks like a bug in the template config edit: not. |
@milahu I just looked at chrome dev tools again. With the scss preprocessor the lines in the |
This comment has been minimized.
This comment has been minimized.
one problem is: sourcemap support in rollup-plugin-svelte is not yet released |
Good spot! Installing I'm fairly sure everything's configured correctly. As I said I'm just using the template repo and running the |
too long, dont readlooks like svelte-preprocess fails to parse the sourcemap from typescript App.svelte
result.code from typescript
result.map from typescript 1:0 <-- App.svelte 1:0 <script lang="ts">export let name: string; 1:1 <-- App.svelte 1:1 <script lang="ts">export let name: string; 1:7 <-- App.svelte 1:7 <script lang="ts">export let name: string; 1:8 <-- App.svelte 1:8 <script lang="ts">export let name: string; 1:12 <-- App.svelte 1:12 <script lang="ts">export let name: string; 1:13 <-- App.svelte 1:13 <script lang="ts">export let name: string; 1:14 <-- App.svelte 1:14 <script lang="ts">export let name: string; 1:16 <-- App.svelte 1:16 <script lang="ts">export let name: string; 1:17 <-- App.svelte 1:17 <script lang="ts">export let name: string; 3:0 <-- App.svelte 13:0 </script> 3:1 <-- App.svelte 13:1 </script> 3:2 <-- App.svelte 13:2 </script> 3:8 <-- App.svelte 13:8 </script> = line trace:
// svelte-preprocess/src/transformers/typescript.ts
const {
outputText: code,
sourceMapText: map,
diagnostics,
} = ts.transpileModule(content, {
fileName: filename,
compilerOptions,
reportDiagnostics: options.reportDiagnostics !== false,
transformers: {
before: [importTransformer],
},
}); here |
@milahu Thank you very much, works perfectly. I also tested some more complex configs with autoprefixer & sass prependData. Would like to see these PRs merged to fix the issue: @benmccann
Related PRs:
Example Repo is updated with the patched versions. |
… for ts (#286) (#299) * fix typescript: make sourcemaps default on (#286) * move option * getTransformerOptions: accept propPath * typescript: fix propPath to compilerOptions.sourceMap * typescript: remove old patch * lint * fix test to use propPath * chore: 🤖 lint * refactor to function setProp * setProp: clarify fn signature Co-authored-by: Christian Kaisermann <christian@kaisermann.me>
Thanks to sveltejs/svelte#5854, |
A new version of |
Still facing the same issues as before, TS <script> blocks' source maps appear to map everything to the first line. Again, I'm just running the template repo, adding a couple of lines to This is with |
@benmccann @Conduitry Thanks at least for me all issues are fixed |
I think the problem is #300 - |
nope, when svelte-preprocess/src/autoProcess.ts Lines 129 to 133 in 4446571
svelte-preprocess/src/modules/language.ts Lines 39 to 41 in 4446571
"map everything to the first line" happens when *should* be fixed by #299 =
100% sure? please run node -e 'console.log(require("svelte-preprocess/package.json").version)' |
Yep 100%.
Perhaps the config created by the |
yes! this was missing:
fixed in sveltejs/template#216 |
I'm reading the whole thread and I'm a bit lost. Apart from (the ts sourcemap prop I know it is, thanks @milahu 🎉 ) |
should be all fixed, @Maggi64 said
|
That's the VS Code extension putting out these warnings, that's unrelated. The VS Code extension uses a somewhat incomplete approach to this and I plan to refactor this some day. |
Describe the bug
In my current project and in the example repo below the sourcemaps are offset by a few lines.
This seems to be related to the style tag:
To Reproduce
npm run dev
Expected behavior
Correctly linked sourcemaps. Otherwise debugging issues becomes quite hard.
Information about your project:
Your browser and the version: (Chrome 87)
Your operating system: (Windows 10)
Rollup & svelte-preprocess are updated to the newest versions (see repo package.json)
All other packages used are also on the newest version
I hope this is the correct place for this issue. Help and suggestions where that problem exactly comes from are appreciated.
Edit: Even without scss preprocessing this issue still persists. Adjusted example repo.
The text was updated successfully, but these errors were encountered: