Skip to content

Fix off-by-one in column numbers when applying source maps - #35

Merged
rmuratov merged 1 commit into
mainfrom
fix-column-off-by-one
Jul 5, 2026
Merged

Fix off-by-one in column numbers when applying source maps#35
rmuratov merged 1 commit into
mainfrom
fix-column-off-by-one

Conversation

@rmuratov

@rmuratov rmuratov commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Closes #22
Closes #26

What

Browsers report stack trace columns as 1-based, while the source-map library 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.ts

  • tryGetOriginalPosition now passes column - 1 (clamped to 0) into originalPositionFor — the library throws on negative columns, and some tools emit 0-based columns in traces.
  • Mapped positions are converted back to 1-based columns for display.
  • The !column guard is replaced with column == null, so column 0 frames are transformed instead of being silently skipped (column === 0 is skipped due to falsy check in tryGetOriginalPosition #26).
  • When the lookup finds nothing, originalPositionFor returns an all-null position; previously that was rendered as at (null:null:null). Such frames now fall back to the original line.

Tests

  • New column numbers test suite drives the full App with a crafted source map (built via SourceMapGenerator) 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 old lib.ts and pass with the fix.
  • regular fixture expectations updated (+1 on mapped columns). Verified against the embedded sourcesContent: 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

@codecov

codecov Bot commented Jul 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (6c700e3) to head (364f614).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying sourcemap-tools with  Cloudflare Pages  Cloudflare Pages

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

View logs

@rmuratov
rmuratov merged commit 5be63c6 into main Jul 5, 2026
4 checks passed
@rmuratov
rmuratov deleted the fix-column-off-by-one branch July 5, 2026 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

column === 0 is skipped due to falsy check in tryGetOriginalPosition Off-by-one in column numbers when applying source maps

1 participant