Skip to content

Flatten index sourcemaps returned by plugins - #6601

Merged
lukastaegert merged 6 commits into
rollup:masterfrom
wleeaf:sourcemap-index-maps
Oct 28, 2026
Merged

lukastaegert merged 6 commits into
rollup:masterfrom
wleeaf:sourcemap-index-maps

Conversation

@wleeaf

@wleeaf wleeaf commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

This PR contains:

  • bugfix

Are tests included?

  • yes (bugfixes and features will not be merged without tests)

Breaking Changes?

  • no

List any relevant issue numbers:

Description

ECMA-426 defines index source maps as an alternative to regular maps. They have no mappings field. Instead, sections lists embedded regular maps, each with the generated offset it starts at. When a load, transform or renderChunk hook returns one, decodedSourcemap finds no mappings and replaces it with an empty map, so every mapping of that module is dropped without a warning.

decodedSourcemap now flattens these maps the way the spec's DecodeIndexSourceMap does:

  • Each section's mappings are appended, shifted by the section's offset. The column offset only applies to the section's first line.
  • Each embedded map's own sourceRoot is applied to its sources, because an embedded map "does not inherit any values from the containing index map". An absolute source is left as is, as for regular maps.
  • Sources with the same name are shared unless their contents differ, as when collapsing. This matters for transform maps, where only the first source stands for the previous code.

SourceMapInput now includes index maps, so typed plugins can return them without a cast. An embedded map may omit names.

Regular maps only pay for an extra 'sections' in map check. The new index-sourcemaps sample covers a load map and a transform map. It fails on master because the output map has no sources.

generated with AI

@vercel

vercel Bot commented Oct 26, 2026

Copy link
Copy Markdown

@wleeaf is attempting to deploy a commit to the rollup-js Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown

Thank you for your contribution! ❤️

You can try out this pull request locally by installing Rollup via

npm install wleeaf/rollup#sourcemap-index-maps

Notice: To build the native dependencies, you need Rustup installed; the required nightly toolchain is then picked up automatically from rust-toolchain.toml.

@github-actions
github-actions Bot requested a balanced review from Copilot October 26, 2026 11:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@vercel

vercel Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
rollup Ready Ready Preview Oct 28, 2026 11:22am UTC

Request Review

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Performance report

  • BUILD: 7537ms, 852 MB
    • initialize: 0ms, 24.1 MB
    • generate module graph: 2887ms, 630 MB
      • generate ast: 1473ms (+45ms, +3.2%), 619 MB
    • sort and bind modules: 439ms, 694 MB
    • mark included statements: 4221ms, 852 MB
      • treeshaking pass 1: 2474ms, 826 MB
      • treeshaking pass 2: 493ms, 841 MB
      • treeshaking pass 3: 419ms, 833 MB
      • treeshaking pass 4: 408ms, 825 MB
      • treeshaking pass 5: 410ms, 852 MB
  • GENERATE: 674ms, 884 MB
    • initialize render: 0ms, 852 MB
    • generate chunks: 46ms, 828 MB (+2%)
      • optimize chunks: 0ms, 831 MB
    • render chunks: 614ms, 857 MB
    • transform chunks: 14ms, 884 MB
    • generate bundle: 0ms, 884 MB

@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.31%. Comparing base (6a498da) to head (e180c07).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6601      +/-   ##
==========================================
+ Coverage   98.30%   98.31%   +0.01%     
==========================================
  Files         380      380              
  Lines       13985    14034      +49     
  Branches     2978     2991      +13     
==========================================
+ Hits        13748    13798      +50     
  Misses        194      194              
+ Partials       43       42       -1     

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Embedded maps without names can abort the build, and public plugin types still reject index-map objects.

2 open issues

Review effort: Balanced

Comment thread src/utils/decodedSourcemap.ts Resolved
Comment thread src/utils/decodedSourcemap.ts Resolved

@lukastaegert lukastaegert left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing to consider is that currently, index source maps are not accepted in the user-facing types in rollup.d.ts. If we are to support them, maybe we should add them?

E.g.

export type SourceMapInput = ExistingRawSourceMap | IndexSourceMap | string | null | { mappings: '' };

export interface IndexSourceMap {
	file?: string | undefined;
	sections: {
		map: ExistingRawSourceMap | IndexSourceMap;
		offset: { column: number; line: number };
	}[];
	version: number;
}

names is optional in a source map, so an embedded map without it must
not abort the build.
Typed plugins can now return an index map from load, transform and
renderChunk without a cast.
@wleeaf

wleeaf commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Added in 307673d with your IndexSourceMap shape. SourceMapInput now includes it, the private input type is gone, the transform.ts annotation uses SourceMapInput, and the tests no longer need any. test/typescript has a load hook that returns an index map. A section whose map is itself an index map works too, since decodedSourcemap flattens recursively.

The Copilot finding about names was right: an embedded map without names threw in the section loop. Missing names now count as empty (d8d6414), and the first section of the index-sourcemaps test omits them.

The new index-sourcemaps-names test covers names across sections, a source shared by two sections and a sourceRoot ending in /, which codecov reported as uncovered. The plugin docs now mention index maps next to mappings.

Once both PRs are in, the casts in flattenIndexSourceMap that work around the old sources type are no longer needed; whichever PR is merged second can drop them.

@lukastaegert lukastaegert left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good!

Once both PRs are in, the casts in flattenIndexSourceMap that work around the old sources type are no longer needed; whichever PR is merged second can drop them.

As the other PR is merged, this is not unlocked I suppose?

@wleeaf

wleeaf commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

Yes. I'm merging master into this branch and dropping those casts in flattenIndexSourceMap, and will push it here once the full test run is through.

@wleeaf

wleeaf commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

Merged master and dropped the three casts in flattenIndexSourceMap that worked around the old sources type (e180c07). With #6600 in, the types already allow null there, so no other type change was needed. The full test suite (5592 passing), tsc and the test/typescript types test pass.

@lukastaegert lukastaegert left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

@lukastaegert
lukastaegert added this pull request to the merge queue Oct 28, 2026
Merged via the queue into rollup:master with commit 9414afb Oct 28, 2026
49 checks passed
@github-actions

Copy link
Copy Markdown

This PR has been released as part of rollup@4.66.0. You can test it via npm install rollup.

This branch was successfully deployed

1 active deployment
Preview — e180c074 Deployed Oct 28, 2026 by vercel[bot]
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.

3 participants