Skip to content

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

Merged
nodejs-github-bot merged 2 commits into
nodejs:mainfrom
jackyzha0:sourcemap-trailing-segment
Nov 19, 2026
Merged

nodejs-github-bot merged 2 commits 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.

@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.73%. Comparing base (371ac09) to head (9d5b2db).
⚠️ Report is 21 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66264      +/-   ##
==========================================
+ Coverage   90.71%   90.73%   +0.01%     
==========================================
  Files         801      801              
  Lines      280790   280796       +6     
  Branches    54214    54212       -2     
==========================================
+ Hits       254717   254769      +52     
+ Misses      16242    16205      -37     
+ Partials     9831     9822       -9     
Files with missing lines Coverage Δ
lib/internal/source_map/source_map.js 99.63% <100.00%> (+<0.01%) ⬆️

... and 32 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.

Comment thread lib/internal/source_map/source_map.js Resolved
robobun added a commit to oven-sh/bun that referenced this pull request Nov 2, 2026
The decoder read a one-field segment with no delimiter after it as
Node.js v26.13.0 does: as a mapped segment with zero deltas. In Node.js
that is a read past the end of the string (nodejs/node#66264). ECMA-426
and its test suite give the segment no source.

`mapping::parse` now keeps the same row for every one-field segment,
and `write_vlqs` writes no `;` after one that ends the list.

Tests:
- The rows for the end of the string have their own table.
- The three cases of the test of nodejs/node#66264 and the single-field
  case of the specification tests are added.
- A stack frame in a segment that ends the string keeps its position in
  the loaded file.
- The SIMD tests read the name of a one-field row that lies between
  segments with names.
- The coverage test has a mapped segment after the one-field segment,
  and its map names the loaded file as the source.
@legendecas legendecas added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Nov 13, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 14, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@legendecas legendecas added the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Nov 16, 2026
@github-actions github-actions Bot removed the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Nov 16, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@legendecas legendecas added commit-queue PRs queued for automated landing through the Commit Queue. commit-queue-squash PRs the Commit Queue should land as one squashed commit. labels Nov 17, 2026
@nodejs-github-bot nodejs-github-bot added commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. and removed commit-queue PRs queued for automated landing through the Commit Queue. labels Nov 17, 2026
@nodejs-github-bot

This comment was marked as outdated.

@legendecas

Copy link
Copy Markdown
Member

@jackyzha0 would you mind address the merge conflicts? Thanks!

@legendecas legendecas removed author ready PRs with CI started, the required approvals, and no outstanding review comments. commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. labels Nov 17, 2026
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>
Check hasNext() before reading the optional name field, and add a test
for a segment that has no name.

Signed-off-by: Jacky Zhao <j.zhao2k19@gmail.com>
Assisted-by: Claude Code
@jackyzha0
jackyzha0 force-pushed the sourcemap-trailing-segment branch from 9d71a74 to 9d5b2db Compare November 19, 2026 03:41
@legendecas legendecas added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 19, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 19, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@legendecas legendecas added commit-queue PRs queued for automated landing through the Commit Queue. author ready PRs with CI started, the required approvals, and no outstanding review comments. labels Nov 19, 2026
@nodejs-github-bot
nodejs-github-bot merged commit 0c8797b into nodejs:main Nov 19, 2026
68 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 0c8797b

@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 19, 2026
aduh95 pushed a commit that referenced this pull request Nov 20, 2026
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>
PR-URL: #66264
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
robobun added a commit to oven-sh/bun that referenced this pull request Nov 21, 2026
The decoder read a one-field segment with no delimiter after it as
Node.js v26.13.0 does: as a mapped segment with zero deltas. In Node.js
that is a read past the end of the string (nodejs/node#66264). ECMA-426
and its test suite give the segment no source.

`mapping::parse` now keeps the same row for every one-field segment,
and `write_vlqs` writes no `;` after one that ends the list.

Tests:
- The rows for the end of the string have their own table.
- The three cases of the test of nodejs/node#66264 and the single-field
  case of the specification tests are added.
- A stack frame in a segment that ends the string keeps its position in
  the loaded file.
- The SIMD tests read the name of a one-field row that lies between
  segments with names.
- The coverage test has a mapped segment after the one-field segment,
  and its map names the loaded file as the source.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. commit-queue-squash PRs the Commit Queue should land as one squashed commit. 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.

4 participants