Skip to content

Commit 3c06a16

Browse files
committed
refactor: allow no parser
1 parent 89a26bd commit 3c06a16

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,18 @@ describe('MatcherPatternQueryParam', () => {
401401
})
402402
})
403403

404-
describe('defaultValue', () => {
404+
it('should work without parser parameter', () => {
405+
const matcher = new MatcherPatternQueryParam('test', 'test_param', 'value')
406+
// Should use PARAM_PARSER_DEFAULTS.get which returns value ?? null
407+
expect(matcher.match({ test_param: 'value' })).toEqual({
408+
test: 'value',
409+
})
410+
expect(matcher.build({ test: 'value' })).toEqual({
411+
test_param: 'value',
412+
})
413+
})
414+
415+
describe('parser fallback', () => {
405416
describe('match', () => {
406417
it('should fallback to PARAM_PARSER_DEFAULTS.get when parser.get is undefined', () => {
407418
const matcher = new MatcherPatternQueryParam(

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ export class MatcherPatternQueryParam<T, ParamName extends string>
2323
private paramName: ParamName,
2424
private queryKey: string,
2525
private format: 'value' | 'array' | 'both',
26-
private parser: ParamParser<T>,
27-
// TODO: optional values
28-
// private format: 'value' | 'array' | 'both' = 'both',
29-
// private parser: ParamParser<T> = PATH_PARAM_DEFAULT_PARSER,
26+
private parser: ParamParser<T> = {},
3027
private defaultValue?: (() => T) | T
3128
) {}
3229

0 commit comments

Comments
 (0)