]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
chore: minor cleanup
authorEduardo San Martin Morote <posva13@gmail.com>
Tue, 14 Jun 2022 16:09:41 +0000 (18:09 +0200)
committerEduardo San Martin Morote <posva@users.noreply.github.com>
Thu, 30 Jun 2022 07:59:00 +0000 (09:59 +0200)
packages/router/src/types/paths.ts
packages/router/test-dts/paths.test-d.ts
packages/router/test-dts/perfNamedRoutes.test-d.ts

index 87cbc1ac7070110a4de52a1f8e0d1533d1cee00e..2f93e68213ff122a08d15ddee1656ce202eab3f0 100644 (file)
@@ -108,7 +108,7 @@ type _ExtractParamName<
     ? // Keep extracting other alphanumeric chars
       _ExtractParamName<Rest, `${Head}${C}`>
     : 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<Head, Tail>
 
 /**
index 9555528dcb3c006b8189d1e631c0d6344a7710ac..13ebc812f7870a8523e35c3305d78921f08512d2 100644 (file)
@@ -115,8 +115,6 @@ function stripRegex<S extends string>(_s: S): _StripRegex<S> {
   return '' as any
 }
 
-const a = '/:id(\\d+)+/edit/:more(.*)' as '/:id+/edit/:more'
-
 expectType<'+/edit/'>(stripRegex('(\\d+)+/edit/'))
 expectType<'*'>(stripRegex('(.*)*'))
 expectType<'?/rest'>(stripRegex('?/rest'))
index 251417b0fbe8fa865b6d3429c1a0bfd7731b39ae..4b841f564545f14586d4e08bc832590c33fd605c 100644 (file)
@@ -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<R extends Readonly<RouteRecordRaw[]>>(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<typeof routes>) {}
-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 extends string = string> =
+  | LiteralType
+  | (BaseType & Record<never, never>)
+
+// function pushStr(
+//   route: LiteralUnion<keyof RouteStaticPathMap<typeof routes>>
+// ) {}
+// pushStr('/admin/dashboard')
 
 // function push1(
 //   route: RouteNamedMap<typeof routes>[keyof RouteNamedMap<typeof routes>]
 // ) {}
 // push1({ })
-function pushEnd(route: keyof RouteNamedMap<typeof routes>) {}
 
-pushEnd('NotFound')
+// function pushEnd(route: keyof RouteNamedMap<typeof routes>) {}
+
+// pushEnd('NotFound')
+
+// function push(
+//   route:
+//     | LiteralUnion<keyof RouteStaticPathMap<typeof routes>>
+//     | {
+//         name: keyof RouteNamedMap<typeof routes>
+//       }
+// ) {}
 
-function push(
-  route:
-    | keyof RouteStaticPathMap<typeof routes>
-    | {
-        name: keyof RouteNamedMap<typeof routes>
-      }
-) {}
+// push('/documents/:id')