]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
refactor: identity fn
authorEduardo San Martin Morote <posva13@gmail.com>
Sun, 10 Aug 2025 16:44:26 +0000 (18:44 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Sun, 10 Aug 2025 16:44:26 +0000 (18:44 +0200)
packages/router/src/experimental/route-resolver/matchers/matcher-pattern.ts
packages/router/src/utils/index.ts

index 083902a19b113f58dff5633ad3a1487dbcfb8eb3..e898ad4d64d019b204eaf05a07d63489fe12f567 100644 (file)
@@ -1,3 +1,4 @@
+import { identityFn } from '../../../utils'
 import { encodeParam } from '../../../encoding'
 import { warn } from '../../../warning'
 import { decode, MatcherQueryParams } from '../resolver-abstract'
@@ -289,13 +290,10 @@ export class MatcherPatternPathCustomParams<
       var currentMatch = (match[i + 1] as string | undefined) ?? null
 
       var value = paramOptions.repeat
-        ? (currentMatch?.split('/') || []).map(
-            // using just decode makes the type inference fail
-            v => decode(v)
-          )
+        ? (currentMatch?.split('/') || []).map<string>(decode)
         : decode(currentMatch)
 
-      params[paramName] = (paramOptions.get || (v => v))(
+      params[paramName] = (paramOptions.get || identityFn)(
         value
         // NOTE: paramName and paramOptions are not connected from TS point of view
       )
@@ -325,7 +323,7 @@ export class MatcherPatternPathCustomParams<
           const paramName = this.paramsKeys[paramIndex++]
           const paramOptions = this.params[paramName]
           const value: ReturnType<NonNullable<Param_GetSet['set']>> = (
-            paramOptions.set || (v => v)
+            paramOptions.set || identityFn
           )(params[paramName])
 
           return Array.isArray(value)
index c6d622095ab50002a261a60fbbe83a527ce1c49f..b9cf4f72d403e4fb2ee1319e3d5a686515559c08 100644 (file)
@@ -5,6 +5,15 @@ import {
   RawRouteComponent,
 } from '../types'
 
+/**
+ * Identity function that returns the value as is.
+ *
+ * @param v - the value to return
+ *
+ * @internal
+ */
+export const identityFn = <T>(v: T) => v
+
 export * from './env'
 
 /**