Skip to content

Commit 31700cb

Browse files
committed
better condition grouping
1 parent 7d2b299 commit 31700cb

File tree

2 files changed

+192
-128
lines changed

2 files changed

+192
-128
lines changed

packages/router-core/tests/built.test.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import {
55
parsePathname,
66
processRouteTree,
77
} from '../src'
8-
import { SEGMENT_TYPE_OPTIONAL_PARAM, SEGMENT_TYPE_PARAM, SEGMENT_TYPE_PATHNAME, SEGMENT_TYPE_WILDCARD } from "../src/path"
8+
import {
9+
SEGMENT_TYPE_OPTIONAL_PARAM,
10+
SEGMENT_TYPE_PARAM,
11+
SEGMENT_TYPE_PATHNAME,
12+
SEGMENT_TYPE_WILDCARD,
13+
} from '../src/path'
914

1015
interface TestRoute {
1116
id: string
@@ -170,7 +175,10 @@ describe('work in progress', () => {
170175
let fn = 'const baseSegments = parsePathname(from);'
171176
fn += '\nconst l = baseSegments.length;'
172177

173-
type ParsedRoute = { path: string, segments: ReturnType<typeof parsePathname> }
178+
type ParsedRoute = {
179+
path: string
180+
segments: ReturnType<typeof parsePathname>
181+
}
174182

175183
function recursiveStaticMatch(
176184
parsedRoutes: Array<ParsedRoute>,
@@ -181,19 +189,14 @@ describe('work in progress', () => {
181189
for (const route of parsedRoutes) {
182190
if (resolved.has(route)) continue // already resolved
183191
console.log('\n')
184-
console.log(
185-
'resolving: depth=',
186-
depth,
187-
'parsed=',
188-
route.path,
189-
)
192+
console.log('resolving: depth=', depth, 'parsed=', route.path)
190193
console.log('\u001b[34m' + fn + '\u001b[0m')
191194
const currentSegment = route.segments[depth]
192195
if (!currentSegment) {
193196
throw new Error(
194197
'Implementation error: this should not happen, depth=' +
195-
depth +
196-
`, route=${route.path}`,
198+
depth +
199+
`, route=${route.path}`,
197200
)
198201
}
199202
const candidates = parsedRoutes.filter((r) => {
@@ -227,7 +230,10 @@ describe('work in progress', () => {
227230
rParsed.suffixSegment === currentSegment.suffixSegment
228231
)
229232
})
230-
console.log('candidates:', candidates.map(r => r.path))
233+
console.log(
234+
'candidates:',
235+
candidates.map((r) => r.path),
236+
)
231237
if (candidates.length === 0) {
232238
throw new Error('Implementation error: this should not happen')
233239
}
@@ -321,7 +327,9 @@ describe('work in progress', () => {
321327
const leaf = candidates[0]!
322328

323329
// Check if this route contains a wildcard segment
324-
const wildcardIndex = leaf.segments.findIndex((s) => s && s.type === SEGMENT_TYPE_WILDCARD)
330+
const wildcardIndex = leaf.segments.findIndex(
331+
(s) => s && s.type === SEGMENT_TYPE_WILDCARD,
332+
)
325333

326334
if (wildcardIndex !== -1 && wildcardIndex >= depth) {
327335
// This route has a wildcard at or after the current depth
@@ -642,6 +650,7 @@ describe('work in progress', () => {
642650
'/images/thumb_200x300.jpg',
643651
'/logs/error.txt',
644652
'/cache/temp_user456.log',
653+
'/a/b/c/d/e',
645654
])('matching %s', (s) => {
646655
const originalMatch = originalMatcher(s)
647656
const buildMatch = buildMatcher(parsePathname, s)

0 commit comments

Comments
 (0)