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

fix: don't deduplicate comments with same start index #13169

Merged
merged 1 commit into from Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 0 additions & 6 deletions packages/babel-generator/src/printer.ts
Expand Up @@ -44,7 +44,6 @@ class Printer {
_printStack: Array<t.Node> = [];
_indent: number = 0;
_insideAux: boolean = false;
_printedCommentStarts: any = {};
_parenPushNewlineState: any = null;
_noLineTerminator: boolean = false;
_printAuxAfterOnNextUserNode: boolean = false;
Expand Down Expand Up @@ -598,11 +597,6 @@ class Printer {
if (this._printedComments.has(comment)) return;
this._printedComments.add(comment);

if (comment.start != null) {
if (this._printedCommentStarts[comment.start]) return;
kaicataldo marked this conversation as resolved.
Show resolved Hide resolved
this._printedCommentStarts[comment.start] = true;
}

const isBlockComment = comment.type === "CommentBlock";

// Add a newline before and after a block comment, unless explicitly
Expand Down
14 changes: 14 additions & 0 deletions packages/babel-generator/test/index.js
Expand Up @@ -348,6 +348,20 @@ describe("generation", function () {
const output = generate(type).code;
expect(output).toBe("(infer T)[]");
});

it("should not deduplicate comments with same start index", () => {
const code1 = "/*#__PURE__*/ a();";
const code2 = "/*#__PURE__*/ b();";

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

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

expect(generate(ast).code).toBe(
"/*#__PURE__*/\na();\n\n/*#__PURE__*/\nb();",
);
});
});

describe("programmatic generation", function () {
Expand Down