]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
refactor: merge the parser config
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 8 Aug 2025 21:25:35 +0000 (23:25 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Fri, 8 Aug 2025 21:25:35 +0000 (23:25 +0200)
packages/experiments-playground/src/router/index.ts
packages/router/src/experimental/route-resolver/matchers/matcher-pattern.spec.ts
packages/router/src/experimental/route-resolver/matchers/matcher-pattern.ts

index accf3723f03d39998e75be117852f81a7cb858fc..27789265e3003e6ab64aadf856114133fb0e1118 100644 (file)
@@ -144,9 +144,7 @@ const r_profiles_detail = normalizeRouteRecord({
   path: new MatcherPatternPathCustomParams(
     /^\/profiles\/([^/]+)$/i,
     {
-      userId: {
-        parser: PARAM_INTEGER,
-      },
+      userId: PARAM_INTEGER,
     },
     ['profiles', 0]
   ),
index 5ddf274f1355eadc05ae61ca88599bf2aa389307..0a4c8b04e03a97be30421e33e2b8fac930260b63 100644 (file)
@@ -141,7 +141,7 @@ describe('MatcherPatternPathCustom', () => {
     const pattern = new MatcherPatternPathCustomParams(
       /^\/teams(?:\/([^/]+?))?\/b$/i,
       {
-        teamId: { optional: true },
+        teamId: {},
       },
       ['teams', 0, 'b']
     )
@@ -177,7 +177,7 @@ describe('MatcherPatternPathCustom', () => {
     const pattern = new MatcherPatternPathCustomParams(
       /^\/teams(?:\/(.+?))?\/b$/i,
       {
-        teamId: { repeat: true, optional: true },
+        teamId: { repeat: true },
       },
       ['teams', 0, 'b']
     )
index e1f21b78a1c974bf4691f9743d4ea7d89e3bb9f8..083902a19b113f58dff5633ad3a1487dbcfb8eb3 100644 (file)
@@ -198,11 +198,11 @@ export type ParamsFromParsers<P extends Record<string, ParamParser_Generic>> = {
 interface MatcherPatternPathCustomParamOptions<
   TIn extends string | string[] | null = string | string[] | null,
   TOut = string | string[] | null,
-> {
+> extends Param_GetSet<TIn, TOut> {
   repeat?: boolean
-  // TODO: not needed because in the regexp, the value is undefined if the group is optional and not given
-  optional?: boolean
-  parser?: Param_GetSet<TIn, TOut>
+  // NOTE: not needed because in the regexp, the value is undefined if
+  // the group is optional and not given
+  // optional?: boolean
 }
 
 /**
@@ -295,7 +295,7 @@ export class MatcherPatternPathCustomParams<
           )
         : decode(currentMatch)
 
-      params[paramName] = (paramOptions.parser?.get || (v => v))(
+      params[paramName] = (paramOptions.get || (v => v))(
         value
         // NOTE: paramName and paramOptions are not connected from TS point of view
       )
@@ -325,7 +325,7 @@ export class MatcherPatternPathCustomParams<
           const paramName = this.paramsKeys[paramIndex++]
           const paramOptions = this.params[paramName]
           const value: ReturnType<NonNullable<Param_GetSet['set']>> = (
-            paramOptions.parser?.set || (v => v)
+            paramOptions.set || (v => v)
           )(params[paramName])
 
           return Array.isArray(value)