Skip to content

[Bug]: Wrong logic for printing [no LineTerminator here] after arbitrary node #16737

@nicolo-ribaudo

Description

@nicolo-ribaudo

💻

  • Would you like to work on a fix?

How are you using Babel?

Other (Next.js, Gatsby, vue-cli, ...)

Input code

(
  a * (b // c
)) satisfies c;

Configuration file name

No response

Configuration

/

Current and expected behavior

When parsing and re-printing (with no transforms) Babel generates this code:

a * b // c
satisfies c;

It should instead wrap the LHS in parens, and generate

(
  a * b // c
) satisfies c;

Environment

  • Babel 7.25.3

Possible solution

No response

Additional context

This is quite annoying to fix. We are currently checking if the expression contains any trailing comments, but we should instead check if any right-most descendants of the expression do.

Also, some cases already have parens due to operator precedence, so while fixing this issue we must make sure to avoid double parens, e.g.

(
  a || (b // c
)) satisfies c;

Metadata

Metadata

Assignees

No one assigned

    Labels

    outdatedA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: generator

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions