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]: babel generate duplicate comments after cloneNode #14549

Closed
wwsun opened this issue May 13, 2022 · 2 comments · Fixed by #14551
Closed

[Bug]: babel generate duplicate comments after cloneNode #14549

wwsun opened this issue May 13, 2022 · 2 comments · Fixed by #14551
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@wwsun
Copy link

wwsun commented May 13, 2022

How are you using Babel?

@babel/eslint-parser

Input code

import * as t from '@babel/types';
import { parse } from '@babel/parser';
import generator from '@babel/generator';

const code = `
import React from "react";
// 1111
class App extends React.Component {}
`;

describe('babel', () => {
  it('clone and generate', () => {
    expect(
      generator(
        t.cloneNode(
          parse(code, {
            sourceType: 'module',
          }),
          true,
          false,
        ),
        {
          retainLines: true,
        },
      ).code,
    ).toEqual(code);
  });
});

Current and expected behavior

current code: with duplicate comments

import React from "react";
// 1111
// 1111
class App extends React.Component {}

expected code

import React from "react";
// 1111
class App extends React.Component {}

Environment

  "dependencies": {
    "@babel/generator": "^7.17.10",
    "@babel/parser": "^7.17.10",
    "@babel/traverse": "^7.17.10",
    "@babel/types": "^7.17.10",
    "@types/babel__generator": "^7.6.4",
    "@types/babel__traverse": "^7.17.1",
  },
  • node: v16.14.2
  • os: macos

Possible solution

No response

Additional context

No response

@babel-bot
Copy link
Collaborator

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

@nicolo-ribaudo
Copy link
Member

This might be the same bug I was seeing in #14538 (in the "follow up" section).

@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 Aug 24, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants