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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Extra newlines added to JSX with retainLines option #14868

Closed
1 task
michaldudak opened this issue Aug 22, 2022 · 3 comments · Fixed by #14869
Closed
1 task

[Bug]: Extra newlines added to JSX with retainLines option #14868

michaldudak opened this issue Aug 22, 2022 · 3 comments · Fixed by #14869
Assignees
Labels
area: jsx i: bug i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: generator

Comments

@michaldudak
Copy link

michaldudak commented Aug 22, 2022

💻

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

import * as babel from "@babel/core";

const source = `
export default function Component() {
  return (
    <ul>
      <li>One</li>
      <li>Two</li>
      <li>Three</li>
    </ul>
  );
}`;

const result = babel.transformSync(source, {
  filename: "source.tsx",
  plugins: ["@babel/plugin-syntax-jsx"],
  configFile: false,
  babelrc: false,
  retainLines: true,
});

console.log(result.code);

Configuration file name

No response

Configuration

No response

Current and expected behavior

Additional newlines that don't exist in source are added to the output:

Actual

export default function Component() {
  return (
    <ul>

      <li>One</li>

      <li>Two</li>

      <li>Three</li>

    </ul>);

}

Expected

export default function Component() {
  return (
    <ul>
      <li>One</li>
      <li>Two</li>
      <li>Three</li>
    </ul>
  );
}

Environment

System:
OS: Windows 10 10.0.19044
Binaries:
Node: 16.17.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
npm: 8.15.0 - ~\node_modules.bin\npm.CMD
npmPackages:
@babel/core: 7.17.5 => 7.17.5
@babel/plugin-syntax-jsx: 7.17.12 => 7.17.12

Possible solution

No response

Additional context

This bug was likely introduced in @babel/generator@7.18.9. When I pinned the version to 7.18.7, the output was correct.

@babel-bot
Copy link
Collaborator

Hey @michaldudak! 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.

@michaldudak
Copy link
Author

Thanks for the super-quick fix!

@JLHwung
Copy link
Contributor

JLHwung commented Aug 22, 2022

Fixed in @babel/generator 7.18.13

@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 Nov 22, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: jsx 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.

4 participants