diff --git a/src/router/reg-exp-router/matcher.ts b/src/router/reg-exp-router/matcher.ts index 51312a58a..cfa862b63 100644 --- a/src/router/reg-exp-router/matcher.ts +++ b/src/router/reg-exp-router/matcher.ts @@ -7,10 +7,9 @@ export type Matcher = [RegExp, HandlerData[], StaticMap] export type MatcherMap = Record | null> export const emptyParam: string[] = [] -export const buildAllMatchersKey = Symbol('buildAllMatchers') export function match, T>(this: R, method: string, path: string): Result { // eslint-disable-next-line @typescript-eslint/no-explicit-any - const matchers: MatcherMap = (this as any)[buildAllMatchersKey]() + const matchers: MatcherMap = (this as any).buildAllMatchers() const match = ((method, path) => { const matcher = (matchers[method] || matchers[METHOD_NAME_ALL]) as Matcher diff --git a/src/router/reg-exp-router/prepared-router.ts b/src/router/reg-exp-router/prepared-router.ts index e0dbaf648..611af40c6 100644 --- a/src/router/reg-exp-router/prepared-router.ts +++ b/src/router/reg-exp-router/prepared-router.ts @@ -1,7 +1,7 @@ import type { ParamIndexMap, Result, Router } from '../../router' import { METHOD_NAME_ALL } from '../../router' import type { HandlerData, Matcher, MatcherMap, StaticMap } from './matcher' -import { match, buildAllMatchersKey, emptyParam } from './matcher' +import { match, emptyParam } from './matcher' import { RegExpRouter } from './router' type RelocateMap = Record @@ -62,7 +62,7 @@ export class PreparedRegExpRouter implements Router { } } - [buildAllMatchersKey](): MatcherMap { + protected buildAllMatchers(): MatcherMap { return this.#matchers } @@ -72,12 +72,17 @@ export class PreparedRegExpRouter implements Router { export const buildInitParams: (params: { paths: string[] }) => ConstructorParameters = ({ paths }) => { - const router = new RegExpRouter() + const RegExpRouterWithMatcherExport = class extends RegExpRouter { + buildAndExportAllMatchers() { + return this.buildAllMatchers() + } + } + const router = new RegExpRouterWithMatcherExport() for (const path of paths) { router.add(METHOD_NAME_ALL, path, path) } - const matchers = router[buildAllMatchersKey]() + const matchers = router.buildAndExportAllMatchers() const all = matchers[METHOD_NAME_ALL] as Matcher const relocateMap: RelocateMap = {} diff --git a/src/router/reg-exp-router/router.ts b/src/router/reg-exp-router/router.ts index a78be2b1a..e6410d324 100644 --- a/src/router/reg-exp-router/router.ts +++ b/src/router/reg-exp-router/router.ts @@ -6,7 +6,7 @@ import { } from '../../router' import { checkOptionalParameter } from '../../utils/url' import type { HandlerData, StaticMap, Matcher, MatcherMap } from './matcher' -import { match, emptyParam, buildAllMatchersKey } from './matcher' +import { match, emptyParam } from './matcher' import { PATH_ERROR } from './node' import type { ParamAssocArray } from './node' import { Trie } from './trie' @@ -203,9 +203,9 @@ export class RegExpRouter implements Router { } } - match: typeof match, T> = match; + match: typeof match, T> = match - [buildAllMatchersKey](): MatcherMap { + protected buildAllMatchers(): MatcherMap { const matchers: MatcherMap = Object.create(null) Object.keys(this.#routes!)