svelte-preprocess icon indicating copy to clipboard operation
svelte-preprocess copied to clipboard

Better preservation/fallback of/for source maps

Open dummdidumm opened this issue 4 years ago • 5 comments

Is your feature request related to a problem? Please describe. Some preprocessors might not return a source map. This breaks the "chain" of source maps and the result is that positions due to errors for example cannot be mapped correctly anymore.

Describe the solution you'd like Investigate if there's a possibility to provide somewhat sane fallbacks for Style and Script preprocessors, like "return a source map that indicates that script/style now has this length instead of the previous one". Don't know how to phrase this better, just an idea.

How important is this feature to you? Nice to have

dummdidumm avatar Jun 23 '21 16:06 dummdidumm

this causes issues with vite, eg. https://github.com/sveltejs/kit/issues/1745 (I also saw it happen with windicss), so i'm in favor of providing sourcemaps where possible.

In case of postcss i'm sure that it does provide sourcemaps, so it should be possible to pass them on. The case where a preprocessor does not return a sourcemap should/could be handled in svelte core instead.

dominikg avatar Jun 24 '21 09:06 dominikg

Addendum: I think svelte-preprocess itself is a bit of a special case due to it's internal handling of multiple preprocess steps with a single preprocessor (preprocess: sveltePreprocess()), so it might have to account for missing sourcemaps in its internal steps also

dominikg avatar Jun 24 '21 09:06 dominikg

Some preprocessors like PostCSS do not return a source map

Are you sure about this? If so, we should fix that. I thought that it did though. I remember @milahu trying to fix some issues with the line numbers being a bit off in https://github.com/sveltejs/svelte-preprocess/issues/286, so I'd expect it was returning something at some point. He also had started on some improvements in the postcss css repo https://github.com/postcss/postcss/pull/1487, but they were not completed/merged

benmccann avatar Jun 24 '21 13:06 benmccann

No honestly I'm not sure about it 😄 I adjusted the wording

dummdidumm avatar Jun 24 '21 15:06 dummdidumm

FWIW @dominikg had implemented this for vite-plugin-svelte a while ago. It's under the experimental options though and I've never heard anyone using it. But if it works, the code could be re-used internally here or in Svelte core too.

bluwy avatar Sep 04 '21 14:09 bluwy