Repository navigation
Fix originalPositionFor at the start of an index map section - #99
Merged
Merged
Conversation
The section search compared the needle's 0-based column with the section's 1-based generatedOffset.generatedColumn, so a lookup at a section's exact first position landed in the previous section (or none) and returned nulls. Fixes #82
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #82.
The bug
In an index map,
originalPositionForreturned all-null fields for the exact position where a section starts, even when the section has a mapping there. One column later worked. With the map from the issue:a.js1:0b.js1:0a.js1:2a.js1:2b.js1:0b.js1:0The "after" column matches trace-mapping 0.3.31 for the same map. source-map 0.6.1 has the same bug: the code comes from there.
Cause
IndexedSourceMapConsumer#originalPositionForfirst binary-searches for the section that contains the position. Its comparator subtractedsection.generatedOffset.generatedColumn, which is stored 1-based (offset.column + 1), from the needle's 0-based column. At a section's first column the comparator returned -1 instead of 0, so the search picked the previous section, or none. The code that then converts the needle into the section's coordinates already subtracts the 1; this does the same in the comparator.Not fixed here
A separate bug in the same area: the column offset of a section whose
offset.lineis above 0 is applied to the section's second line instead of its first, in decoding (lib/source-map-consumer.js:1267) and ingeneratedPositionFor(line 1210).test/test-ecma426-conformance.jshas a todo test for it.Testing
New regression test with the map from the issue.
pnpm test(227 tests),pnpm test:coverageandpnpm format:checkpass on Node 26.13.1.