Skip to content

Parentheses around nullish coalescing operator (??) within logical expressions #6403

@mroch

Description

@mroch

in the latest stage 3 draft, nullish coalescing can no longer immediately contain, or be contained within, && and ||: https://tc39.es/proposal-nullish-coalescing/

so, foo ?? bar || baz is illegal, but you can write (foo ?? bar) || baz.

Playground link

Input:

(foo ?? bar) || baz

Output:

foo ?? bar || baz

Expected behavior:

(foo ?? bar) || baz

Flow v0.106.0 implements the change to the spec, making this a parse error. So, prettier will turn valid code into invalid code by removing the parens.

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:javascriptIssues affecting JSlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions