Skip to content

Commit b068e7e

Browse files
committed
refactor
1 parent 7e922f6 commit b068e7e

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/index.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,12 @@ type ContextualizeToken<TToken extends TokenWithIndex> = TToken extends { type:
351351
? ContextualizeGroups<TToken['groups']>
352352
: never
353353
;
354-
// Distribution
355-
type Distribute<T extends Record<
356-
keyof T & GroupWithIndex['index'],
354+
// Transformation
355+
type CaptureValue<T extends Record<K, {value: unknown}>, K extends keyof T> = Fallback<T[K]['value'], undefined>;
356+
type Transform<T extends Record<
357+
keyof T,
357358
{
358-
value: string,
359+
value: unknown,
359360
reference: GroupWithIndex['value']
360361
}
361362
>> = T extends unknown
@@ -366,7 +367,7 @@ type Distribute<T extends Record<
366367
]: T[K]
367368
}, infer CaptureRecord>
368369
? {
369-
captures: ToTuple<{ [K in keyof CaptureRecord]: Fallback<CaptureRecord[K]['value'], undefined> }>,
370+
captures: ToTuple<{ [K in keyof CaptureRecord]: CaptureValue<CaptureRecord, K> }>,
370371
namedCaptures: {
371372
[K in keyof CaptureRecord as unknown extends As<CaptureRecord[K]['reference'], infer Capture>
372373
? Capture extends {
@@ -376,7 +377,7 @@ type Distribute<T extends Record<
376377
? Capture['name']
377378
: never
378379
: never
379-
]: Fallback<CaptureRecord[K]['value'], undefined>
380+
]: CaptureValue<CaptureRecord, K>
380381
}
381382
}
382383
: never
@@ -392,7 +393,7 @@ export type Parse<T extends string> = string extends T
392393
namedCaptures: Record<string, string | undefined>;
393394
}
394395
// @ts-expect-error: Excessive stack depth
395-
: Distribute<ContextualizeToken<IndexToken<{
396+
: Transform<ContextualizeToken<IndexToken<{
396397
type: 'groups',
397398
groups: [{
398399
isCaptured: true,

0 commit comments

Comments
 (0)