Improve handleParenthesizedExpressionTrailingComment (#19281)

This commit is contained in:
fisker Cheung authored and GitHub committed 2026-06-04 02:22:52 +08:00
1 parent f941cb6364
commit 296fbe6b7f
3 files changed
+22 -3

No files matched your search

+1 -3
View File
@@ -1078,7 +1078,6 @@ function handleParenthesizedExpressionTrailingComment({
enclosingNode,
precedingNode,
followingNode,
text,
}) {
if (!followingNode && enclosingNode) {
if (
@@ -1102,8 +1101,7 @@ function handleParenthesizedExpressionTrailingComment({
enclosingNode.argument === precedingNode) ||
(isSequence &&
enclosingNode.type === "AssignmentExpression" &&
enclosingNode.right === precedingNode)) &&
getNextNonSpaceNonCommentCharacter(text, locEnd(comment)) === ")"
enclosingNode.right === precedingNode))
) {
addTrailingComment(
isSequence ? precedingNode.expressions.at(-1) : precedingNode.right,
@@ -133,15 +133,19 @@ parsers: ["babel", "flow", "typescript"]
printWidth: 80 (default) |
=====================================input======================================
const x1 = (a, b, c /* comment */);
const x12 = (a, b, c) /* comment */;
const x2 = (a = c /* comment */);
const x22 = (a = c) /* comment */;
(a, b, c /* comment */);
(a, b, c) /* comment */;
(a, b, c /* comment */
);
(a, b, c
/* comment */
);
(a = c /* comment */);
(a = c) /* comment */;
(a = c /* comment */
);
(a = c
@@ -155,6 +159,7 @@ const x2 = (a = c /* comment */);
);
(foo() /* comment */);
(foo()) /* comment */;
(foo()
/* comment */
);
@@ -162,23 +167,29 @@ const x2 = (a = c /* comment */);
);
assigned = (a, b, c /* comment */);
assigned = (a, b, c) /* comment */;
// assigned = (a = c /* comment */);
function f() {
return (a, b, c /* comment */);
return (a, b, c) /* comment */;
return (a = c /* comment */);
}
=====================================output=====================================
const x1 = (a, b, c /* comment */);
const x12 = (a, b, c); /* comment */
const x2 = (a = c /* comment */);
const x22 = (a = c); /* comment */
(a, b, c); /* comment */
(a, b, c); /* comment */
(a, b, c); /* comment */
(a, b, c);
/* comment */
a = c; /* comment */
a = c; /* comment */
a = c; /* comment */
a = c;
/* comment */
({ a } = c); /* comment */
@@ -186,16 +197,19 @@ a = c;
/* comment */
({ a } = c); /* comment */
foo(); /* comment */
foo(); /* comment */
foo();
/* comment */
foo(); /* comment */
assigned = (a, b, c /* comment */);
assigned = (a, b, c); /* comment */
// assigned = (a = c /* comment */);
function f() {
return (a, b, c /* comment */);
return (a, b, c); /* comment */
return (a = c /* comment */);
}
@@ -1,13 +1,17 @@
const x1 = (a, b, c /* comment */);
const x12 = (a, b, c) /* comment */;
const x2 = (a = c /* comment */);
const x22 = (a = c) /* comment */;
(a, b, c /* comment */);
(a, b, c) /* comment */;
(a, b, c /* comment */
);
(a, b, c
/* comment */
);
(a = c /* comment */);
(a = c) /* comment */;
(a = c /* comment */
);
(a = c
@@ -21,6 +25,7 @@ const x2 = (a = c /* comment */);
);
(foo() /* comment */);
(foo()) /* comment */;
(foo()
/* comment */
);
@@ -28,9 +33,11 @@ const x2 = (a = c /* comment */);
);
assigned = (a, b, c /* comment */);
assigned = (a, b, c) /* comment */;
// assigned = (a = c /* comment */);
function f() {
return (a, b, c /* comment */);
return (a, b, c) /* comment */;
return (a = c /* comment */);
}