Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(website): esquery is not working at TypescriptNode #8917

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@mdx-js/react": "^3.0.1",
"@prettier/sync": "*",
"@typescript-eslint/parser": "7.6.0",
"@typescript-eslint/visitor-keys": "7.6.0",
"@typescript-eslint/website-eslint": "7.6.0",
"clsx": "^2.1.0",
"eslint": "*",
Expand Down
3 changes: 2 additions & 1 deletion packages/website/src/components/ast/ASTViewer.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { visitorKeys } from '@typescript-eslint/visitor-keys';
armano2 marked this conversation as resolved.
Show resolved Hide resolved
import type * as ESQuery from 'esquery';
import React, { useEffect, useMemo } from 'react';

Expand All @@ -24,7 +25,7 @@ function tryToApplyFilter<T>(value: T, filter?: ESQuery.Selector): T | T[] {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (window.esquery && filter) {
// @ts-expect-error - esquery requires js ast types
return window.esquery.match(value, filter);
return window.esquery.match(value, filter, { visitorKeys });
}
} catch (e: unknown) {
console.error(e);
Expand Down
25 changes: 22 additions & 3 deletions packages/website/typings/esquery.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,33 @@ declare module 'esquery' {
declare function query(ast: Node, selector: string): Node[];

declare namespace query {
interface ESQueryOptions {
nodeTypeKey?: string;
visitorKeys?: Record<string, readonly string[]>;
fallback?: (node: Node) => string[];
matchClass?: (className: string, node: Node, ancestry: Node[]) => boolean;
}
/** Parse a selector and return its AST. */
function parse(selector: string): Selector;
/** From a JS AST and a selector AST, collect all JS AST nodes that match the selector. */
function match(ast: Node, selector: Selector): Node[];
function match(
ast: Node,
selector: Selector,
options?: ESQueryOptions,
): Node[];
/** Given a `node` and its ancestors, determine if `node` is matched by `selector`. */
function matches(node: Node, selector: Selector, ancestry: Node[]): boolean;
function matches(
node: Node,
selector: Selector,
ancestry: Node[],
options?: ESQueryOptions,
): boolean;
/** Query the code AST using the selector string. */
function query(ast: Node, selector: string): Node[];
function query(
ast: Node,
selector: string,
options?: ESQueryOptions,
): Node[];

//
// Unions
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19987,6 +19987,7 @@ __metadata:
"@typescript-eslint/parser": 7.6.0
"@typescript-eslint/rule-schema-to-typescript-types": 7.6.0
"@typescript-eslint/types": 7.6.0
"@typescript-eslint/visitor-keys": 7.6.0
"@typescript-eslint/website-eslint": 7.6.0
clsx: ^2.1.0
copy-webpack-plugin: ^12.0.0
Expand Down