Skip to content

sourcemaps: don't map a trailing generated-only segment - #66264

Open
jackyzha0 wants to merge 1 commit into
nodejs:mainfrom
jackyzha0:sourcemap-trailing-segment
Open

jackyzha0 wants to merge 1 commit into
nodejs:mainfrom
jackyzha0:sourcemap-trailing-segment

Conversation

@jackyzha0

@jackyzha0 jackyzha0 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Why

The mappings parser detects a segment that has only a generated column by peeking at the next character.

At the end of the mappings string the peek returns an empty string, which is not a separator, so a final generated-only segment is decoded with phantom zero deltas and inherits the source, line, and column of the segment before it.

With --enable-source-maps, stack frames in code after the last mapped segment are then attributed to the last mapped source.

repro.js:

vendor();
function vendor() { throw new Error('boom'); }
//# sourceMappingURL=repro.js.map

repro.js.map:

{"version":3,"sources":["app.ts"],"names":[],"mappings":"AAAA;A"}
$ node --enable-source-maps repro.js
Error: boom
    at vendor (app.ts:1:1)

With this change:

$ node --enable-source-maps repro.js
Error: boom
    at vendor (repro.js:2:27)

What Changed

Check for the end of the string before reading source fields.

Disclaimer: this PR was written with the help of Opus 5.5 but I have personally read, reviewed, and validated the changes.

The mappings parser detects a segment that has only a generated column
by peeking at the next character. At the end of the mappings string the
peek returns an empty string, which is not a separator, so a final
generated-only segment is decoded with phantom zero deltas and inherits
the source, line, and column of the segment before it. With
--enable-source-maps, stack frames in code after the last mapped
segment are then attributed to the last mapped source.

Check for the end of the string before reading source fields.

Signed-off-by: Jacky Zhao <j.zhao2k19@gmail.com>
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. source maps Issues and PRs related to source map support. labels Sep 24, 2026
@codecov

codecov Bot commented Sep 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.28%. Comparing base (e7d8ab5) to head (be06031).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66264      +/-   ##
==========================================
- Coverage   90.30%   90.28%   -0.02%     
==========================================
  Files         789      789              
  Lines      272880   272881       +1     
  Branches    52110    52113       +3     
==========================================
- Hits       246418   246365      -53     
- Misses      16912    16975      +63     
+ Partials     9550     9541       -9     
Files with missing lines Coverage Δ
lib/internal/source_map/source_map.js 99.48% <100.00%> (+<0.01%) ⬆️

... and 27 files with indirect coverage changes

🚀 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. source maps Issues and PRs related to source map support.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants