Skip to content

Parentheses around nullish coalescing operator within conditional expression #4873

@mariusschulz

Description

@mariusschulz

Prettier 1.13.5
Playground link

--parser babylon

Input:

const value = condition ? (nullableValue ?? fallbackValue) : nonNullableValue;

Output:

const value = condition ? nullableValue ?? fallbackValue : nonNullableValue;

Expected behavior:

I think it would be better if Prettier preserved the parentheses around the arguments of the nullish coalescing operator if nested within a conditional expression:

const value = condition ? (nullableValue ?? fallbackValue) : nonNullableValue;

My concern is that the precedence of ?? isn't immediately obvious, and I think that parentheses would improve readability here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedWe're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue!lang:javascriptIssues affecting JSlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions