0.0.2 • Published 3 months ago

magic-esquery v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

Installation

npm i magic-esquery

Usage

Currently the library exports only Query, Match and Parse types.

  • Parse - parse selector into Selector AST
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
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)
import type { TSESTree } from '@typescript-eslint/typescript-estree'
import type { Query } from 'magic-esquery'

type res = Query<'CallExpression', TSESTree.Node>
//   ^? type res = TSESTree.CallExpression

Features

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.

Highlights

  • 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!
  • Enhanced child type inference (CallExpression > .callee)
  • Any combination of :matches and :not should work correctly, regardless of nesting combinations

License

MIT

0.0.2

3 months ago

0.0.1

3 months ago

0.0.0

3 months ago