How to use the @teleporthq/teleport-plugin-common.ASTUtils.convertValueToLiteral function in @teleporthq/teleport-plugin-common

To help you get started, we’ve selected a few @teleporthq/teleport-plugin-common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github teleporthq / teleport-code-generators / packages / teleport-plugin-vue-base-component / src / utils.ts View on Github external
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
  }, {})
}
github teleporthq / teleport-code-generators / packages / teleport-plugin-stencil-base-component / src / utils.ts View on Github external
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'), []))]
    )
  )
github teleporthq / teleport-code-generators / packages / teleport-plugin-lit-element-base-component / src / utils.ts View on Github external
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'), []))]
    )
  )
github teleporthq / teleport-code-generators / packages / teleport-plugin-angular-base-component / src / utils.ts View on Github external
const dataDeclaration = Object.keys(dataObject).map((dataKey) => {
    return t.classProperty(
      t.identifier(dataKey),
      ASTUtils.convertValueToLiteral(dataObject[dataKey]),
      t.tsTypeAnnotation(ASTUtils.getTSAnnotationForType(typeof dataObject[dataKey]))
    )
  })
github teleporthq / teleport-code-generators / packages / teleport-plugin-angular-base-component / src / utils.ts View on Github external
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'), []))]
    )
  })
github teleporthq / teleport-code-generators / packages / teleport-plugin-react-base-component / src / utils.ts View on Github external
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])
    ),
  ])
}
github teleporthq / teleport-code-generators / packages / teleport-plugin-preact-base-component / src / utils.ts View on Github external
const stateDeclarationsAST = Object.keys(stateDefinitions).map((stateKey) => {
      const stateDefinition = stateDefinitions[stateKey]
      return t.objectProperty(
        t.identifier(stateKey),
        ASTUtils.convertValueToLiteral(stateDefinition.defaultValue)
      )
    })

@teleporthq/teleport-plugin-common

Common building and modelating functions for ASTs and HASTs

MIT
Latest version published 2 days ago

Package Health Score

82 / 100
Full package analysis

Similar packages