You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Formatter moves a line comment in a switch/if/loop operand into the block #9060
A line comment inside the operand of switch, if, while, for, for..of, for await..of or try moves when formatting: first after the {, then on the next run into the block. Formatting is not idempotent.
switchobj// c
.x {
| _=> ()
}
First run:
switchobj.x { // c
| _=> ()
}
Second run, the comment is now in the block:
switchobj.x {
// c
| _=> ()
}
The same happens with if, while, for..of, for await..of, try (where the comment moves past catch) and with these operands:
for i in 0 // c\nto n {: the comment moves past to n and into the loop body
switch f(// c\nx) { is fine, because the arguments group breaks after the comment.
Expected: the comment stays in the operand, for example
switch (
obj.x// c
) {
| _=> ()
}
Cause: the printer queues a trailing line comment as a line suffix and prints it at the next line break of a breaking group. The field access, object get, pipe or binary expression is printed flat with no line break after the comment, so the first break is the one after the block's {.
Found while reviewing #8906, which is about a related case, but this bug is already on master.
Activity
Keep a line comment in an operand that has its own parentheses
Keep a line comment in a block construct's operand in the operand (#9061