From: Eduardo San Martin Morote Date: Tue, 14 Jun 2022 16:09:41 +0000 (+0200) Subject: chore: minor cleanup X-Git-Tag: v4.1.0~17 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fde74a504e3f945ff5fe3e27c330669433904f7a;p=thirdparty%2Fvuejs%2Frouter.git chore: minor cleanup --- diff --git a/packages/router/src/types/paths.ts b/packages/router/src/types/paths.ts index 87cbc1ac..2f93e682 100644 --- a/packages/router/src/types/paths.ts +++ b/packages/router/src/types/paths.ts @@ -108,7 +108,7 @@ type _ExtractParamName< ? // Keep extracting other alphanumeric chars _ExtractParamName : never // ERR - : // add the rest to the end after a % which is invalid in a path so it can be used as a delimiter + : // end the recursion _ParamExtractResult /** diff --git a/packages/router/test-dts/paths.test-d.ts b/packages/router/test-dts/paths.test-d.ts index 9555528d..13ebc812 100644 --- a/packages/router/test-dts/paths.test-d.ts +++ b/packages/router/test-dts/paths.test-d.ts @@ -115,8 +115,6 @@ function stripRegex(_s: S): _StripRegex { return '' as any } -const a = '/:id(\\d+)+/edit/:more(.*)' as '/:id+/edit/:more' - expectType<'+/edit/'>(stripRegex('(\\d+)+/edit/')) expectType<'*'>(stripRegex('(.*)*')) expectType<'?/rest'>(stripRegex('?/rest')) diff --git a/packages/router/test-dts/perfNamedRoutes.test-d.ts b/packages/router/test-dts/perfNamedRoutes.test-d.ts index 251417b0..4b841f56 100644 --- a/packages/router/test-dts/perfNamedRoutes.test-d.ts +++ b/packages/router/test-dts/perfNamedRoutes.test-d.ts @@ -1,9 +1,4 @@ -import { - RouteRecordRaw, - RouteNamedMap, - RouteStaticPathMap, - RouteLocationNamedRaw, -} from '.' +import { createRouter, createMemoryHistory } from '.' import { defineComponent } from 'vue' const Home = defineComponent({}) @@ -11,145 +6,177 @@ const User = defineComponent({}) const LongView = defineComponent({}) const component = defineComponent({}) -function defineRoutes>(routes: R): R { - return routes -} +const router = createRouter({ + history: createMemoryHistory(), + routes: [ + { path: '/home', redirect: '/' }, + { + path: '/', + components: { default: Home, other: component }, + }, + { + path: '/always-redirect', + component, + }, + { path: '/users/:id', name: 'user', component: User, props: true }, + { path: '/documents/:id', name: 'docs', component: User, props: true }, + { path: '/optional/:id?', name: 'optional', component: User, props: true }, + // { path: encodeURI('/n/€'), name: 'euro', component }, + { path: '/n/:n', name: 'increment', component }, + { path: '/multiple/:a/:b', name: 'multiple', component }, + { path: '/long-:n', name: 'long', component: LongView }, + { + path: '/lazy', + component, + }, + { + path: '/with-guard/:n', + name: 'guarded', + component, + }, + { path: '/cant-leave', component }, + { + path: '/children', + name: 'WithChildren', + component, + children: [ + { path: '', alias: 'alias', name: 'default-child', component }, + { path: 'a', name: 'a-child', component }, + { + path: 'b', + name: 'WithChildrenB', + component, + children: [ + { + path: '', + name: 'b-child', + component, + }, + { path: 'a2', component }, + { path: 'b2', component }, + ], + }, + ], + }, + { path: '/with-data', component, name: 'WithData' }, + { path: '/rep/:a*', component, name: 'repeat' }, + { path: '/:data(.*)' as '/:data', component, name: 'NotFound' }, + { + path: '/nested', + alias: '/anidado', + component, + name: 'Nested', + children: [ + { + path: 'nested', + alias: 'a', + name: 'NestedNested', + component, + children: [ + { + name: 'NestedNestedNested', + path: 'nested', + component, + }, + ], + }, + { + path: 'other', + alias: 'otherAlias', + component, + name: 'NestedOther', + }, + { + path: 'also-as-absolute', + alias: '/absolute', + name: 'absolute-child', + component, + }, + ], + }, -const routes = [ - { path: '/home', redirect: '/' }, - { - path: '/', - components: { default: Home, other: component }, - }, - { - path: '/always-redirect', - component, - }, - { path: '/users/:id', name: 'user', component: User, props: true }, - { path: '/documents/:id', name: 'docs', component: User, props: true }, - { path: '/optional/:id?', name: 'optional', component: User, props: true }, - { path: encodeURI('/n/€'), name: 'euro', component }, - { path: '/n/:n', name: 'increment', component }, - { path: '/multiple/:a/:b', name: 'multiple', component }, - { path: '/long-:n', name: 'long', component: LongView }, - { - path: '/lazy', - component, - }, - { - path: '/with-guard/:n', - name: 'guarded', - component, - }, - { path: '/cant-leave', component }, - { - path: '/children', - name: 'WithChildren', - component, - children: [ - { path: '', alias: 'alias', name: 'default-child', component }, - { path: 'a', name: 'a-child', component }, - { - path: 'b', - name: 'WithChildrenB', - component, - children: [ - { - path: '', - name: 'b-child', - component, - }, - { path: 'a2', component }, - { path: 'b2', component }, - ], - }, - ], - }, - { path: '/with-data', component, name: 'WithData' }, - { path: '/rep/:a*', component, name: 'repeat' }, - { path: '/:data(.*)', component, name: 'NotFound' }, - { - path: '/nested', - alias: '/anidado', - component, - name: 'Nested', - children: [ - { - path: 'nested', - alias: 'a', - name: 'NestedNested', - component, - children: [ - { - name: 'NestedNestedNested', - path: 'nested', - component, - }, - ], - }, - { - path: 'other', - alias: 'otherAlias', - component, - name: 'NestedOther', - }, - { - path: 'also-as-absolute', - alias: '/absolute', - name: 'absolute-child', - component, - }, - ], - }, + { + path: '/parent/:id', + name: 'parent', + component, + props: true, + alias: '/p/:id', + children: [ + // empty child + { path: '', name: 'child-id', component }, + // child with absolute path. we need to add an `id` because the parent needs it + { path: '/p_:id/absolute-a', alias: 'as-absolute-a', component }, + // same as above but the alias is absolute + { path: 'as-absolute-b', alias: '/p_:id/absolute-b', component }, + ], + }, + { + path: '/dynamic', + name: 'dynamic', + component, + end: false, + strict: true, + }, - { - path: '/parent/:id', - name: 'parent', - component, - props: true, - alias: '/p/:id', - children: [ - // empty child - { path: '', name: 'child-id', component }, - // child with absolute path. we need to add an `id` because the parent needs it - { path: '/p_:id/absolute-a', alias: 'as-absolute-a', component }, - // same as above but the alias is absolute - { path: 'as-absolute-b', alias: '/p_:id/absolute-b', component }, - ], - }, - { - path: '/dynamic', - name: 'dynamic', - component, - end: false, - strict: true, - }, + { + path: '/admin', + children: [ + { path: '', component }, + { path: 'dashboard', component }, + { path: 'settings', component }, + ], + }, + ] as const, +}) - { - path: '/admin', - children: [ - { path: '', component }, - { path: 'dashboard', component }, - { path: 'settings', component }, - ], - }, -] as const +router.resolve('/hello') -function pushStr(route: keyof RouteStaticPathMap) {} -pushStr('') +router.push('/admin') +router.push('/admin2') +router.push('/adminaoeu') +router.push('/admin/settings') +router.push('/admin') +router.push('/admin') +router.push('/children') +router.push('/admin') +router.push('/admin') +router.push('/admin') +router.push('/admin?[{}') +router.push('/admin') +router.push('/admin') +router.push('/admin') +router.push('/admin') +router.push('/admin') +router.push('/admin') +router.push('/admin') + +// router.pushNamed({name: ''}) +// router.pushNamed({ name: 'Nested' }) + +export type LiteralUnion = + | LiteralType + | (BaseType & Record) + +// function pushStr( +// route: LiteralUnion> +// ) {} +// pushStr('/admin/dashboard') // function push1( // route: RouteNamedMap[keyof RouteNamedMap] // ) {} // push1({ }) -function pushEnd(route: keyof RouteNamedMap) {} -pushEnd('NotFound') +// function pushEnd(route: keyof RouteNamedMap) {} + +// pushEnd('NotFound') + +// function push( +// route: +// | LiteralUnion> +// | { +// name: keyof RouteNamedMap +// } +// ) {} -function push( - route: - | keyof RouteStaticPathMap - | { - name: keyof RouteNamedMap - } -) {} +// push('/documents/:id')