Skip to content

Commit

Permalink
Don't print inner comments as leading when wrapping in ()
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Nov 5, 2022
1 parent ce09a26 commit a71b1b4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
3 changes: 1 addition & 2 deletions packages/babel-generator/src/printer.ts
Expand Up @@ -586,8 +586,6 @@ class Printer {
) {
if (!node) return;

this._endsWithInnerRaw = false;

const nodeType = node.type;
const format = this.format;

Expand Down Expand Up @@ -638,6 +636,7 @@ class Printer {
}
if (shouldPrintParens) this.token("(");

this._endsWithInnerRaw = false;
this._lastCommentLine = 0;

this._printLeadingComments(node, parent);
Expand Down
21 changes: 21 additions & 0 deletions packages/babel-generator/test/index.js
Expand Up @@ -1055,6 +1055,27 @@ describe("programmatic generation", function () {
const output = generate(exportDefaultDeclaration).code;
expect(output).toBe("export default (function () {});");
});

it("inner comments are not printed after leading parenthesis", () => {
const functionExpression = t.functionExpression(
null,
[],
t.blockStatement([]),
);
functionExpression.innerComments = [
{
type: "CommentBlock",
value: "foo",
},
];
const stmt = t.expressionStatement(functionExpression);
const output = generate(stmt).code;
expect(output).toMatchInlineSnapshot(`
"(function
/*foo*/
() {});"
`);
});
});

describe("class expressions", () => {
Expand Down

0 comments on commit a71b1b4

Please sign in to comment.