fix(codegen): preserve comments before ConditionalExpression consequent#21325
fix(codegen): preserve comments before ConditionalExpression consequent#21325babu-ch wants to merge 2 commits intooxc-project:mainfrom
ConditionalExpression consequent#21325Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
514b935 to
cc88690
Compare
cc88690 to
d97b033
Compare
| 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; | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
closes #21301
related #20718