Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
default:
// don't handle anything else
throw new Error(
`createVuePropsDefinition encountered a unknown PropDefinition, ${JSON.stringify(
uidlPropDefinitions[name]
)}`
)
}
let defaultPropValue = null
if (defaultValue !== undefined) {
defaultPropValue =
type === 'array' || type === 'object'
? new ParsedASTNode(
t.arrowFunctionExpression([], ASTUtils.convertValueToLiteral(defaultValue))
)
: defaultValue
}
acc[name] = defaultPropValue ? { type: mappedType, default: defaultPropValue } : mappedType
acc[name] = isRequired ? { required: isRequired, ...acc[name] } : acc[name]
return acc
}, {})
}
const propDeclaration = Object.keys(propDefinitions).map((propKey) =>
t.classProperty(
t.identifier(propKey),
ASTUtils.convertValueToLiteral(propDefinitions[propKey].defaultValue),
types.tsTypeAnnotation(ASTUtils.getTSAnnotationForType(propDefinitions[propKey].type)),
[t.decorator(t.callExpression(t.identifier('Prop'), []))]
)
)
const propDeclaration = Object.keys(propDefinitions).map((propKey) =>
t.classProperty(
t.identifier(propKey),
ASTUtils.convertValueToLiteral(propDefinitions[propKey].defaultValue),
types.tsTypeAnnotation(ASTUtils.getTSAnnotationForType(propDefinitions[propKey].type)),
[t.decorator(t.callExpression(t.identifier('property'), []))]
)
)
const dataDeclaration = Object.keys(dataObject).map((dataKey) => {
return t.classProperty(
t.identifier(dataKey),
ASTUtils.convertValueToLiteral(dataObject[dataKey]),
t.tsTypeAnnotation(ASTUtils.getTSAnnotationForType(typeof dataObject[dataKey]))
)
})
if (definition.type === 'func') {
return t.classProperty(
t.identifier(propKey),
t.newExpression(t.identifier('EventEmitter'), []),
t.typeAnnotation(
t.genericTypeAnnotation(
t.identifier('EventEmitter'),
t.typeParameterInstantiation([t.anyTypeAnnotation()])
)
),
[t.decorator(t.callExpression(t.identifier('Output'), []))]
)
}
return t.classProperty(
t.identifier(propKey),
ASTUtils.convertValueToLiteral(propDefinitions[propKey].defaultValue),
t.tsTypeAnnotation(ASTUtils.getTSAnnotationForType(propDefinitions[propKey].type)),
[t.decorator(t.callExpression(t.identifier('Input'), []))]
)
})
const createStateHookAST = (stateKey: string, stateDefinition: UIDLStateDefinition, t = types) => {
const defaultValueArgument = ASTUtils.convertValueToLiteral(
stateDefinition.defaultValue,
stateDefinition.type
)
return t.variableDeclaration('const', [
t.variableDeclarator(
t.arrayPattern([
t.identifier(stateKey),
t.identifier(`set${StringUtils.capitalize(stateKey)}`),
]),
t.callExpression(t.identifier('useState'), [defaultValueArgument])
),
])
}
...args.map((arg) => ASTUtils.convertValueToLiteral(arg)),
])
const stateDeclarationsAST = Object.keys(stateDefinitions).map((stateKey) => {
const stateDefinition = stateDefinitions[stateKey]
return t.objectProperty(
t.identifier(stateKey),
ASTUtils.convertValueToLiteral(stateDefinition.defaultValue)
)
})