Skip to content

fix(codegen): preserve comments before ConditionalExpression consequent#21325

Open
babu-ch wants to merge 2 commits intooxc-project:mainfrom
babu-ch:fix/codegen-consequent-comment-21301
Open

fix(codegen): preserve comments before ConditionalExpression consequent#21325
babu-ch wants to merge 2 commits intooxc-project:mainfrom
babu-ch:fix/codegen-consequent-comment-21301

Conversation

@babu-ch
Copy link
Copy Markdown
Contributor

@babu-ch babu-ch commented Apr 11, 2026

closes #21301

related #20718

@github-actions github-actions Bot added A-codegen Area - Code Generation C-bug Category - Bug labels Apr 11, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 11, 2026

Merging this PR will not alter performance

✅ 48 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing babu-ch:fix/codegen-consequent-comment-21301 (db76b56) with main (e16848e)2

Open in CodSpeed

Footnotes

  1. 3 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.

  2. No successful run was found on main (e8bd51d) during the generation of this report, so e16848e was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@babu-ch babu-ch force-pushed the fix/codegen-consequent-comment-21301 branch from 514b935 to cc88690 Compare April 11, 2026 02:58
@babu-ch babu-ch force-pushed the fix/codegen-consequent-comment-21301 branch from cc88690 to d97b033 Compare April 11, 2026 03:45
@babu-ch babu-ch marked this pull request as ready for review April 11, 2026 03:53
Comment thread tasks/coverage/snapshots/minifier_test262.snap Outdated
@github-actions github-actions Bot added the A-minifier Area - Minifier label Apr 13, 2026
Comment on lines +90 to +101
let outer_start = paren_expr.span.start;
let is_sequence = matches!(&paren_expr.expression, Expression::SequenceExpression(_));
*expr = paren_expr.expression.take_in(ctx.ast);
// For `SequenceExpression`, the surrounding parens are syntactically required
// when re-emitted in expression context, so any comments attached to the outer
// `(` should remain reachable via the inner expression's span.
if is_sequence {
let span = expr.span_mut();
if outer_start < span.start {
span.start = outer_start;
}
}
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.

Does it relate?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes — the codegen change in this PR exposed snapshot failures in minifier_test262. Tracking those down, the root cause was that comments attached to the outer ( were dropped when (seq, expr) got unwrapped here. Without this fix the new comment lookup in ConditionalExpression codegen wouldn't find them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-codegen Area - Code Generation A-minifier Area - Minifier C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

codegen: preserve coverage comments before ConditionalExpression's consequent

3 participants