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

This commit is contained in:
Jason 2021-04-21 21:57:57 +08:00 committed by GitHub
parent adb5adac0c
commit 66181dbe37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View File

@ -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;
@ -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;
this._printedCommentStarts[comment.start] = true;
}
const isBlockComment = comment.type === "CommentBlock";
// Add a newline before and after a block comment, unless explicitly

View File

@ -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 () {