Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
hastUtils.addAttributeToNode(htmlNode, dynamicAttrKey, attrValue.content.id)
break
case 'static':
if (Array.isArray(attrValue.content)) {
// This handles the cases when arrays are sent as props or passed as attributes
// The array will be placed on the dataObject and the data reference is placed on the node
const dataObjectIdentifier = `${elementName}${StringUtils.capitalize(attrKey)}`
dataObject[dataObjectIdentifier] = attrValue.content
hastUtils.addAttributeToNode(htmlNode, dynamicAttrKey, dataObjectIdentifier)
} else if (typeof attrValue.content === 'boolean') {
hastUtils.addBooleanAttributeToNode(htmlNode, attrKey)
} else if (typeof attrValue.content === 'string') {
hastUtils.addAttributeToNode(
htmlNode,
attrKey,
StringUtils.encode(attrValue.content.toString())
)
} else {
// For numbers and values that are passed to components and maintain their type
hastUtils.addAttributeToNode(htmlNode, dynamicAttrKey, attrValue.content.toString())
}
break
default:
throw new Error(
`generateElementNode could not generate code for attribute of type ${JSON.stringify(
attrValue
)}`
)
}
}
const getProperAttributeValueAssignment = (value: any, t = types) => {
if (!value) {
return null
}
if (typeof value === 'string') {
return t.stringLiteral(StringUtils.encode(value))
}
return t.jsxExpressionContainer(convertValueToLiteral(value))
}
const generateNode: NodeToJSX = (node, params, options) => {
switch (node.type) {
case 'static':
return StringUtils.encode(node.content.toString())
case 'dynamic':
return createDynamicValueExpression(node, options)
case 'element':
return generateElementNode(node, params, options)
case 'repeat':
return generateRepeatNode(node, params, options)
case 'conditional':
return generateConditionalNode(node, params, options)
case 'slot':
if (options.slotHandling === 'native') {
return generateNativeSlotNode(node, params, options)
const generateNode: NodeToHTML = (node, params, templateSyntax) => {
switch (node.type) {
case 'static':
return StringUtils.encode(node.content.toString())
case 'dynamic':
return templateSyntax.interpolation(node.content.id)
case 'element':
return generateElementNode(node, params, templateSyntax)
case 'repeat':
return generateRepeatNode(node, params, templateSyntax)
case 'conditional':
return generateConditionalNode(node, params, templateSyntax)
case 'slot':
return generateSlotNode(node, params, templateSyntax)