fix: don't deduplicate comments with same start index (#13169)
This commit is contained in:
parent
adb5adac0c
commit
66181dbe37
@ -44,7 +44,6 @@ class Printer {
|
|||||||
_printStack: Array<t.Node> = [];
|
_printStack: Array<t.Node> = [];
|
||||||
_indent: number = 0;
|
_indent: number = 0;
|
||||||
_insideAux: boolean = false;
|
_insideAux: boolean = false;
|
||||||
_printedCommentStarts: any = {};
|
|
||||||
_parenPushNewlineState: any = null;
|
_parenPushNewlineState: any = null;
|
||||||
_noLineTerminator: boolean = false;
|
_noLineTerminator: boolean = false;
|
||||||
_printAuxAfterOnNextUserNode: boolean = false;
|
_printAuxAfterOnNextUserNode: boolean = false;
|
||||||
@ -598,11 +597,6 @@ class Printer {
|
|||||||
if (this._printedComments.has(comment)) return;
|
if (this._printedComments.has(comment)) return;
|
||||||
this._printedComments.add(comment);
|
this._printedComments.add(comment);
|
||||||
|
|
||||||
if (comment.start != null) {
|
|
||||||
if (this._printedCommentStarts[comment.start]) return;
|
|
||||||
this._printedCommentStarts[comment.start] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const isBlockComment = comment.type === "CommentBlock";
|
const isBlockComment = comment.type === "CommentBlock";
|
||||||
|
|
||||||
// Add a newline before and after a block comment, unless explicitly
|
// Add a newline before and after a block comment, unless explicitly
|
||||||
|
|||||||
@ -348,6 +348,20 @@ describe("generation", function () {
|
|||||||
const output = generate(type).code;
|
const output = generate(type).code;
|
||||||
expect(output).toBe("(infer T)[]");
|
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 () {
|
describe("programmatic generation", function () {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user