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, precedingNode,
followingNode, followingNode,
}) { }) {
if (!followingNode && enclosingNode) { if (!followingNode && enclosingNode && precedingNode) {
if ( if (
enclosingNode.type === "ExpressionStatement" && enclosingNode.type === "ExpressionStatement" &&
enclosingNode.expression === precedingNode enclosingNode.expression === precedingNode
@@ -1088,8 +1088,8 @@ function handleParenthesizedExpressionTrailingComment({
return true; return true;
} }
const isSequence = precedingNode?.type === "SequenceExpression"; const isSequence = precedingNode.type === "SequenceExpression";
const isAssignment = precedingNode?.type === "AssignmentExpression"; const isAssignment = precedingNode.type === "AssignmentExpression";
if ( if (
(isSequence || isAssignment) && (isSequence || isAssignment) &&
@@ -1099,8 +1099,7 @@ function handleParenthesizedExpressionTrailingComment({
enclosingNode.init === precedingNode) || enclosingNode.init === precedingNode) ||
(enclosingNode.type === "ReturnStatement" && (enclosingNode.type === "ReturnStatement" &&
enclosingNode.argument === precedingNode) || enclosingNode.argument === precedingNode) ||
(isSequence && (enclosingNode.type === "AssignmentExpression" &&
enclosingNode.type === "AssignmentExpression" &&
enclosingNode.right === precedingNode)) enclosingNode.right === precedingNode))
) { ) {
addTrailingComment( addTrailingComment(