Skip to content

Commit

Permalink
feat: export Query type
Browse files Browse the repository at this point in the history
  • Loading branch information
auvred committed Jan 21, 2024
1 parent 1cd3b78 commit 3d7419e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
10 changes: 7 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import type { MatchIt } from './matcher'
import type { ParseIt } from './parser'

export type Parse<Query extends string> = ParseIt<Query>
export type Match<Selector, AST extends { type: string }> = MatchIt<
Selector,
export type Parse<Selector extends string> = ParseIt<Selector>
export type Match<SelectorAST, AST extends { type: string }> = MatchIt<
SelectorAST,
AST
>
export type Query<
Selector extends string,
AST extends { type: string },
> = Match<Parse<Selector>, AST>
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Match as MatchIt, Parse as ParseIt } from "../../../src/index"
import type { Query } from "../../../src/index"
import type { Equal, Expect } from "../../../src/utils"
import type { TSESTree as T } from '@typescript-eslint/typescript-estree'

type Match<_T extends string> = MatchIt<ParseIt<_T>, T.Node>
type Match<_T extends string> = Query<_T, T.Node>

export type TestCases = [
Expect<Equal<Match<"*">, T.Node>>,
Expand Down
4 changes: 2 additions & 2 deletions tests/ecosystem/tests/jest.matcher.generated-test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Match as MatchIt, Parse as ParseIt } from "../../../src/index"
import type { Query } from "../../../src/index"
import type { Equal, Expect } from "../../../src/utils"
import type { TSESTree as T } from '@typescript-eslint/typescript-estree'

type Match<_T extends string> = MatchIt<ParseIt<_T>, T.Node>
type Match<_T extends string> = Query<_T, T.Node>

export type TestCases = [
Expect<Equal<Match<"ArrowFunctionExpression">, T.ArrowFunctionExpression>>,
Expand Down
4 changes: 2 additions & 2 deletions tests/ecosystem/tests/ts-eslint.matcher.generated-test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Match as MatchIt, Parse as ParseIt } from "../../../src/index"
import type { Query } from "../../../src/index"
import type { Equal, Expect } from "../../../src/utils"
import type { TSESTree as T } from '@typescript-eslint/typescript-estree'

type Match<_T extends string> = MatchIt<ParseIt<_T>, T.Node>
type Match<_T extends string> = Query<_T, T.Node>

export type TestCases = [
Expect<Equal<Match<"*">, T.Node>>,
Expand Down
4 changes: 2 additions & 2 deletions tests/types/match.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Match as MatchIt, Parse as ParseIt } from '../../src/index'
import type { Query } from '../../src/index'
import type { Equal, Expect } from '../../src/utils'
import type { TSESTree as T } from '@typescript-eslint/typescript-estree'

type Match<_T extends string> = MatchIt<ParseIt<_T>, T.Node>
type Match<_T extends string> = Query<_T, T.Node>

export type TestCases = [
Expect<Equal<Match<'Program'>, T.Program>>,
Expand Down
4 changes: 2 additions & 2 deletions tests/utils/gen-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ function genMatcherTestsFromPairs(
const srcPath = srcPathRelativeFrom(destPath)
const indexPath = JSON.stringify(path.join(srcPath, 'index'))
const utilsPath = JSON.stringify(path.join(srcPath, 'utils'))
let content = `import type { Match as MatchIt, Parse as ParseIt } from ${indexPath}
let content = `import type { Query } from ${indexPath}
import type { Equal, Expect } from ${utilsPath}
import type { TSESTree as T } from '@typescript-eslint/typescript-estree'
type Match<_T extends string> = MatchIt<ParseIt<_T>, T.Node>
type Match<_T extends string> = Query<_T, T.Node>
export type TestCases = [
`
Expand Down

0 comments on commit 3d7419e

Please sign in to comment.