Prevent comment after head of member chain move around (#20125)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
fisker Cheungandautofix-ci[bot] authored and GitHub committed 2026-09-21 23:20:48 +08:00
1 parent 0bab82ffb8
commit 6bc99db278
4 files changed
+56 -5

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
#### Prevent comment after head of member chain move around (#20125 by @fisker)
<!-- prettier-ignore -->
```jsx
// Input
x // comment
.foo()
// Prettier stable
x.foo(); // comment
// Prettier main
x // comment
.foo();
```
+6 -5
View File
@@ -293,11 +293,12 @@ function printMemberChain(path, options, print) {
if (groups[0].length === 1) {
const firstNode = groups[0][0].node;
return (
firstNode.type === "ThisExpression" ||
(firstNode.type === "Identifier" &&
(isFactory(firstNode.name) ||
(isExpressionStatement && isShort(firstNode.name)) ||
hasComputed))
(firstNode.type === "ThisExpression" ||
(firstNode.type === "Identifier" &&
(isFactory(firstNode.name) ||
(isExpressionStatement && isShort(firstNode.name)) ||
hasComputed))) &&
!hasComment(firstNode, CommentCheckFlags.Trailing)
);
}
@@ -1281,6 +1281,33 @@ s.get(u)?.trigger({
================================================================================
`;
exports[`issue-18523.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80 (default) |
=====================================input======================================
a //
.bla()
abc //
.bla()
this //
.bla()
=====================================output=====================================
a //
.bla();
abc //
.bla();
this //
.bla();
================================================================================
`;
exports[`logical.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
@@ -0,0 +1,8 @@
a //
.bla()
abc //
.bla()
this //
.bla()