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: Missing parentheses after line break #16122

Merged
merged 2 commits into from
Nov 28, 2023
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
8 changes: 8 additions & 0 deletions packages/babel-generator/src/printer.ts
Expand Up @@ -1036,6 +1036,14 @@ class Printer {

let val;
if (isBlockComment) {
const { _parenPushNewlineState } = this;
if (
_parenPushNewlineState?.printed === false &&
HAS_NEWLINE.test(comment.value)
) {
this.token("(");
_parenPushNewlineState.printed = true;
}
val = `/*${comment.value}*/`;
if (this.format.indent.adjustMultilineComment) {
const offset = comment.loc?.start.column;
Expand Down
26 changes: 26 additions & 0 deletions packages/babel-generator/test/index.js
Expand Up @@ -1512,6 +1512,32 @@ describe("programmatic generation", function () {
);"
`);
});

it("multi-line leading comment after return compact", () => {
const val = t.identifier("val");
val.leadingComments = [{ type: "CommentBlock", value: "new\nline" }];
expect(
generate(t.returnStatement(val), {
compact: true,
}).code,
).toMatchInlineSnapshot(`
"return(/*new
line*/val);"
`);
});

it("multi-line leading comment after return concise", () => {
const val = t.identifier("val");
val.leadingComments = [{ type: "CommentBlock", value: "new\nline" }];
expect(
generate(t.returnStatement(val), {
concise: true,
}).code,
).toMatchInlineSnapshot(`
"return (/*new
line*/ val );"
`);
});
});
});

Expand Down