UNPKG

@shopify/theme-language-server-common

Version:

<h1 align="center" style="position: relative;" > <br> <img src="https://github.com/Shopify/theme-check-vscode/blob/main/images/shopify_glyph.png?raw=true" alt="logo" width="141" height="160"> <br> Theme Language Server </h1>

24 lines (23 loc) 1.22 kB
import { AST, LiquidHtmlNode, NodeOfType, SourceCodeType, NodeTypes } from '@shopify/theme-check-common'; export type VisitorMethod<S extends SourceCodeType, T, R> = (node: NodeOfType<S, T>, ancestors: AST[S][]) => R | R[] | undefined; export type Visitor<S extends SourceCodeType, R> = { [T in NodeTypes[S]]?: VisitorMethod<S, T, R>; }; export type ExecuteFunction<S extends SourceCodeType> = (node: AST[S], lineage: AST[S][]) => void; /** * @example * * const links = visit<'LiquidHTML', DocumentLink>(liquidAST, { * 'LiquidTag': (node, ancestors) => { * if (node.name === 'render' || node.name === 'include') { * return DocumentLink.create(...); * } * }, * }) * * Note: this is the ChatGPT-rewritten version of the recursive method. * If you want to refactor it, just ask it to do it for you :P */ export declare function visit<S extends SourceCodeType, R>(node: AST[S], visitor: Visitor<S, R>): R[]; export declare function forEachChildNodes<S extends SourceCodeType>(node: AST[S], lineage: AST[S][], execute: ExecuteFunction<S>): void; export declare function findCurrentNode(ast: LiquidHtmlNode, cursorPosition: number): [node: LiquidHtmlNode, ancestors: LiquidHtmlNode[]];