Skip to content

Commit 1bbc50d

Browse files
committed
refactor: longer name for route records
1 parent 30a2b41 commit 1bbc50d

File tree

2 files changed

+59
-57
lines changed

2 files changed

+59
-57
lines changed

src/codegen/generateRouteResolver.spec.ts

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ describe('generateRouteRecord', () => {
233233
paramParsersMap,
234234
})
235235
).toMatchInlineSnapshot(`
236-
"const r_0 = normalizeRouteRecord({
236+
"const __route_0 = normalizeRouteRecord({
237237
name: '/a',
238238
path: new MatcherPatternPathStatic('/a'),
239239
components: {
@@ -251,7 +251,7 @@ describe('generateRouteRecord', () => {
251251
paramParsersMap,
252252
})
253253
).toMatchInlineSnapshot(`
254-
"const r_1 = normalizeRouteRecord({
254+
"const __route_1 = normalizeRouteRecord({
255255
name: '/a/b/c',
256256
path: new MatcherPatternPathStatic('/a/b/c'),
257257
components: {
@@ -279,30 +279,30 @@ describe('generateRouteResolver', () => {
279279

280280
expect(resolver).toMatchInlineSnapshot(`
281281
"
282-
const r_0 = normalizeRouteRecord({
282+
const __route_0 = normalizeRouteRecord({
283283
name: '/a',
284284
path: new MatcherPatternPathStatic('/a'),
285285
components: {
286286
'default': () => import('a.vue')
287287
},
288288
})
289289
290-
const r_1 = normalizeRouteRecord({
290+
const __route_1 = normalizeRouteRecord({
291291
name: '/b/c',
292292
path: new MatcherPatternPathStatic('/b/c'),
293293
components: {
294294
'default': () => import('b/c.vue')
295295
},
296296
})
297-
const r_2 = normalizeRouteRecord({
297+
const __route_2 = normalizeRouteRecord({
298298
name: '/b/c/d',
299299
path: new MatcherPatternPathStatic('/b/c/d'),
300300
components: {
301301
'default': () => import('b/c/d.vue')
302302
},
303-
parent: r_1,
303+
parent: __route_1,
304304
})
305-
const r_3 = normalizeRouteRecord({
305+
const __route_3 = normalizeRouteRecord({
306306
name: '/b/e/f',
307307
path: new MatcherPatternPathStatic('/b/e/f'),
308308
components: {
@@ -311,10 +311,10 @@ describe('generateRouteResolver', () => {
311311
})
312312
313313
export const resolver = createFixedResolver([
314-
r_2, // /b/c/d
315-
r_3, // /b/e/f
316-
r_1, // /b/c
317-
r_0, // /a
314+
__route_2, // /b/c/d
315+
__route_3, // /b/e/f
316+
__route_1, // /b/c
317+
__route_0, // /a
318318
])
319319
"
320320
`)
@@ -345,70 +345,70 @@ describe('generateRouteResolver', () => {
345345

346346
expect(resolver).toMatchInlineSnapshot(`
347347
"
348-
const r_0 = normalizeRouteRecord({
348+
const __route_0 = normalizeRouteRecord({
349349
name: '/a',
350350
path: new MatcherPatternPathStatic('/a'),
351351
components: {
352352
'default': () => import('a.vue')
353353
},
354354
})
355-
const r_1 = normalizeRouteRecord({
355+
const __route_1 = normalizeRouteRecord({
356356
name: '/a/(a-home)',
357357
path: new MatcherPatternPathStatic('/a'),
358358
components: {
359359
'default': () => import('a/(a-home).vue')
360360
},
361-
parent: r_0,
361+
parent: __route_0,
362362
})
363-
const r_2 = normalizeRouteRecord({
363+
const __route_2 = normalizeRouteRecord({
364364
name: '/a/b',
365365
path: new MatcherPatternPathStatic('/a/b'),
366366
components: {
367367
'default': () => import('a/b.vue')
368368
},
369-
parent: r_0,
369+
parent: __route_0,
370370
})
371-
const r_3 = normalizeRouteRecord({
371+
const __route_3 = normalizeRouteRecord({
372372
name: '/a/b/(b-home)',
373373
path: new MatcherPatternPathStatic('/a/b'),
374374
components: {
375375
'default': () => import('a/b/(b-home).vue')
376376
},
377-
parent: r_2,
377+
parent: __route_2,
378378
})
379-
const r_4 = normalizeRouteRecord({
379+
const __route_4 = normalizeRouteRecord({
380380
name: '/a/b/c',
381381
path: new MatcherPatternPathStatic('/a/b/c'),
382382
components: {
383383
'default': () => import('a/b/c.vue')
384384
},
385-
parent: r_2,
385+
parent: __route_2,
386386
})
387-
const r_5 = normalizeRouteRecord({
387+
const __route_5 = normalizeRouteRecord({
388388
name: '/a/b/e',
389389
path: new MatcherPatternPathStatic('/a/b/e'),
390390
components: {
391391
'default': () => import('a/b/e.vue')
392392
},
393-
parent: r_2,
393+
parent: __route_2,
394394
})
395-
const r_6 = normalizeRouteRecord({
395+
const __route_6 = normalizeRouteRecord({
396396
name: '/a/d',
397397
path: new MatcherPatternPathStatic('/a/d'),
398398
components: {
399399
'default': () => import('a/d.vue')
400400
},
401-
parent: r_0,
401+
parent: __route_0,
402402
})
403403
404404
export const resolver = createFixedResolver([
405-
r_3, // /a/b
406-
r_4, // /a/b/c
407-
r_5, // /a/b/e
408-
r_1, // /a
409-
r_2, // /a/b
410-
r_6, // /a/d
411-
r_0, // /a
405+
__route_3, // /a/b
406+
__route_4, // /a/b/c
407+
__route_5, // /a/b/e
408+
__route_1, // /a
409+
__route_2, // /a/b
410+
__route_6, // /a/d
411+
__route_0, // /a
412412
])
413413
"
414414
`)
@@ -524,30 +524,30 @@ describe('generateRouteResolver', () => {
524524

525525
expect(resolver).toMatchInlineSnapshot(`
526526
"
527-
const r_0 = normalizeRouteRecord({
527+
const __route_0 = normalizeRouteRecord({
528528
name: '/a',
529529
path: new MatcherPatternPathStatic('/a'),
530530
components: {
531531
'default': () => import('a.vue')
532532
},
533533
})
534534
535-
const r_1 = normalizeRouteRecord({
535+
const __route_1 = normalizeRouteRecord({
536536
name: '/b/c',
537537
path: new MatcherPatternPathStatic('/b/c'),
538538
components: {
539539
'default': () => import('b/c.vue')
540540
},
541541
})
542-
const r_2 = normalizeRouteRecord({
542+
const __route_2 = normalizeRouteRecord({
543543
name: '/b/c/d',
544544
path: new MatcherPatternPathStatic('/b/c/d'),
545545
components: {
546546
'default': () => import('b/c/d.vue')
547547
},
548-
parent: r_1,
548+
parent: __route_1,
549549
})
550-
const r_3 = normalizeRouteRecord({
550+
const __route_3 = normalizeRouteRecord({
551551
name: '/b/e/f',
552552
path: new MatcherPatternPathStatic('/b/e/f'),
553553
components: {
@@ -556,10 +556,10 @@ describe('generateRouteResolver', () => {
556556
})
557557
558558
export const resolver = createFixedResolver([
559-
r_2, // /b/c/d
560-
r_3, // /b/e/f
561-
r_1, // /b/c
562-
r_0, // /a
559+
__route_2, // /b/c/d
560+
__route_3, // /b/e/f
561+
__route_1, // /b/c
562+
__route_0, // /a
563563
])
564564
"
565565
`)
@@ -580,25 +580,25 @@ describe('generateRouteResolver', () => {
580580

581581
expect(resolver).toMatchInlineSnapshot(`
582582
"
583-
const r_0 = normalizeRouteRecord({
583+
const __route_0 = normalizeRouteRecord({
584584
name: '/a',
585585
path: new MatcherPatternPathStatic('/a'),
586586
components: {
587587
'default': () => import('a.vue')
588588
},
589589
})
590-
const r_1 = normalizeRouteRecord({
590+
const __route_1 = normalizeRouteRecord({
591591
name: '/a/b/c/e',
592592
path: new MatcherPatternPathStatic('/a/b/c/e'),
593593
components: {
594594
'default': () => import('a/b/c/e.vue')
595595
},
596-
parent: r_0,
596+
parent: __route_0,
597597
})
598598
599599
export const resolver = createFixedResolver([
600-
r_1, // /a/b/c/e
601-
r_0, // /a
600+
__route_1, // /a/b/c/e
601+
__route_0, // /a
602602
])
603603
"
604604
`)
@@ -622,23 +622,23 @@ describe('generateRouteResolver', () => {
622622

623623
expect(resolver).toMatchInlineSnapshot(`
624624
"
625-
const r_0 = normalizeRouteRecord({
625+
const __route_0 = normalizeRouteRecord({
626626
/* internal name: '/a/b' */
627627
meta: {
628628
"requiresAuth": true
629629
},
630630
})
631-
const r_1 = normalizeRouteRecord({
631+
const __route_1 = normalizeRouteRecord({
632632
name: '/a/b/c',
633633
path: new MatcherPatternPathStatic('/a/b/c'),
634634
components: {
635635
'default': () => import('a/b/c.vue')
636636
},
637-
parent: r_0,
637+
parent: __route_0,
638638
})
639639
640640
export const resolver = createFixedResolver([
641-
r_1, // /a/b/c
641+
__route_1, // /a/b/c
642642
])
643643
"
644644
`)
@@ -663,7 +663,7 @@ describe('generateRouteResolver', () => {
663663

664664
expect(resolver).toMatchInlineSnapshot(`
665665
"
666-
const r_0 = normalizeRouteRecord({
666+
const __route_0 = normalizeRouteRecord({
667667
name: '/users',
668668
path: new MatcherPatternPathStatic('/users'),
669669
meta: {
@@ -676,7 +676,7 @@ describe('generateRouteResolver', () => {
676676
})
677677
678678
export const resolver = createFixedResolver([
679-
r_0, // /users
679+
__route_0, // /users
680680
])
681681
"
682682
`)
@@ -701,7 +701,7 @@ describe('generateRouteResolver', () => {
701701
expect(resolver).toMatchInlineSnapshot(`
702702
"
703703
704-
const r_0 = normalizeRouteRecord(
704+
const __route_0 = normalizeRouteRecord(
705705
_mergeRouteRecord(
706706
{
707707
name: '/profile',
@@ -716,7 +716,7 @@ describe('generateRouteResolver', () => {
716716
717717
718718
export const resolver = createFixedResolver([
719-
r_0, // /profile
719+
__route_0, // /profile
720720
])
721721
"
722722
`)
@@ -744,7 +744,7 @@ describe('generateRouteResolver', () => {
744744

745745
expect(resolver).toMatchInlineSnapshot(`
746746
"
747-
const r_0 = normalizeRouteRecord({
747+
const __route_0 = normalizeRouteRecord({
748748
name: '/search',
749749
path: new MatcherPatternPathStatic('/search'),
750750
query: [
@@ -757,7 +757,7 @@ describe('generateRouteResolver', () => {
757757
})
758758
759759
export const resolver = createFixedResolver([
760-
r_0, // /search
760+
__route_0, // /search
761761
])
762762
"
763763
`)

src/codegen/generateRouteResolver.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ interface GenerateRouteResolverState {
6363
}[]
6464
}
6565

66+
const ROUTE_RECORD_VAR_PREFIX = '__route_'
67+
6668
export function generateRouteResolver(
6769
tree: PrefixTree,
6870
options: ResolvedOptions,
@@ -94,7 +96,7 @@ ${state.matchableRecords
9496
.sort((a, b) => compareRouteScore(a.score, b.score))
9597
.map(
9698
({ varName, path }) =>
97-
` ${varName}, ${' '.repeat(String(state.id).length - varName.length + 2)}// ${path}`
99+
` ${varName}, ${' '.repeat(String(state.id).length - varName.length + ROUTE_RECORD_VAR_PREFIX.length)}// ${path}`
98100
)
99101
.join('\n')}
100102
])
@@ -145,7 +147,7 @@ export function generateRouteRecord({
145147
}
146148

147149
if (!shouldSkipNode) {
148-
varName = `r_${state.id++}`
150+
varName = `${ROUTE_RECORD_VAR_PREFIX}${state.id++}`
149151

150152
let recordName: string
151153
let recordComponents: string

0 commit comments

Comments
 (0)