Skip to content

Unnecessary parentheses wrapping for BinaryExpression in UnaryExpression #18802

@Dunqing

Description

@Dunqing

Prettier 3.8.1
Playground link

--parser babel

Input:
All are prettier tests at

!(x || y);
!(/* foo */ x || y);
!(x || y /* foo */);

!(x || y);
!(/* foo */ x || y);
!(x || y /* foo */);

Output:

!(x || y);
!(/* foo */ (x || y));
!((x || y) /* foo */);

Expected output:

!(x || y);
!(/* foo */ x || y);
!(x || y /* foo */);

Note: Same as input

Why?

The added parentheses are unnecessary - !(x || y) already groups the expression clearly.

Also, this is inconsistent: multi-line chains with comments don't get extra parentheses:

!(
  x || // foo
  y // bar
);

<!-- short explanation of expected output -->

Metadata

Metadata

Assignees

No one assigned

    Labels

    locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions