prettier/prettier
View on GitHubExtra parentheses added for nullish coalescing operator in ternary expression
Open
#19,533 opened on Jul 3, 2026
help wantedlang:javascript
Repository metrics
- Stars
- (51,868 stars)
- PR merge metrics
- (Avg merge 6d) (186 merged PRs in 30d)
Description
Prettier v3.9.4 Playground link
--parser babel
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.)