🪄 Type level ESQuery selector parser and matcher!
npm install magic-esqueryType level ESQuery selector parser and matcher!
✨ Try it out in the TypeScript Playground

```
npm i magic-esquery
Currently the library exports only Query, Match and Parse types.
- Parse - parse selector into Selector AST
`ts
import type { Parse } from 'magic-esquery'
type res = Parse<'CallExpression'>
// ^? type res = { type: "identifier"; value: "CallExpression" }
`
- Match - infer the AST Node type based on Selector AST
`ts
import type { TSESTree } from '@typescript-eslint/typescript-estree'
import type { Match } from 'magic-esquery'
type res = Match<{ type: 'identifier'; value: 'CallExpression' }, TSESTree.Node>
// ^? type res = TSESTree.CallExpression
`
- Query - parse selector and infer AST Node type (basically Parse + Match)
`ts
import type { TSESTree } from '@typescript-eslint/typescript-estree'
import type { Query } from 'magic-esquery'
type res = Query<'CallExpression', TSESTree.Node>
// ^? type res = TSESTree.CallExpression
`
This package is tested on selectors used in @typescript-eslint/eslint-plugin, @stylistic/eslint-plugin, eslint-plugin-jest.
Check out the current ecosystem test suites here.
You can also check out additional tests for matcher and parser.
- All ESQuery grammars are supported except :first-child, :last-child, :nth-child and :nth-last-child. They're not widely used. But if anyone wants magic-esquery to support them, issues/prs are welcome!CallExpression > .callee
- Enhanced child type inference ():matches
- Any combination of and :not` should work correctly, regardless of nesting combinations