UNPKG

1.15 kBTypeScriptView Raw
1/// <reference types="esquery" />
2import type { Node, ScriptKind, Selector } from './index';
3/**
4 * @public
5 * Find AST `Nodes` within a given `string` of code or AST `Node` matching a `Selector`.
6 *
7 * @param code - the code to be searched. This could be a `string` of TypeScript code, a TypeScript [`SourceFile`](https://github.com/microsoft/TypeScript/blob/main/src/services/types.ts#L159), or a `Node` from a previous query.
8 * @param selector - a TSQuery `Selector` (using the [ESQuery selector syntax](https://github.com/estools/esquery)).
9 * @param scriptKind - the TypeScript [`ScriptKind`](https://github.com/microsoft/TypeScript/blob/main/src/compiler/types.ts#L7305) of the code. Only required when passing a `string` of code. Defaults to `ScriptKind.TSX`. Set this to `ScriptKind.TS` if your code uses the `<Type>` syntax for casting.
10 * @returns an `Array` of `Nodes` which match the `Selector`.
11 */
12export declare function query<T extends Node = Node>(code: string, selector: string | Selector, scriptKind?: ScriptKind): Array<T>;
13export declare function query<T extends Node = Node>(code: Node, selector: string | Selector): Array<T>;