Fix off-by-one in column numbers when applying source maps - #35
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #35 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 9 9
Lines 203 203
Branches 49 51 +2
=========================================
Hits 203 203 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Deploying sourcemap-tools with
|
| Latest commit: |
364f614
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://49d5bb62.sourcemap-tools.pages.dev |
| Branch Preview URL: | https://fix-column-off-by-one.sourcemap-tools.pages.dev |
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.
Closes #22
Closes #26
What
Browsers report stack trace columns as 1-based, while the
source-maplibrary expects 0-based columns on lookup and returns 0-based columns in results. Both directions were passed through unconverted, so lookups could resolve to a neighboring mapping and displayed columns were off by one.Changes in
src/lib.tstryGetOriginalPositionnow passescolumn - 1(clamped to 0) intooriginalPositionFor— the library throws on negative columns, and some tools emit 0-based columns in traces.!columnguard is replaced withcolumn == null, so column0frames are transformed instead of being silently skipped (column === 0 is skipped due to falsy check in tryGetOriginalPosition #26).originalPositionForreturns an all-nullposition; previously that was rendered asat (null:null:null). Such frames now fall back to the original line.Tests
column numberstest suite drives the full App with a crafted source map (built viaSourceMapGenerator) where 0-based columns 10 and 11 map to different original lines, so the off-by-one produces a visibly wrong result. Covers the conversion, the column-0 case, and the unmapped-position fallback. All three tests fail against the oldlib.tsand pass with the fix.regularfixture expectations updated (+1 on mapped columns). Verified against the embeddedsourcesContent: the new 1-based columns point exactly at the start of the call expressions (previousInstance(event),processDispatchQueue(...),fn(a), …), where the old values pointed at the whitespace before them.🤖 Generated with Claude Code