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

@babel/generator comment deduplication removes too many comments #12769

Closed
1 task
mischnic opened this issue Feb 5, 2021 · 3 comments · Fixed by #13169 or #13178
Closed
1 task

@babel/generator comment deduplication removes too many comments #12769

mischnic opened this issue Feb 5, 2021 · 3 comments · Fixed by #13169 or #13178
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: generator

Comments

@mischnic
Copy link
Contributor

mischnic commented Feb 5, 2021

Bug Report

  • I would like to work on a fix!

Input Code

import { parse } from "@babel/parser";
import generator from "@babel/generator";
import t from "@babel/types";

const code1 = `
// hello!
a();
`;

const code2 = `
// hello
b();
`;

let ast1 = parse(code1).program;
let ast2 = parse(code2).program;

let ast = t.program([...ast1.body, ...ast2.body]);

console.log(generator.default(ast).code);

Expected behavior

// hello!
a();
// hello
b();

Current behavior

// hello!
a();
b();

Environment

    "@babel/generator": "7.12.15",
    "@babel/parser": "7.12.15",

Possible Solution

Additional context

I was surprised that there are cases where comment exists twice (as leading and trailing), e.g.

if (1) {
  a();
}
// /* */
else {
  b();
}

. Looks like babel-generators "workaround" for this isn't quite right.

Distantly related to parcel-bundler/parcel#5787

@babel-bot
Copy link
Collaborator

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

@kaicataldo
Copy link
Member

This does seem like unexpected/destructive behavior to me, though I think the example given in #13169 (comment) is a more realistic repro case. Curious what the rest of the team thinks.

@kaicataldo
Copy link
Member

I don't think this is fixed yet since we split #13169 into two separate PRs. Reopening for now.

@kaicataldo kaicataldo reopened this Apr 20, 2021
@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 Jul 22, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 22, 2021
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 pkg: generator
Projects
None yet
3 participants