import type { Node } from 'web-tree-sitter'; const TYPE = 'comment' as const; // ================================================================ // ================================================================ // // CommentNode // // GraphQL comment node // // ================================================================ // ================================================================ /** * Represents a comment in the GraphQL AST. * */ export interface CommentNode extends Node { type: typeof TYPE; } // ================================================================ // ================================================================ // // Type Guard // // ================================================================ // ================================================================ /** * Type guard to check if a node is a {@link CommentNode}. * * @param node - The node to check * @returns True if the node is a {@link CommentNode} * * @example * ```typescript * if (isCommentNode(node)) { * // TypeScript now knows node is CommentNode * console.log(node.type); // 'comment' * } * ``` */ export function isCommentNode(node: unknown): node is CommentNode { return (node as any)?.type === TYPE; } // ================================================================ // ================================================================ // // Constructor // // ================================================================ // ================================================================ /** * Creates a new {@link CommentNode} with the specified properties. * * @returns A new {@link CommentNode} * * @example * ```typescript * const node = CommentNode({ * // properties... * }); * ``` */ export function CommentNode(props: Omit): CommentNode { return { type: TYPE, ...props }; }