Skip to content

fix: incorrect sourcemap when postBanner/postFooter is used with shebang#8459

Merged
shulaoda merged 5 commits intomainfrom
copilot/fix-postbanner-sourcemap-issue
Feb 26, 2026
Merged

fix: incorrect sourcemap when postBanner/postFooter is used with shebang#8459
shulaoda merged 5 commits intomainfrom
copilot/fix-postbanner-sourcemap-issue

Conversation

Copy link
Contributor

Copilot AI commented Feb 25, 2026

When postBanner/postFooter is combined with a source file containing a shebang, the output sourcemap's generated line numbers are off by 1.

Root cause: post_banner_footer splits chunk content into the shebang and rest_content, attaching the original sourcemap to rest_content. The sourcemap was generated for the full content (shebang at line 0), so all token dst_line values are 1-indexed relative to rest_content. SourceJoiner's line_offset then compounds the error rather than correcting it.

Changes

  • crates/rolldown_sourcemap/src/lib.rs: Add adjust_sourcemap_dst_lines(sourcemap, subtract) — creates an adjusted sourcemap with all token dst_line values decremented by subtract.
  • crates/rolldown/src/stages/generate_stage/post_banner_footer.rs: When a shebang is present and a sourcemap exists, call adjust_sourcemap_dst_lines(source_map, 1) before handing the map to SourceJoiner, so the map is correctly anchored to rest_content's line 0.
  • packages/rolldown/tests/fixtures/function/post-banner/sourcemap-with-shebang/: New test fixture asserting correct sourcemap mappings when postBanner is used with a shebang-bearing entry.

Example — with postBanner: '/* banner */' and entry #!/usr/bin/env node\nconsole.log('hello');:

Line 0: #!/usr/bin/env node      ← shebang
Line 1: /* banner */             ← postBanner
Line 2: //#region ...
Line 3: console.log("hello");    ← sourcemap must point here, not line 4

Before the fix the sourcemap mapped console.log to line 4; after the fix it correctly maps to line 3.

Original prompt

This section details on the original issue you should resolve

<issue_title>Follow up issues of postBanner/Footer</issue_title>
<issue_description>Caused by #7583

