Skip to content

fix(minifier): preserve annotation comments when inlining single-use variables during DCE#21567

Merged
graphite-app[bot] merged 1 commit intomainfrom
fix/minifier-preserve-annotation-comments-on-inline
Apr 20, 2026
Merged

fix(minifier): preserve annotation comments when inlining single-use variables during DCE#21567
graphite-app[bot] merged 1 commit intomainfrom
fix/minifier-preserve-annotation-comments-on-inline

Conversation

@Dunqing
Copy link
Copy Markdown
Member

@Dunqing Dunqing commented Apr 20, 2026

When substitute_single_use_symbol_in_expression inlines a single-use const variable, it replaced the identifier with the init expression using replacement.take_in(), which kept the replacement's original span from the variable declaration site. Since comments are associated with AST nodes via the attached_to field (keyed by span start), @vite-ignore and webpackIgnore comments attached to the original identifier were lost because the replacement expression had a different span start.

This only manifested in DCE mode (used by rolldown) because in full optimization mode, inline_identifier_reference runs first and correctly preserves the span via ctx.value_to_expr(expr.span(), ...).

The fix preserves the target identifier's span on the replacement expression after substitution.

Fixes rolldown/rolldown#8248
Closes vitejs/vite#21950

Copy link
Copy Markdown
Member Author

Dunqing commented Apr 20, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent changes, fast-track this PR to the front of the merge queue

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 20, 2026

Merging this PR will not alter performance

✅ 44 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing fix/minifier-preserve-annotation-comments-on-inline (c9588f4) with main (50e9d26)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Dunqing Dunqing marked this pull request as ready for review April 20, 2026 07:57
@Dunqing Dunqing requested a review from sapphi-red April 20, 2026 07:57
@Dunqing
Copy link
Copy Markdown
Member Author

Dunqing commented Apr 20, 2026

This is actually similar to what the workaround at vitejs/vite#21950 (comment) does.

@Dunqing Dunqing added the 0-merge Merge with Graphite Merge Queue label Apr 20, 2026
Copy link
Copy Markdown
Member Author

Dunqing commented Apr 20, 2026

Merge activity

…variables during DCE (#21567)

When `substitute_single_use_symbol_in_expression` inlines a single-use `const` variable, it replaced the identifier with the init expression using `replacement.take_in()`, which kept the replacement's original span from the variable declaration site. Since comments are associated with AST nodes via the `attached_to` field (keyed by span start), `@vite-ignore` and `webpackIgnore` comments attached to the original identifier were lost because the replacement expression had a different span start.

This only manifested in DCE mode (used by rolldown) because in full optimization mode, `inline_identifier_reference` runs first and correctly preserves the span via `ctx.value_to_expr(expr.span(), ...)`.

The fix preserves the target identifier's span on the replacement expression after substitution.

Fixes rolldown/rolldown#8248
Closes vitejs/vite#21950
@graphite-app graphite-app Bot force-pushed the fix/minifier-preserve-annotation-comments-on-inline branch from c9588f4 to 385eb94 Compare April 20, 2026 12:10
@graphite-app graphite-app Bot merged commit 385eb94 into main Apr 20, 2026
27 checks passed
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Apr 20, 2026
@graphite-app graphite-app Bot deleted the fix/minifier-preserve-annotation-comments-on-inline branch April 20, 2026 12:14
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.

vite-rolldown removes @vite-ignore comments [Bug]: /*@vite-ignore*/ is incorrectly stripped

2 participants