From d5cc5267a9e5531d6357767be1dc941b394c2009 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 29 Oct 2026 12:41:53 +0000 Subject: [PATCH] refactor(router): drop a type check and a field reset that change nothing A path without `{` parses into literal segments only, so the `%`-path check in `addParsed` need not test each segment's type. `literalChild` no longer clears `literalNode` when it moves to a map, as nothing reads it once `literal` is cleared. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VVaw7Sutbw6xMTMyDFeNfw --- packages/router/src/index.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/router/src/index.ts b/packages/router/src/index.ts index b98cff7..7abedee 100644 --- a/packages/router/src/index.ts +++ b/packages/router/src/index.ts @@ -36,7 +36,7 @@ interface Node { literals: Map> | undefined /** The text of the only literal child, if there is just one. */ literal: string | undefined - /** The only literal child, if there is just one. */ + /** The only literal child, while `literal` holds its text. */ literalNode: Node | undefined param: Node | undefined /** The routes whose catch-all param starts here, most specific first. */ @@ -222,16 +222,13 @@ function addParsed( ) } } else { - const segments = parse(path) + // Without `{`, every segment is literal text. + const segments = parse(path) as string[] // Paths with `{` wait in `pending`, so one whose decoded text has a `{` // waits there too, keeping the first of two that read the same. if ( segments.every( - (segment) => - typeof segment === 'string' && - !segment.includes('/') && - !segment.includes('%') && - !segment.includes('{'), + (segment) => !segment.includes('/') && !segment.includes('%') && !segment.includes('{'), ) ) { addStatic(methods, method, `/${segments.join('/')}`, data) @@ -491,7 +488,6 @@ function literalChild(node: Node, segment: string): Node { node.literals = new Map() node.literals.set(node.literal!, node.literalNode) node.literal = undefined - node.literalNode = undefined } let child = node.literals.get(segment)