Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
addDanglingComment(enclosingNode, comment);
return true;
}
if (followingNode.kind === "if") {
addBlockOrNotComment(followingNode.body, comment);
return true;
}
// For comments positioned after the condition parenthesis in an if statement
// before the consequent without brackets on, such as
// if (a) /* comment */ true,
// we look at the next character to see if the following node
// is the consequent for the if statement
if (enclosingNode.body === followingNode) {
addLeadingComment(followingNode, comment);
return true;
}
return false;
}
enclosingNode,
precedingNode,
followingNode,
comment
) {
if (
!followingNode &&
enclosingNode &&
(enclosingNode.kind === "for" || enclosingNode.kind === "foreach")
) {
// For a shortform for loop (where the body is just one node), add
// this as a leading comment to the body
if (enclosingNode.body && enclosingNode.body.kind !== "block") {
addLeadingComment(followingNode, comment);
} else {
addLeadingComment(enclosingNode, comment);
}
return true;
}
return false;
}
function handleForComments(
enclosingNode,
precedingNode,
followingNode,
comment
) {
if (
!followingNode &&
enclosingNode &&
(enclosingNode.kind === "for" || enclosingNode.kind === "foreach")
) {
// For a shortform for loop (where the body is just one node), add
// this as a leading comment to the body
if (enclosingNode.body && enclosingNode.body.kind !== "block") {
addLeadingComment(followingNode, comment);
} else {
addLeadingComment(enclosingNode, comment);
}
return true;
}
return false;
}
function handleEntryComments(enclosingNode, comment) {
if (enclosingNode && enclosingNode.kind === "entry") {
addLeadingComment(enclosingNode, comment);
return true;
}
return false;
}
function addBlockOrNotComment(node, comment) {
if (node.kind === "block") {
addBlockStatementFirstComment(node, comment);
} else {
addLeadingComment(node, comment);
}
}
) {
const isSameLineAsPrecedingNode =
precedingNode &&
!hasNewlineInRange(
text,
options.locEnd(precedingNode),
options.locStart(comment)
);
if (
(!precedingNode || !isSameLineAsPrecedingNode) &&
enclosingNode &&
enclosingNode.kind === "retif" &&
followingNode
) {
addLeadingComment(followingNode, comment);
return true;
}
return false;
}
function addBlockStatementFirstComment(node, comment) {
const { children } = node;
if (children.length === 0) {
addDanglingComment(node, comment);
} else {
addLeadingComment(children[0], comment);
}
}
function handleMemberExpressionComments(enclosingNode, followingNode, comment) {
if (
enclosingNode &&
isLookupNode(enclosingNode) &&
followingNode &&
["identifier", "variable", "encapsed"].includes(followingNode.kind)
) {
addLeadingComment(enclosingNode, comment);
return true;
}
return false;
}