Skip to content

[Bug]: With comments: false, babel inserts an extra newline before the => of an arrow function #15161

@ehoogeveen-medweb

Description

@ehoogeveen-medweb

💻

  • Would you like to work on a fix?

How are you using Babel?

@babel/cli

Input code

var test = (/* placeholder */) => {
  /* Unused */
}

Configuration file name

babel.config.json

Configuration

{
  "sourceType": "script",
  "presets": ["@babel/preset-env"],
  "comments": false
}

Browserslist is set to ["defaults"].

Current and expected behavior

With comments: false, the following output is produced:

var test = (
)
=> {
};

which is not valid code. With comments: true, the following output is produced:

var test = ( /* placeholder */
) => {
  /* Unused */
};

which is valid. With @babel/generator version 7.20.2 and comments: false, the following output is produced:

var test = (
) => {
};

which is valid, so this looks like a regression in version 7.20.3 (from #15135?).

Environment

System:
    OS: Windows 10 10.0.19044
  Binaries:
    Node: 18.12.1 - C:\Program Files\nodejs\node.EXE
    npm: 8.19.3 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    @babel/cli: ^7.19.3 => 7.19.3
    @babel/core: ^7.20.2 => 7.20.2
    @babel/generator: ^7.20.3 => 7.20.3
    @babel/parser: ^7.20.3 => 7.20.3
    @babel/preset-env: ^7.20.2 => 7.20.2

Possible solution

No response

Additional context

Maybe #15160 will also fix this, but there seems to be a gap in testing with comments: false.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions