fix(minifier): preserve annotation comments when inlining single-use variables during DCE#21567
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via 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. |
Merging this PR will not alter performance
Comparing Footnotes
|
|
This is actually similar to what the workaround at vitejs/vite#21950 (comment) does. |
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
c9588f4 to
385eb94
Compare

When
substitute_single_use_symbol_in_expressioninlines a single-useconstvariable, it replaced the identifier with the init expression usingreplacement.take_in(), which kept the replacement's original span from the variable declaration site. Since comments are associated with AST nodes via theattached_tofield (keyed by span start),@vite-ignoreandwebpackIgnorecomments 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_referenceruns first and correctly preserves the span viactx.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