Skip to content

Commit be1679c

Browse files
committed
refactor: optional param parser
1 parent a129f12 commit be1679c

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

packages/router/src/experimental/route-resolver/matchers/matcher-pattern.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export type MatcherPatternPathDynamic_ParamOptions<
9595
/**
9696
* Param parser to use for this param.
9797
*/
98-
parser: ParamParser<TOut, TIn>,
98+
parser?: ParamParser<TOut, TIn>,
9999

100100
/**
101101
* Is tha param a repeatable param and should be converted to an array
@@ -181,7 +181,7 @@ export class MatcherPatternPathDynamic<
181181
? (currentMatch?.split('/') || []).map<string>(decode)
182182
: decode(currentMatch)
183183

184-
params[paramName] = (parser.get || identityFn)(value)
184+
params[paramName] = (parser?.get || identityFn)(value)
185185
}
186186

187187
if (
@@ -206,7 +206,6 @@ export class MatcherPatternPathDynamic<
206206
>)[keyof TParamsOptions][0]
207207
let repeatable: boolean | undefined
208208
let optional: boolean | undefined
209-
let lastParamPart: number | undefined
210209
let value: ReturnType<NonNullable<ParamParser['set']>> | undefined
211210
const path =
212211
'/' +
@@ -217,8 +216,7 @@ export class MatcherPatternPathDynamic<
217216
} else if (typeof part === 'number') {
218217
paramName = this.paramsKeys[paramIndex++]
219218
;[parser, repeatable, optional] = this.params[paramName]
220-
lastParamPart = part
221-
value = (parser.set || identityFn)(params[paramName])
219+
value = (parser?.set || identityFn)(params[paramName])
222220

223221
if (Array.isArray(value) && !value.length && !optional) {
224222
throw miss()
@@ -237,7 +235,7 @@ export class MatcherPatternPathDynamic<
237235

238236
paramName = this.paramsKeys[paramIndex++]
239237
;[parser, repeatable, optional] = this.params[paramName]
240-
value = (parser.set || identityFn)(params[paramName])
238+
value = (parser?.set || identityFn)(params[paramName])
241239

242240
// param cannot be repeatable when in a sub segment
243241
if (__DEV__ && repeatable) {

0 commit comments

Comments
 (0)