Skip to content

Commit

Permalink
Fix if there is a previous token
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Nov 8, 2022
1 parent b0b7c7a commit d329301
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 23 deletions.
8 changes: 6 additions & 2 deletions packages/babel-generator/src/printer.ts
Expand Up @@ -587,6 +587,8 @@ class Printer {
) {
if (!node) return;

this._endsWithInnerRaw = false;

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

Expand Down Expand Up @@ -635,9 +637,11 @@ class Printer {
} else {
shouldPrintParens = needsParens(node, parent, this._printStack);
}
if (shouldPrintParens) this.token("(");
if (shouldPrintParens) {
this.token("(");
this._endsWithInnerRaw = false;
}

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

this._printLeadingComments(node, parent);
Expand Down
@@ -0,0 +1,3 @@
1 + ((/* c */) => {});

(function /* c */ () {});
@@ -0,0 +1,2 @@
1 + (( /* c */) => {});
(function /* c */ () {});
21 changes: 0 additions & 21 deletions packages/babel-generator/test/index.js
Expand Up @@ -1055,27 +1055,6 @@ 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 d329301

Please sign in to comment.