Keep a line comment in a block construct's operand in the operand
Why
A trailing line comment is printed at the next line break of a breaking group. In a flat operand such as obj.x, obj["m"] or obj->f, that is the break after the block's {, so formatting moved the comment after the { and on the next run into the block. When the comment is still pending at the end of the operand of switch, if, while, for, for..of, for await..of or try, the operand now goes into parentheses with the comment before the ).
modifiedFormat switch operand
switch obj // c.x {| _ => ()}
rescript
switch obj.x { // c| _ => ()}⇝
switch obj.x {// c| _ => ()}
switch ( obj.x // c) {| _ => ()}
Review
- Does code that formatted stably before change? No: an operand only gets parentheses when a line comment in it is still queued at its end, which always moved the comment. No existing snapshot changes.