<agent_instructions>Correct the incorrect postBanner/Footer sourcemap</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@hyf0 > I tried the latest version and found that there were extra blank lines between `postBanner` and shebang in the output. [example](https://stackblitz.com/edit/vitejs-vite-zl8hy4bz?file=package.json)

Feel free to open a PR to fix it.</comment_new>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@netlify
Copy link

netlify bot commented Feb 25, 2026

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit bef6dd7
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/69a00fad0775e300099f6977

Copilot AI changed the title [WIP] Fix incorrect sourcemap for postBanner/Footer Fix incorrect sourcemap when postBanner/postFooter is used with shebang Feb 25, 2026
Copilot AI requested a review from shulaoda February 25, 2026 07:09
Copilot AI and others added 3 commits February 26, 2026 17:01
…shebang

Co-authored-by: shulaoda <165626830+shulaoda@users.noreply.github.com>
@shulaoda shulaoda force-pushed the copilot/fix-postbanner-sourcemap-issue branch from 255a2ff to f7357d3 Compare February 26, 2026 09:01
@shulaoda shulaoda changed the title Fix incorrect sourcemap when postBanner/postFooter is used with shebang fix: incorrect sourcemap when postBanner/postFooter is used with shebang Feb 26, 2026
@shulaoda shulaoda requested a review from Copilot February 26, 2026 09:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes an off-by-one error in generated sourcemaps when postBanner/postFooter is used on chunks whose entry source contains a shebang, by re-anchoring the chunk’s sourcemap to the post-shebang “rest content”.

Changes:

  • Added a helper to shift/strip destination line numbers in a SourceMap by a fixed number of lines.
  • Applied the helper during post_banner_footer when splitting out a shebang so the sourcemap matches the sliced content.
  • Added a new fixture asserting the expected output ordering and sourcemap mappings for postBanner + shebang.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
crates/rolldown_sourcemap/src/lib.rs Adds adjust_sourcemap_dst_lines to decrement all token dst_line values after removing a prefix line.
crates/rolldown/src/stages/generate_stage/post_banner_footer.rs Adjusts sourcemap lines by 1 when a shebang is split off before concatenation.
packages/rolldown/tests/fixtures/function/post-banner/sourcemap-with-shebang/main.js New shebang-bearing input fixture.
packages/rolldown/tests/fixtures/function/post-banner/sourcemap-with-shebang/_config.ts New test verifying banner placement and sourcemap mappings stability.

@shulaoda shulaoda marked this pull request as ready for review February 26, 2026 09:19
Copilot AI review requested due to automatic review settings February 26, 2026 09:19
@shulaoda shulaoda requested review from hyf0 and sapphi-red February 26, 2026 09:20
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@github-actions
Copy link
Contributor

Benchmarks Rust

  • target: main(d1f7e79)
  • pr: copilot/fix-postbanner-sourcemap-issue(bef6dd7)
group                                                        pr                                     target
-----                                                        --                                     ------
bundle/bundle@multi-duplicated-top-level-symbol              1.00     66.3±1.58ms        ? ?/sec    1.00     66.4±1.31ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-sourcemap    1.00     70.8±1.21ms        ? ?/sec    1.02     72.1±1.86ms        ? ?/sec
bundle/bundle@rome_ts                                        1.00     96.9±1.72ms        ? ?/sec    1.01     97.9±1.73ms        ? ?/sec
bundle/bundle@rome_ts-sourcemap                              1.00    106.8±1.57ms        ? ?/sec    1.01    107.4±1.71ms        ? ?/sec
bundle/bundle@threejs                                        1.00     36.7±1.36ms        ? ?/sec    1.02     37.4±2.48ms        ? ?/sec
bundle/bundle@threejs-sourcemap                              1.00     39.2±0.83ms        ? ?/sec    1.01     39.6±0.73ms        ? ?/sec
bundle/bundle@threejs10x                                     1.01    364.0±5.45ms        ? ?/sec    1.00    359.6±6.59ms        ? ?/sec
bundle/bundle@threejs10x-sourcemap                           1.02    416.4±6.63ms        ? ?/sec    1.00    409.0±4.90ms        ? ?/sec
scan/scan@rome_ts                                            1.01     76.1±2.18ms        ? ?/sec    1.00     75.6±2.12ms        ? ?/sec
scan/scan@threejs                                            1.04     27.6±1.69ms        ? ?/sec    1.00     26.7±0.39ms        ? ?/sec
scan/scan@threejs10x                                         1.02    266.9±3.41ms        ? ?/sec    1.00    261.1±2.50ms        ? ?/sec

@shulaoda shulaoda merged commit 6774878 into main Feb 26, 2026
41 checks passed
@shulaoda shulaoda deleted the copilot/fix-postbanner-sourcemap-issue branch February 26, 2026 11:03
@github-actions github-actions bot mentioned this pull request Feb 26, 2026
shulaoda added a commit that referenced this pull request Feb 26, 2026
## [1.0.0-rc.6] - 2026-02-26

### 💥 BREAKING CHANGES

- css: remove `css_entry_filenames` , `css_chunk_filenames` and related code (#8402) by @hyf0
- css: drop builtin CSS bundling to explore alternative solutions (#8399) by @hyf0

### 🚀 Features

- rust/data-url: use hash as id for data url modules to prevent long string overhead (#8420) by @hyf0
- validate bundle stays within output dir (#8441) by @sapphi-red
- rust: support `PluginOrder::PinPost` (#8417) by @hyf0
- support `ModuleType:Copy` (#8407) by @hyf0
- expose `ESTree` types from `rolldown/utils` (#8400) by @sapphi-red

### 🐛 Bug Fixes

- incorrect sourcemap when postBanner/postFooter is used with shebang (#8459) by @Copilot
- resolver: disable node_path option to align ESM resolver behavior (#8472) by @sapphi-red
- parse `.js` within `"type": "commonjs"` as ESM for now (#8470) by @sapphi-red
- case-insensitive filename conflict detection for chunk deduplication (#8458) by @Copilot
- prevent inlining CJS exports that are mutated by importers (#8456) by @IWANABETHATGUY
- parse `.cjs` / `.cts` / `.js` within `"type": "commonjs"` as CommonJS (#8455) by @sapphi-red
- plugin/copy-module: correct hooks' priority (#8423) by @hyf0
- plugin/chunk-import-map: ensure `render_chunk_meta` run after users plugin (#8422) by @hyf0
- rust: correct hooks order of `DataUriPlugin` (#8418) by @hyf0
- `jsx.preserve` should also considering tsconfig json preserve (#8324) by @IWANABETHATGUY
- `deferred_scan_data.rs "Should have resolved id: NotFound"` error (#8379) by @sapphi-red
- cli: require value for `--dir`/`-d` and `--file`/`-o` (#8378) by @Copilot
- dev: avoid mutex deadlock caused by inconsistent lock order (#8370) by @sapphi-red

### 🚜 Refactor

- watch: rename TaskStart/TaskEnd to BundleStart/BundleEnd (#8463) by @hyf0
- rust: rename `rolldown_plugin_data_uri` to `rolldown_plugin_data_url` (#8421) by @hyf0
- bindingify-build-hook: extract helper for PluginContextImpl (#8438) by @ShroXd
- give source loading a proper name (#8436) by @IWANABETHATGUY
- ban holding DashMap refs across awaits (#8362) by @sapphi-red

### 📚 Documentation

- add glob pattern usage example to input option (#8469) by @IWANABETHATGUY
- remove `https://rolldown.rs` from links in reference docs (#8454) by @sapphi-red
- mention execution order issue in `output.codeSplitting` docs (#8452) by @sapphi-red
- clarify `output.comments` behavior a bit (#8451) by @sapphi-red
- replace npmjs package links with npmx.dev (#8439) by @Boshen
- reference: add `Exported from` for values / types exported from subpath exports (#8394) by @sapphi-red
- add JSDocs for APIs exposed from subpath exports (#8393) by @sapphi-red
- reference: generate reference pages for APIs exposed from subpath exports (#8392) by @sapphi-red
- avoid pipe character in codeSplitting example to fix broken rendering (#8391) by @IWANABETHATGUY

### ⚡ Performance

- avoid redundant PathBuf allocations in resolve paths (#8435) by @Brooooooklyn
- bump to `sugar_path@2` (#8432) by @hyf0
- use flag-based convergence detection in include_statements (#8412) by @Brooooooklyn

### 🧪 Testing

- execute `_test.mjs` even if `executeOutput` is false (#8398) by @sapphi-red
- add retry to tree-shake/module-side-effects-proxy4 as it is flaky (#8397) by @sapphi-red
- avoid `expect.assertions()` as it is not concurrent test friendly (#8383) by @sapphi-red
- disable `mockReset` option (#8382) by @sapphi-red
- fix flaky failure caused by concurrent resolveId calls (#8381) by @sapphi-red

### ⚙️ Miscellaneous Tasks

- deps: update dependency rollup to v4.59.0 [security] (#8471) by @renovate[bot]
- ai/design: add design doc about watch mode (#8453) by @hyf0
- deps: update oxc resolver to v11.19.0 (#8461) by @renovate[bot]
- ai: introduce progressive spec-driven development pattern (#8446) by @hyf0
- deprecate output.legalComments (#8450) by @sapphi-red
- deps: update dependency oxlint-tsgolint to v0.15.0 (#8448) by @renovate[bot]
- ai: make CLAUDE.md a symlink of AGENTS.md (#8445) by @hyf0
- deps: update rollup submodule for tests to v4.59.0 (#8433) by @sapphi-red
- deps: update test262 submodule for tests (#8434) by @sapphi-red
- deps: update oxc to v0.115.0 (#8430) by @renovate[bot]
- deps: update oxc apps (#8429) by @renovate[bot]
- deps: update npm packages (#8426) by @renovate[bot]
- deps: update rust crate owo-colors to v4.3.0 (#8428) by @renovate[bot]
- deps: update github-actions (#8424) by @renovate[bot]
- deps: update rust crates (#8425) by @renovate[bot]
- deps: update oxc resolver to v11.18.0 (#8406) by @renovate[bot]
- deps: update dependency oxlint-tsgolint to v0.14.2 (#8405) by @renovate[bot]
- ban `expect.assertions` in all fixture tests (#8395) by @sapphi-red
- deps: update oxc apps (#8389) by @renovate[bot]
- ban `expect.assertions` in fixture tests (#8387) by @sapphi-red
- enable lint for `_config.ts` files (#8386) by @sapphi-red
- deps: update dependency oxlint-tsgolint to v0.14.1 (#8385) by @renovate[bot]

Co-authored-by: shulaoda <165626830+shulaoda@users.noreply.github.com>
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.

Follow up issues of postBanner/Footer

4 participants