Repository navigation
refactor(router): drop a type check and a field reset that change nothing - #200
Conversation
…hing
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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VVaw7Sutbw6xMTMyDFeNfw
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
addParsedliteral fast path — dropped thetypeof segment === 'string'guard and typed the parsed resultstring[].toSegmentonly yields aRouteParamfor text opening with{, andaddroutes only{-free paths into this branch, so every segment is genuinely a string. The cast is sound and the new comment states the reason.literalChildpromotion — removed thenode.literalNode = undefinedreset when the single literal becomes a map.literalNodeis read only in theliterals === undefinedbranch ofliteralChildand infindonly whilenode.literal !== undefined; the map transition clearsliteralandliteralsis never reset toundefined, so the stale value is unreachable. TheliteralNodedoc comment now correctly scopes the field.
Both changes are behavior-neutral; matching (find) is untouched and neither line runs per request.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Requested by dinwwwh · project thread
What
Two pieces of code that never change a result are removed.
addParsed, for a path with%but no{: the check no longer tests whether each segment is a string.toSegmentreturns a param only for text that starts with{, so such a path parses into strings only. The segments are now typedstring[], with a comment saying why. Stryker had reported thetypeoftest as a surviving mutant for this reason.literalChild, when a node's second literal child turns its children into a map:literalNodeis no longer set back toundefined.findreadsliteralNodeonly whileliteralis set, andliteralChildreads it only whileliteralsis unset, so nothing reads the old value. Its doc comment now says it holds the only child "whileliteralholds its text".I also tried keeping
literalset as well and havingfindcheck the map first. That cut 10 B gzip but cost 0.4–1% per request with params, so it is not in this PR.Measurements
Instruction counts from callgrind,
node --single-threaded, averaged over hash seeds 1 and 2:Steady-state matching is unchanged:
findis not touched, and neither changed line runs per request.Checks
typeofmutant is gone.Generated by Claude Code