How to use the @teleporthq/teleport-types.ChunkType.AST function in @teleporthq/teleport-types

To help you get started, we’ve selected a few @teleporthq/teleport-types 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-jsx-proptypes / src / index.ts View on Github external
}

    if (hasDefaultProps) {
      const defaultPropsAst = buildDefaultPropsAst(componentClassName, uidl.propDefinitions)
      chunks.push({
        type: ChunkType.AST,
        fileType: FileType.JS,
        name: defaultPropsChunkName,
        linkAfter: [componentChunkName],
        content: defaultPropsAst,
      })
      exportChunk.linkAfter.push(defaultPropsChunkName)
    }

    chunks.push({
      type: ChunkType.AST,
      fileType: FileType.JS,
      name: typesOfPropsChunkName,
      linkAfter: [componentChunkName],
      content: typesOfPropsAst,
    })

    // push export of component after declarations of types
    exportChunk.linkAfter.push(typesOfPropsChunkName)

    return structure
  }
github teleporthq / teleport-code-generators / packages / teleport-plugin-react-styled-jsx / __tests__ / index.ts View on Github external
},
        group: {
          openingElement: {
            name: {
              name: 'Fragment',
            },
            attributes: [],
          },
          children: [],
        },
      },
      dynamicRefPrefix: {
        prop: 'props.',
      },
    },
    type: ChunkType.AST,
    fileType: FileType.JS,
    linkAfter: ['import-local'],
    content: {},
  }

  it('adds nothing on the AST if not styles are defined', async () => {
    const uidlSample = component('StyledJSX', elementNode('container'))
    const structure: ComponentStructure = {
      uidl: uidlSample,
      options: {},
      chunks: [componentChunk],
      dependencies: {},
    }

    const oldStructure = JSON.stringify(structure)
    await plugin(structure)
github teleporthq / teleport-code-generators / packages / teleport-plugin-react-styled-components / __tests__ / index.ts View on Github external
name: 'jsx-component',
    meta: {
      nodesLookup: {
        container: {
          openingElement: {
            name: {
              name: '',
            },
          },
        },
      },
      dynamicRefPrefix: {
        prop: 'props.',
      },
    },
    type: ChunkType.AST,
    fileType: FileType.JS,
    linkAfter: ['import-local'],
    content: {},
  }

  it('Should not add styled as dependency', async () => {
    const uidlSample = component('StyledComponents', elementNode('container'))
    const structure: ComponentStructure = {
      uidl: uidlSample,
      options: {},
      chunks: [componentChunk],
      dependencies: {},
    }

    const { dependencies } = await plugin(structure)
github teleporthq / teleport-code-generators / packages / teleport-plugin-vue-head-config / __tests__ / index.ts View on Github external
const uidlSample = component('SimpleComponent', elementNode('container'))
    uidlSample.node.content.key = 'container'
    uidlSample.seo = {
      metaTags: [
        {
          name: 'description',
          value: 'test',
        },
        {
          randomKey: 'randomValue',
        },
      ],
    }

    const jsChunk: ChunkDefinition = {
      type: ChunkType.AST,
      fileType: FileType.JS,
      name: 'vue-js-chunk',
      content: {
        declaration: {
          properties: [],
        },
      },
      linkAfter: [],
    }

    const structure: ComponentStructure = {
      uidl: uidlSample,
      options: {},
      chunks: [jsChunk],
      dependencies: {},
    }
github teleporthq / teleport-code-generators / packages / teleport-plugin-stencil-app-routing / __tests__ / index.ts View on Github external
options: {},
      chunks: [],
      dependencies: {},
    }

    const { dependencies, chunks } = await stencilAppRouting(structure)

    expect(chunks.length).toBe(2)
    expect(Object.keys(dependencies).length).toBe(2)
    expect(chunks[0].name).toBe('component-decorator')
    expect(chunks[0].fileType).toBe(FileType.TSX)
    expect(chunks[0].type).toBe(ChunkType.AST)
    expect(chunks[0].content).toBeDefined()
    expect(chunks[1].name).toBe('jsx-component')
    expect(chunks[1].fileType).toBe(FileType.TSX)
    expect(chunks[1].type).toBe(ChunkType.AST)
    expect(chunks[1].content).toBeDefined()
  })
})
github teleporthq / teleport-code-generators / packages / teleport-plugin-jsx-proptypes / __tests__ / index.ts View on Github external
const uidlSample = component('SimpleComponent', elementNode('container'), props)
    const structure: ComponentStructure = {
      uidl: uidlSample,
      options: {},
      chunks: [reactChunk, exportChunk],
      dependencies: {},
    }
    const result = await plugin(structure)

    const defaultProps = result.chunks.filter((chunk) => chunk.name === 'component-default-props')
    const propTypes = result.chunks.filter((chunk) => chunk.name === 'component-types-of-props')

    expect(defaultProps.length).toEqual(0)
    expect(propTypes.length).toEqual(1)
    expect(propTypes[0].type).toBe(ChunkType.AST)
  })
