-
Notifications
You must be signed in to change notification settings - Fork 25
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
Empty source map causes sources to be unset #116
Comments
Hi @dummdidumm, I'm a bit confused on what output you expect here. The first map says there are 8 lines, put there are no segments on those lines that point into the original file. The second map says there's 2 lines, with only the first having any content. What generated these sourcemaps? It seems like the output is incorrect, but maybe I'll understand better if you can give a simple reproduction. |
This might be related to #91? In particular, if a mappings line is empty, we consider it to have no content. |
Sorry for the confusion, here is a minimum reproducible with two empty source maps: const result = remapping([
{
version: 3,
names: [],
sources: [ 'foo.js' ],
sourcesContent: [ '' ],
mappings: ''
},
{
version: 3,
mappings: '',
names: [],
sources: [ 'foo.js' ]
}
],
() => null);
// result is { version: 3, mappings: [], sources: [], names: [] }
// expected { version: 3, mappings: [], sources: ['foo.js'], names: [] } |
Ok, so we're expecting And, is there a case where there are 2 sources in a file without any segments? That would be ambiguous. |
I think 2 sources without any segments is a case that should never occur, simply because it makes no sense - how did 2 sources end up in the map if there is nothing to map? So I think this "no mappings" case may be a special one which needs special treatment like if (mapIsEmpty && noSourcesSet) {
sources.push(firstSourceOfEmptyMap)
} I can't quite follow you on the |
We might be able to use the first source (if it's the only source) and Are you using |
I'm using |
I was trying to figure out what was generating the segment-less sourcemap. Appears it's coming from Svelte, in particular it's use of Normally, the AST being printed would contain <h1>decoded-sourcemap</h1>
<div>replace me</div> The So now we have to decide what to do for an empty map on our end. The complication is, where should we end the trace at? Just because the current map only has one source, the next map in our chain could have multiple sources. There's no way for us to associate a empty map into the correct original source in this scenario. I think that means that this case is invalid, and shouldn't be directly supported. |
Re: #116, which has an sourcemap without any segments. There's no point in keeping trailing lines without any segments, and truncating better matches the output from `source-map`.
Closing as intended behavior with the explanation in #116 (comment). |
You know what, I'm changing my mind. Supporting an edits only type of sourcemap would reduce memory usage (no longer need to generate giant The rules for an "editmap" are:
|
note, probably this will only work with the array interface of remapping, where the previous sourcemap is unique
aka overlay map, transparent map, fall through map, partial map .... |
Right. The array map is guaranteed to work, and the function-callback style will only work when there's a single source file. If there's more, we'll throw during building, similar to the array interface's error. |
Thanks for the excellent investigation @jridgewell! I've filed an issue in the Svelte repo with your findings sveltejs/svelte#6092 |
I opened #120 which will partially solve this. I hit a problem with segmentless lines (the This is because lines any number of lines could be removed, or added, or mixed. Without a segment to tell me the respective line in the sourcemap, the remapped segments pointed at meaningless lines in the original source. So I had to require a line marker segment, like what So some work will still be required for Svelte to generate correct sourcemaps. Eg, sveltejs/svelte#6092. |
When combining source maps, and one of the maps is empty, the sources array is empty afterwards.
It produces
{ version: 3, mappings: ';;;;;;;', names: [], sources: [] }
(note the empty sources array. Mappings is also empty, not sure if that is intended).Digging into the source code, I think that in this function the combination is done, and the line where
sources
is updated is never reached in case of empty mappings.The text was updated successfully, but these errors were encountered: