Skip to content

Commit 4ccd88a

Browse files
committed
refactor: reorg resolver
1 parent 5a60b24 commit 4ccd88a

File tree

14 files changed

+498
-518
lines changed

14 files changed

+498
-518
lines changed

packages/router/src/experimental/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ export { createStaticResolver } from './route-resolver/resolver-static'
1717
export type {
1818
MatcherQueryParams,
1919
MatcherQueryParamsValue,
20-
} from './route-resolver/resolver'
20+
} from './route-resolver/resolver-abstract'
2121
export {
2222
MatcherPatternPathDynamic,
2323
MatcherPatternPathStatic,
2424
MatcherPatternPathStar,
25-
} from './route-resolver/matcher-pattern'
25+
} from './route-resolver/matchers/matcher-pattern'
2626
export type {
2727
MatcherPattern,
2828
MatcherPatternHash,
2929
MatcherPatternPath,
3030
MatcherPatternQuery,
31-
} from './route-resolver/matcher-pattern'
31+
} from './route-resolver/matchers/matcher-pattern'

packages/router/src/experimental/route-resolver/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/router/src/experimental/route-resolver/matcher-location.ts

Lines changed: 0 additions & 64 deletions
This file was deleted.

packages/router/src/experimental/route-resolver/matcher-resolve.spec.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
import { describe, expect, it } from 'vitest'
22
import { defineComponent } from 'vue'
3-
import { RouteComponent, RouteMeta, RouteRecordRaw } from '../types'
4-
import { NEW_stringifyURL } from '../location'
5-
import { mockWarn } from '../../__tests__/vitest-mock-warn'
3+
import { RouteComponent, RouteMeta, RouteRecordRaw } from '../../types'
4+
import { NEW_stringifyURL } from '../../location'
5+
import { mockWarn } from '../../../__tests__/vitest-mock-warn'
66
import {
7-
createCompiledMatcher,
87
type MatcherLocationRaw,
9-
type NEW_MatcherRecordRaw,
10-
type NEW_LocationResolved,
8+
type ResolverLocationResolved,
119
type NEW_MatcherRecord,
1210
NO_MATCH_LOCATION,
13-
} from './resolver'
11+
} from './resolver-abstract'
12+
import { type NEW_MatcherRecordRaw } from './resolver-dynamic'
13+
import { createCompiledMatcher } from './resolver-dynamic'
1414
import { miss } from './matchers/errors'
15-
import { MatcherPatternPath, MatcherPatternPathStatic } from './matcher-pattern'
16-
import { EXPERIMENTAL_RouterOptions } from '../experimental/router'
17-
import { stringifyQuery } from '../query'
18-
import type {
19-
MatcherLocationAsNamed,
20-
MatcherLocationAsPathAbsolute,
21-
} from './matcher-location'
15+
import {
16+
MatcherPatternPath,
17+
MatcherPatternPathStatic,
18+
} from './matchers/matcher-pattern'
19+
import { EXPERIMENTAL_RouterOptions } from '../router'
20+
import { stringifyQuery } from '../../query'
21+
import type { ResolverLocationAsPathAbsolute } from './resolver-abstract'
22+
import type { ResolverLocationAsNamed } from './resolver-abstract'
2223
// TODO: should be moved to a different test file
2324
// used to check backward compatible paths
2425
import {
2526
PATH_PARSER_OPTIONS_DEFAULTS,
2627
PathParams,
2728
tokensToParser,
28-
} from '../matcher/pathParserRanker'
29-
import { tokenizePath } from '../matcher/pathTokenizer'
30-
import { mergeOptions } from '../utils'
29+
} from '../../matcher/pathParserRanker'
30+
import { tokenizePath } from '../../matcher/pathTokenizer'
31+
import { mergeOptions } from '../../utils'
3132

3233
// FIXME: this type was removed, it will be a new one once a dynamic resolver is implemented
3334
export interface EXPERIMENTAL_RouteRecordRaw extends NEW_MatcherRecordRaw {
@@ -128,7 +129,7 @@ describe('RouterMatcher.resolve', () => {
128129

129130
function isMatcherLocationResolved(
130131
location: unknown
131-
): location is NEW_LocationResolved<NEW_MatcherRecord> {
132+
): location is ResolverLocationResolved<NEW_MatcherRecord> {
132133
return !!(
133134
location &&
134135
typeof location === 'object' &&
@@ -155,11 +156,11 @@ describe('RouterMatcher.resolve', () => {
155156
toLocation: Exclude<MatcherLocationRaw, string> | `/${string}`,
156157
expectedLocation: Partial<MatcherResolvedLocation>,
157158
fromLocation:
158-
| NEW_LocationResolved<NEW_MatcherRecord>
159+
| ResolverLocationResolved<NEW_MatcherRecord>
159160
// absolute locations only that can be resolved for convenience
160161
| `/${string}`
161-
| MatcherLocationAsNamed
162-
| MatcherLocationAsPathAbsolute = START_LOCATION
162+
| ResolverLocationAsNamed
163+
| ResolverLocationAsPathAbsolute = START_LOCATION
163164
) {
164165
const records = (Array.isArray(record) ? record : [record]).map(
165166
(record): NEW_MatcherRecordRaw =>

packages/router/src/experimental/route-resolver/matcher-pattern.ts renamed to packages/router/src/experimental/route-resolver/matchers/matcher-pattern.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { decode, MatcherQueryParams } from './resolver'
2-
import { EmptyParams, MatcherParamsFormatted } from './matcher-location'
3-
import { miss } from './matchers/errors'
1+
import { decode, MatcherQueryParams } from '../resolver-abstract'
2+
import { miss } from './errors'
43

54
/**
65
* Base interface for matcher patterns that extract params from a URL.
@@ -274,4 +273,10 @@ export interface MatcherPatternQuery<
274273
*/
275274
export interface MatcherPatternHash<
276275
TParams extends MatcherParamsFormatted = MatcherParamsFormatted,
277-
> extends MatcherPattern<string, TParams> {}
276+
> extends MatcherPattern<string, TParams> {} /**
277+
* Generic object of params that can be passed to a matcher.
278+
*/
279+
export type MatcherParamsFormatted = Record<string, unknown> /**
280+
* Empty object in TS.
281+
*/
282+
export type EmptyParams = Record<PropertyKey, never>

packages/router/src/experimental/route-resolver/matchers/test-utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { EmptyParams } from '../matcher-location'
1+
import { EmptyParams } from './matcher-pattern'
22
import {
33
MatcherPatternPath,
44
MatcherPatternQuery,
55
MatcherPatternHash,
6-
} from '../matcher-pattern'
7-
import { NEW_MatcherRecord } from '../resolver'
6+
} from './matcher-pattern'
7+
import { NEW_MatcherRecord } from '../resolver-abstract'
88
import { invalid, miss } from './errors'
99

1010
export const ANY_PATH_PATTERN_MATCHER: MatcherPatternPath<{

0 commit comments

Comments
 (0)