Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task
ehoogeveen-medweb opened this issue Nov 8, 2022 · 4 comments 路 Fixed by #15160
Closed
1 task
Labels
area: comments i: bug i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: generator

Comments

@ehoogeveen-medweb
Copy link
Contributor

馃捇

  • 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.

@babel-bot
Copy link
Collaborator

Hey @ehoogeveen-medweb! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

@liuxingbaoyu liuxingbaoyu self-assigned this Nov 8, 2022
@nicolo-ribaudo
Copy link
Member

#15160 fixes this, I'll add a test

@nicolo-ribaudo
Copy link
Member

Fixed in @babel/generator 7.20.4

@ehoogeveen-medweb
Copy link
Contributor Author

Thanks for the fast turnaround!

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Feb 8, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: comments i: bug i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: generator
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@nicolo-ribaudo @babel-bot @liuxingbaoyu @ehoogeveen-medweb and others