Skip to content

Commit

Permalink
Merge pull request #908 from teleporthq/error-handling
Browse files Browse the repository at this point in the history
(refactor): Throw error when defaultValue is not UIDLElementNode for slots
  • Loading branch information
vladgrecu authored Jul 2, 2024
2 parents 3f051bb + f3e4f48 commit 76cc70c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/teleport-uidl-validator/src/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ export const parseComponentJSON = (

for (const propKey of Object.keys(result.propDefinitions || {})) {
const prop = result.propDefinitions[propKey]
if (
prop.type === 'element' &&
prop.defaultValue !== undefined &&
typeof prop.defaultValue !== 'object'
) {
throw new ParserError(
`The defaultValue for prop ${propKey} in component ${result.name} is not an object. It should be a UIDLElementNode.`
)
}

if (prop.type === 'element' && prop.defaultValue) {
result.propDefinitions[propKey].defaultValue = parseComponentNode(
prop.defaultValue as unknown as Record<string, unknown>,
Expand Down Expand Up @@ -439,7 +449,6 @@ const parseComponentNode = (node: Record<string, unknown>, component: ComponentU

case 'slot':
const slotNode = node as unknown as UIDLSlotNode

if (slotNode.content.fallback) {
slotNode.content.fallback = parseComponentNode(
slotNode.content.fallback as unknown as Record<string, unknown>,
Expand Down

0 comments on commit 76cc70c

Please sign in to comment.