fix: Ensure identity source map has the same number of fields as the combined source map #122
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi @iFaxity,
In PR #115, we have removed the
file
field in the identity source map because I thought combined source maps from previous plugins do not have it. However, I found it is not always true.The
file
field of a combined source map is added here incombineSourcemaps
function. Below is the call tree fromthis.getCombinedSourcemap
.TransformContext.getCombinedSourcemap
TransformContext#_getCombinedSourcemap
combineSourcemaps
The
combineSourcemaps
function is not called ifTransformContext#sourcemapChain
is empty or has only 1 element.So whether the
file
field exists or not depends on how many previous plugins have output the source maps to be combined, which is practically unpredictable.The solution is quite simple. If the combined source map has a
file
field, the identity source map should.Generally speaking, the two source maps should have the same number of optional fields (
file
,sourceRoot
, andsourceContent
) defined in Source Map Revision 3 format.This PR has the following changes:
file
andsourceRoot
as the combined source mapsourceContent
is sanitized from an identity source map