Skip to content

Commit

Permalink
🐛 Fix exclude id option config parsing
Browse files Browse the repository at this point in the history
It did not correctly handle multiple values in a list
  • Loading branch information
misode committed Nov 22, 2024
1 parent 8737854 commit e81124d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
9 changes: 1 addition & 8 deletions packages/mcdoc/src/runtime/attribute/builtin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,7 @@ const idValidator = validator.alternatives<IdConfig>(
empty: validator.optional(validator.options('allowed')),
exclude: validator.optional(validator.alternatives<string[]>(
validator.map(validator.string, v => [v]),
(value) => {
if (value?.kind === 'tuple') {
return value.items.flatMap(i =>
i.kind === 'literal' && i.value.kind === 'string' ? [i.value.value] : []
)
}
return core.Failure
},
validator.list(validator.string),
)),
}),
() => ({}),
Expand Down
19 changes: 19 additions & 0 deletions packages/mcdoc/src/runtime/attribute/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,25 @@ export function tree<C extends { [K in keyof C]: core.Returnable }>(
}
}

export function list<C extends core.Returnable>(
itemValidator: McdocAttributeValidator<C>,
): McdocAttributeValidator<C[]> {
return (value, ctx) => {
if (value?.kind !== 'tree') {
return core.Failure
}
const result: C[] = []
for (const element of Object.values(value.values)) {
const item = itemValidator(element, ctx)
if (item === core.Failure) {
return core.Failure
}
result.push(item)
}
return result
}
}

export function optional<C extends core.Returnable>(
validator: McdocAttributeValidator<C>,
): McdocAttributeValidator<C | undefined> {
Expand Down

0 comments on commit e81124d

Please sign in to comment.