@@ -166,7 +166,11 @@ describe('work in progress', () => {
166
166
const rebuildPath = ( leaf : ReturnType < typeof parsePathname > ) =>
167
167
`/${ leaf
168
168
. slice ( 1 )
169
- . map ( ( s ) => ( s . value === '/' ? '' : `${ s . prefixSegment ?? '' } ${ s . prefixSegment || s . suffixSegment ? '{' : '' } ${ s . value } ${ s . prefixSegment || s . suffixSegment ? '}' : '' } ${ s . suffixSegment ?? '' } ` ) )
169
+ . map ( ( s ) =>
170
+ s . value === '/'
171
+ ? ''
172
+ : `${ s . prefixSegment ?? '' } ${ s . prefixSegment || s . suffixSegment ? '{' : '' } ${ s . value } ${ s . prefixSegment || s . suffixSegment ? '}' : '' } ${ s . suffixSegment ?? '' } ` ,
173
+ )
170
174
. join ( '/' ) } `
171
175
172
176
const initialDepth = 1
@@ -182,7 +186,12 @@ describe('work in progress', () => {
182
186
for ( const routeSegments of parsedRoutes ) {
183
187
if ( resolved . has ( routeSegments ) ) continue // already resolved
184
188
console . log ( '\n' )
185
- console . log ( 'resolving: depth=' , depth , 'parsed=' , logParsed ( routeSegments ) )
189
+ console . log (
190
+ 'resolving: depth=' ,
191
+ depth ,
192
+ 'parsed=' ,
193
+ logParsed ( routeSegments ) ,
194
+ )
186
195
console . log ( '\u001b[34m' + fn + '\u001b[0m' )
187
196
const currentSegment = routeSegments [ depth ]
188
197
if ( ! currentSegment ) {
@@ -230,28 +239,28 @@ describe('work in progress', () => {
230
239
)
231
240
if ( skipDepth === - 1 ) skipDepth = routeSegments . length - depth - 1
232
241
const lCondition =
233
- skipDepth || depth > initialDepth
234
- ? `l > ${ depth + skipDepth } `
235
- : ''
242
+ skipDepth || depth > initialDepth ? `l > ${ depth + skipDepth } ` : ''
236
243
const skipConditions =
237
- Array . from (
238
- { length : skipDepth + 1 } ,
239
- ( _ , i ) => {
240
- const segment = candidates [ 0 ] ! [ depth + i ] !
241
- if ( segment . type === 1 ) {
242
- const conditions = [ ]
243
- if ( segment . prefixSegment ) {
244
- conditions . push ( `baseSegments[${ depth + i } ].value.startsWith('${ segment . prefixSegment } ')` )
245
- }
246
- if ( segment . suffixSegment ) {
247
- conditions . push ( `baseSegments[${ depth + i } ].value.endsWith('${ segment . suffixSegment } ')` )
248
- }
249
- return conditions . join ( ' && ' )
244
+ Array . from ( { length : skipDepth + 1 } , ( _ , i ) => {
245
+ const segment = candidates [ 0 ] ! [ depth + i ] !
246
+ if ( segment . type === 1 ) {
247
+ const conditions = [ ]
248
+ if ( segment . prefixSegment ) {
249
+ conditions . push (
250
+ `baseSegments[${ depth + i } ].value.startsWith('${ segment . prefixSegment } ')` ,
251
+ )
250
252
}
251
- return `baseSegments[${ depth + i } ].value === '${ segment . value } '`
253
+ if ( segment . suffixSegment ) {
254
+ conditions . push (
255
+ `baseSegments[${ depth + i } ].value.endsWith('${ segment . suffixSegment } ')` ,
256
+ )
257
+ }
258
+ return conditions . join ( ' && ' )
252
259
}
253
- ) . filter ( Boolean ) . join ( `\n${ indent } && ` ) +
254
- ( skipDepth ? `\n${ indent } ` : '' )
260
+ return `baseSegments[${ depth + i } ].value === '${ segment . value } '`
261
+ } )
262
+ . filter ( Boolean )
263
+ . join ( `\n${ indent } && ` ) + ( skipDepth ? `\n${ indent } ` : '' )
255
264
const hasCondition = Boolean ( lCondition || skipConditions )
256
265
if ( hasCondition ) {
257
266
fn += `\n${ indent } if (${ lCondition } ${ lCondition && skipConditions ? ' && ' : '' } ${ skipConditions } ) {`
@@ -266,7 +275,11 @@ describe('work in progress', () => {
266
275
throw new Error ( 'Implementation error: this should not happen' )
267
276
}
268
277
if ( deeper . length > 0 ) {
269
- recursiveStaticMatch ( deeper , depth + 1 + skipDepth , hasCondition ? indent + ' ' : indent )
278
+ recursiveStaticMatch (
279
+ deeper ,
280
+ depth + 1 + skipDepth ,
281
+ hasCondition ? indent + ' ' : indent ,
282
+ )
270
283
}
271
284
if ( leaves . length > 1 ) {
272
285
throw new Error (
@@ -528,7 +541,7 @@ describe('work in progress', () => {
528
541
'/foo/qux' ,
529
542
'/a/user-123' ,
530
543
'/files/hello-world.txt' ,
531
- '/something/foo/bar'
544
+ '/something/foo/bar' ,
532
545
] ) ( 'matching %s' , ( s ) => {
533
546
const originalMatch = originalMatcher ( s )
534
547
const buildMatch = buildMatcher ( parsePathname , s )
@@ -538,4 +551,3 @@ describe('work in progress', () => {
538
551
expect ( buildMatch ) . toBe ( originalMatch )
539
552
} )
540
553
} )
541
-
0 commit comments