-
-
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 source map support for preprocessors #5015
add source map support for preprocessors #5015
Conversation
@halfnelson does this PR supersede #1863 ? |
@antony yep, it attempts to meet Rich's criteria "it'd be great if we could avoid using source-map" |
The downside is it isn't as clean as RedHatters awesome contribution, so happy for suggestions. I tend to stop at the "it works now" stage |
@halfnelson thanks for this! really excited about it. One thing I noticed from a quick peek at this PR is that a lot of the new code uses spaces. Could you convert it to tabs to match the existing code? |
@@ -91,7 +92,8 @@ | |||
"source-map-support": "^0.5.13", | |||
"tiny-glob": "^0.2.6", | |||
"tslib": "^1.10.0", | |||
"typescript": "^3.5.3" | |||
"typescript": "^3.5.3", | |||
"sourcemap-codec": "^1.4.8" |
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.
can you move this up a few lines so that it's in alphabetical order?
@@ -324,6 +325,35 @@ export default class Component { | |||
js.map.sourcesContent = [ | |||
this.source | |||
]; | |||
|
|||
if (compile_options.sourceMap) { |
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.
I would probably call this option sourcemap
(all lowercase) in order to match the rollup option name. I think it'd be easier to remember what to set if they're the same
let out: GeneratedStringWithMap; | ||
let last_end = 0; | ||
for (const { offset, length, replacement } of replacements) | ||
{ |
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.
I think this should probably be on the previous line for consistency with the existing code
if (this.generated.length == 0) return other; | ||
if (other.generated.length == 0) return this; | ||
|
||
//combine sources |
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.
there's a mix here with there sometimes being a space after //
and sometimes not. I'd probably always include a space for consistency
@halfnelson said
thanks for the patch! lets get this done .... shamelessly rebased to current master: conflict was: new version allows self-closing /<!--[^]*?-->|<script(\s[^]*?)?(?:>([^]*?)<\/script>|\/>)/gi,
/<!--[^]*?-->|<style(\s[^]*?)?(?:>([^]*?)<\/style>|\/>)/gi, made a mistake on rebase: applied all suggestions by @benmccann further prettified the code (except tests), added comments, .... see commit messages all tests pass should i make a new PR? |
push - what can i do to get this merged? |
dear maintainers - @benmccann @Conduitry etc what are you waiting for? i fixed all suggestions by @benmccann in my fork |
@milahu we're not waiting for anything. We're extremely busy, using the little free time we have at the moment to work on Sapper. Please open a new PR, mention this one and we will review it in due course. |
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.
//shift the first line of the second mapping by the number of columns in the last line of the first | ||
const end = get_end_location(this.generated); | ||
const col_offset = end.column + 1; | ||
const first_line = other_mappings.length == 0 ? [] : other_mappings[0].map(seg => { | ||
const new_seg = seg.slice() as MappingSegment; | ||
new_seg[0] = seg[0] + col_offset; | ||
return new_seg; | ||
}); |
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.
micro optimization:
we can skip column-shifting if last line of first part is empty
= first_source_str.slice(-1) == '\n'
what value has end.column
in that case?
i guess its not -1
but rather line_length - 1
so the old column-shifting would be wrong
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.
done
end.column is zero if last line is empty (pass)
added micro optimization - skip colum shifting if col_offset is zero
return map; | ||
} | ||
|
||
async function replace_async(str: string, re: RegExp, func: (...any) => Promise<GeneratedStringWithMap>): Promise<GeneratedStringWithMap> { |
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.
this fn replace_async
was moved into fn preprocess
to use the global variable filename
.
should we keep this? or change the fn signature of replace_async
to reduce line diffs of patch and to get a pure fn (clean interface)
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.
done
moved fn replace_async out of fn preprocess, added filename and get_location to fn signature
This lives on in #5428 |
What
Adds support for the handling of source maps generated by preprocessors.
Why
Continuing the ongoing effort for a solid Typescript story for Svelte, The Typescript pre-processor and IDE support are good enough for prime time. The main letdown is the debug story. Svelte component source maps ignore the preprocessing that takes place making it impossible to do meaningful debugging via the web dev tools.
How
We use https://github.com/ampproject/remapping a small and synchronous source map combiner (Based on feedback on #1863)
Some manual source map merging is done in the context of Script and Style preprocessor results using a small set of utility functions developed for that purpose.
Sample level tests have been written to prove the flow.
Next Steps
The bundler plugins/loaders will need to be made aware of the sourcemap compiler option and pass in any preprocessor results.