github teleporthq / teleport-code-generators / packages / teleport-plugin-vue-base-component / src / index.ts View on Github external
linkAfter: [],
    })

    const stateObject = uidl.stateDefinitions ? extractStateObject(uidl.stateDefinitions) : {}
    const jsContent = generateVueComponentJS(
      uidl,
      Object.keys(dependencies),
      {
        ...stateObject,
        ...dataObject,
      },
      methodsObject
    )

    chunks.push({
      type: ChunkType.AST,
      name: vueJSChunkName,
      fileType: FileType.JS,
      linkAfter: jsChunkAfter,
      content: jsContent,
    })

    return structure
  }
github teleporthq / teleport-code-generators / packages / teleport-plugin-export-components / src / index.ts View on Github external
t.stringLiteral(`./${StringUtils.camelCaseToDashCase(component)}`)
      )
    })

    let exportSpecifiers = []
    exportSpecifiers = Object.keys(components).map((component) =>
      t.exportSpecifier(
        t.identifier(StringUtils.capitalize(component)),
        t.identifier(StringUtils.capitalize(component))
      )
    )
    const exportAST = t.exportNamedDeclaration(null, exportSpecifiers)

    chunks.push({
      name: importChunkName,
      type: ChunkType.AST,
      fileType: FileType.JS,
      content: importsAST,
      linkAfter: [],
    })

    chunks.push({
      name: exportChunkName,
      type: ChunkType.AST,
      fileType: FileType.JS,
      content: exportAST,
      linkAfter: [importChunkName],
    })

    return structure
  }
github teleporthq / teleport-code-generators / packages / teleport-plugin-react-jss / src / index.ts View on Github external
})

    const exportChunk = chunks.find((chunk) => chunk.name === exportChunkName)

    const componentName = UIDLUtils.getComponentClassName(uidl)
    const exportStatement = ASTBuilders.createReactJSSDefaultExport(
      componentName,
      jssDeclarationName
    )

    if (exportChunk) {
      exportChunk.content = exportStatement
      exportChunk.linkAfter = [importChunkName, styleChunkName]
    } else {
      chunks.push({
        type: ChunkType.AST,
        fileType: FileType.JS,
        name: exportChunkName,
        content: exportStatement,
        linkAfter: [importChunkName, styleChunkName],
      })
    }

    return structure
  }
github teleporthq / teleport-code-generators / packages / teleport-plugin-preact-base-component / src / index.ts View on Github external
slotHandling: 'props',
    }

    const jsxTagStructure = createJSXSyntax(uidl.node, jsxParams, jsxOptions)

    if (!usePureComponent) {
      dependencies.Component = PREACT_COMPONENT_DEPENDENCY
    }

    const componentName = UIDLUtils.getComponentClassName(uidl)
    const preactComponent = usePureComponent
      ? createPureComponent(componentName, propDefinitions, jsxTagStructure)
      : createClassComponent(componentName, propDefinitions, stateDefinitions, jsxTagStructure)

    structure.chunks.push({
      type: ChunkType.AST,
      fileType: FileType.JS,
      name: componentChunkName,
      meta: {
        nodesLookup,
        dynamicRefPrefix: jsxOptions.dynamicReferencePrefixMap,
      },
      content: preactComponent,
      linkAfter: [importChunkName],
    })

    structure.chunks.push({
      type: ChunkType.AST,
      fileType: FileType.JS,
      name: exportChunkName,
      content: ASTBuilders.createDefaultExport(componentName),
      linkAfter: [componentChunkName],