-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
add: parse attached sourcemap from preprocessor #5854
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks! this looks pretty good to me
@dmitrage do you want to take a look at this as well before it's merged?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Quick review summary:
- please add support for single line comments
- ensure offsets are OK if the last line with comment had mapping (edge case)
And suggestion (for future PR?): maybe we should also remove external sourceMappingURL comment from preprocessed.code when preprocessed.map exists?
done regexspeculation: scss adds the magic comment without a newline, like div {
color: red;
}/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW ... vgICB9XG4iXX0= */ todo: simply use a regex? like
related: with regex, still errors with scss, which returns possible problem: for example result.map.sources = [
'file:///absolute/path/to/src/components/example.svelte',
'src/components/example.svelte' // = the filename passed to preprocessor
] but // offset only segments pointing at original component source
const source_index = decoded_map.sources.indexOf(file_basename);
if (source_index !== -1) {
sourcemap_add_offset(decoded_map, get_location(offset + prefix.length), source_index);
} which should look more like decoded_map.sources
.map((s, i) => ([s, i]))
.filter(([s, _i]) => get_file_basename(s as string) == file_basename)
.forEach(([_s, source_index]) => {
sourcemap_add_offset(decoded_map, get_location(offset + prefix.length), (source_index as number));
})
; .. but i still get the off-by-one error with scss *and* with css - nasty bug! scss sets both |
@milahu What is the current status on this PR? Are we waiting for that Sass PR? |
this PR is pretty-much finished what could be added is: if but regarding issue sveltejs/svelte-preprocess#286
// Combine all the source maps for each preprocessor function into one
const map: RawSourceMap = combine_sourcemaps(
file_basename,
sourcemap_list
); at this point of |
done. typescript does this, and there is no way to disable, so we must remove manually // sourceMappingURL is file path or URL
if (!processed.map) {
// TODO show warning? silently ignore?
throw_error('value error. processed.map is empty, '+
'but processed.code has attached sourcemap file '+map_url+'. '+
'please make your preprocessor return a sourcemap.');
} currently thats a fatal error, maybe can be ignored |
Thanks for this! Were there any other changes you wanted to get in after updating the warning message or will it be ready to merge after that? |
ready : ) |
This has been released in 3.32.0 - thank you! |
solve issue sveltejs/svelte-preprocess#286
allow preprocessors to return sourcemaps not only in
result.map
but also attached to
result.code
as 'magic comment' in script or styleor in script
the attached sourcemap is removed, so the browser does not double-parse the sourcemap
that was the original problem in issue 286
this removal is asserted by the test
for now, support only one sourcemap, either in
result.map
or attached toresult.code
, not both --> fatal erroralso for now, this works only for
script
andstyle
preprocessorsin theory, the 'magic comment' strategy is also possible in html