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