-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
path-matcher.ts
43 lines (38 loc) 路 1.19 KB
/
path-matcher.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { RouteRecordNormalized } from './types'
import {
tokensToParser,
PathParser,
PathParserOptions,
} from './path-parser-ranker'
import { tokenizePath } from './path-tokenizer'
export interface RouteRecordMatcher extends PathParser {
record: RouteRecordNormalized
parent: RouteRecordMatcher | undefined
children: RouteRecordMatcher[]
// aliases that must be removed when removing this record
alias: RouteRecordMatcher[]
}
export function createRouteRecordMatcher(
record: Readonly<RouteRecordNormalized>,
parent: RouteRecordMatcher | undefined,
options?: PathParserOptions
): RouteRecordMatcher {
const parser = tokensToParser(tokenizePath(record.path), options)
const matcher: RouteRecordMatcher = {
...parser,
record,
parent,
// these needs to be populated by the parent
children: [],
alias: [],
}
if (parent) {
// both are aliases or both are not aliases
// we don't want to mix them because the order is used when
// passing originalRecord in Matcher.addRoute
if (!matcher.record.aliasOf === !parent.record.aliasOf)
parent.children.push(matcher)
// else TODO: save alias children to be able to remove them
}
return matcher
}