src/language-js/comments.js/handleOnlyComments
function handleOnlyComments({
  comment,
  enclosingNode,
  followingNode,
  ast,
  isLastComment,
}) {
  // With Flow the enclosingNode is undefined so use the AST instead.
  if (ast && ast.body && ast.body.length === 0) {
    if (isLastComment) {
      addDanglingComment(ast, comment);
    } else {
      addLeadingComment(ast, comment);
    }
    return true;
  }

  if (
    enclosingNode?.type === "Program" &&
    enclosingNode?.body.length === 0 &&
    !isNonEmptyArray(enclosingNode.directives)
  ) {
    if (isLastComment) {
      addDanglingComment(enclosingNode, comment);
    } else {
      addLeadingComment(enclosingNode, comment);
    }
    return true;
  }

  if (
    followingNode?.type === "Program" &&
    followingNode?.body.length === 0 &&
    enclosingNode?.type === "ModuleExpression"
  ) {
    addDanglingComment(followingNode, comment);
    return true;
  }

  return false;
}