-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Leading comment in parenthesized return expression moves to incorrect place in member chain #18843
Copy link
Copy link
Labels
area:commentsIssues with how Prettier prints commentsIssues with how Prettier prints commentslang:javascriptIssues affecting JSIssues affecting JS
Description
Prettier 3.8.1
Playground link
--parser babel-tsInput:
prettier/tests/format/js/comments/return-statement.js
Lines 82 to 87 in 812a4d0
| function memberInAndOutWithCalls() { | |
| return ( | |
| // Reason for a | |
| aFunction.b() | |
| ).c.d() | |
| } |
function memberInAndOutWithCalls() {
return (
// Reason for a
aFunction.b()
).c.d()
}Output:
function memberInAndOutWithCalls() {
return (
aFunction
.b// Reason for a
()
.c.d()
);
}Expected output:
function memberInAndOutWithCalls() {
return (
// Reason for a
aFunction.b()
).c.d();
}Why?
The comment // Reason for a was a leading comment inside parentheses, intended to explain the entire expression being returned. The output moves it to between .b and (), which loses the original intent of explaining "reason for a" (the whole expression)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area:commentsIssues with how Prettier prints commentsIssues with how Prettier prints commentslang:javascriptIssues affecting JSIssues affecting JS