Skip to content

Commit

Permalink
refactor(pattern-router): reduce bundle size and remove outdated comm…
Browse files Browse the repository at this point in the history
…ents (#3936)
  • Loading branch information
EdamAme-x authored Feb 21, 2025
1 parent c9bd830 commit a2ec848
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/router/pattern-router/router.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Params, Result, Router } from '../../router'
import { METHOD_NAME_ALL, UnsupportedPathError } from '../../router'

type Route<T> = [RegExp, string, T] // [pattern, method, handler, path]
type Route<T> = [RegExp, string, T] // [pattern, method, handler]

const emptyParams = Object.create(null)

Expand Down Expand Up @@ -30,13 +30,15 @@ export class PatternRouter<T> implements Router<T> {
}
)

let re
try {
re = new RegExp(`^${parts.join('')}${endsWithWildcard ? '' : '/?$'}`)
this.#routes.push([
new RegExp(`^${parts.join('')}${endsWithWildcard ? '' : '/?$'}`),
method,
handler,
])
} catch {
throw new UnsupportedPathError()
}
this.#routes.push([re, method, handler])
}

match(method: string, path: string): Result<T> {
Expand Down

0 comments on commit a2ec848

Please sign in to comment.