Fix comment between parentheses and function body (#15326)
This commit is contained in:
1 parent
958b355ccb
commit
411ef345a2
5 files changed
+195
-21
No files matched your search
@@ -585,29 +585,20 @@ function handleLastFunctionArgComments({
|
||||
return true;
|
||||
}
|
||||
|
||||
// Comment between function parameters parentheses and function body
|
||||
if (
|
||||
enclosingNode?.type === "FunctionDeclaration" &&
|
||||
followingNode?.type === "BlockStatement"
|
||||
!isBlockComment(comment) &&
|
||||
(enclosingNode?.type === "FunctionDeclaration" ||
|
||||
enclosingNode?.type === "FunctionExpression" ||
|
||||
enclosingNode?.type === "ObjectMethod") &&
|
||||
followingNode?.type === "BlockStatement" &&
|
||||
enclosingNode.body === followingNode
|
||||
) {
|
||||
const functionParamRightParenIndex = (() => {
|
||||
const parameters = getFunctionParameters(enclosingNode);
|
||||
if (parameters.length > 0) {
|
||||
return getNextNonSpaceNonCommentCharacterIndex(
|
||||
text,
|
||||
locEnd(parameters.at(-1)),
|
||||
);
|
||||
}
|
||||
const functionParamLeftParenIndex =
|
||||
getNextNonSpaceNonCommentCharacterIndex(text, locEnd(enclosingNode.id));
|
||||
return (
|
||||
functionParamLeftParenIndex !== false &&
|
||||
getNextNonSpaceNonCommentCharacterIndex(
|
||||
text,
|
||||
functionParamLeftParenIndex + 1,
|
||||
)
|
||||
);
|
||||
})();
|
||||
if (locStart(comment) > functionParamRightParenIndex) {
|
||||
const characterAfterCommentIndex = getNextNonSpaceNonCommentCharacterIndex(
|
||||
text,
|
||||
locEnd(comment),
|
||||
);
|
||||
if (characterAfterCommentIndex === locStart(followingNode)) {
|
||||
addBlockStatementFirstComment(followingNode, comment);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user