Prettier v3.9.4
Playground link
Input:
const value = condition ? (
<Example /> // comment
) : (
"alpha" ?? "bravo"
);
const value = condition ? (
<Example /> // comment
) : (
"alpha" + "bravo"
);
Output:
const value = condition ? (
<Example /> // comment
) : (
("alpha" ?? "bravo")
);
const value = condition ? (
<Example /> // comment
) : (
"alpha" + "bravo"
);
Expected output:
const value = condition ? (
<Example /> // comment
) : (
"alpha" ?? "bravo"
);
const value = condition ? (
<Example /> // comment
) : (
"alpha" + "bravo"
);
(Same as input, unchanged.)
Why?
The nullish coalescing operator ends up in double parentheses even though the second (inner) pair is completely unnecessary. The second example shows the inconsistency with other operators. (The comment isn't actually necessary for the reproduction, it's just an easy way to force breaking, but a long line works just as well.)
Prettier v3.9.4
Playground link
Input:
Output:
Expected output:
(Same as input, unchanged.)
Why?
The nullish coalescing operator ends up in double parentheses even though the second (inner) pair is completely unnecessary. The second example shows the inconsistency with other operators. (The comment isn't actually necessary for the reproduction, it's just an easy way to force breaking, but a long line works just as well.)