Further improve handleParenthesizedExpressionTrailingComment (#19282)

This commit is contained in:
fisker Cheung authored and GitHub committed 2026-06-04 03:02:00 +08:00
1 parent 296fbe6b7f
commit cecb09abac
1 file changed
+4 -5
+4 -5
View File
@@ -1079,7 +1079,7 @@ function handleParenthesizedExpressionTrailingComment({
precedingNode,
followingNode,
}) {
if (!followingNode && enclosingNode) {
if (!followingNode && enclosingNode && precedingNode) {
if (
enclosingNode.type === "ExpressionStatement" &&
enclosingNode.expression === precedingNode
@@ -1088,8 +1088,8 @@ function handleParenthesizedExpressionTrailingComment({
return true;
}
const isSequence = precedingNode?.type === "SequenceExpression";
const isAssignment = precedingNode?.type === "AssignmentExpression";
const isSequence = precedingNode.type === "SequenceExpression";
const isAssignment = precedingNode.type === "AssignmentExpression";
if (
(isSequence || isAssignment) &&
@@ -1099,8 +1099,7 @@ function handleParenthesizedExpressionTrailingComment({
enclosingNode.init === precedingNode) ||
(enclosingNode.type === "ReturnStatement" &&
enclosingNode.argument === precedingNode) ||
(isSequence &&
enclosingNode.type === "AssignmentExpression" &&
(enclosingNode.type === "AssignmentExpression" &&
enclosingNode.right === precedingNode))
) {
addTrailingComment(