All Projects → LeDDGroup → typescript-transform-jsx

LeDDGroup / typescript-transform-jsx

Licence: MIT license
Typescript transform jsx to string

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to typescript-transform-jsx

ts-transform-react-jsx-source
TypeScript AST Transformer that adds source file and line number to JSX elements
Stars: ✭ 12 (-45.45%)
Mutual labels:  jsx, transform
keystone-with-react-engine
KeystoneJS CMS with React Engine as rendering engine, so we can render backend .jsx templates
Stars: ✭ 17 (-22.73%)
Mutual labels:  jsx, jsx-templates
babel-plugin-hyperscript-to-jsx
This plugin transforms react-hyperscript into JSX. Intended to be used as codemod.
Stars: ✭ 20 (-9.09%)
Mutual labels:  jsx
ai-merge
Import your SVG, AI, EPS, and PDF files into a single Illustrator document.
Stars: ✭ 65 (+195.45%)
Mutual labels:  jsx
next-boilerplate
📐 A modern universal boilerplate for React applications using Next.js.
Stars: ✭ 15 (-31.82%)
Mutual labels:  jsx
nornj
More exciting JS/JSX based on Template Engine, support control flow tags, custom directives, two-way binding, filters and custom operators.
Stars: ✭ 97 (+340.91%)
Mutual labels:  jsx
unplugin-icons
🤹 Access thousands of icons as components on-demand universally.
Stars: ✭ 2,064 (+9281.82%)
Mutual labels:  jsx
react-jsx-renderer
A React component for Rendering JSX
Stars: ✭ 43 (+95.45%)
Mutual labels:  jsx
react-for
A React component library to create loops in JSX
Stars: ✭ 22 (+0%)
Mutual labels:  jsx
adobe-discord-rpc
Discord Rich Presence extension for your adobe apps!
Stars: ✭ 383 (+1640.91%)
Mutual labels:  jsx
tung
A javascript library for rendering html
Stars: ✭ 29 (+31.82%)
Mutual labels:  jsx
BarterOnly
An ecommerce platform to buy or exchange items at your convenience
Stars: ✭ 16 (-27.27%)
Mutual labels:  jsx
etran
Erlang Parse Transforms Including Fold (MapReduce) comprehension, Elixir-like Pipeline, and default function arguments
Stars: ✭ 19 (-13.64%)
Mutual labels:  transform
ember-cli-es6-transform
Import ES6 modules from npm, bower or anywhere else in your app.
Stars: ✭ 13 (-40.91%)
Mutual labels:  transform
ExtendScript-for-Visual-Studio-Code
Extension that adds Adobe ExtendScript support to Visual Studio Code
Stars: ✭ 29 (+31.82%)
Mutual labels:  jsx
iwish
I wish that too!
Stars: ✭ 19 (-13.64%)
Mutual labels:  jsx
fjb
fast javascript bundler 📦
Stars: ✭ 103 (+368.18%)
Mutual labels:  jsx
ink-box
Styled box component for Ink
Stars: ✭ 113 (+413.64%)
Mutual labels:  jsx
reacty yew
Generate Yew components from React components via Typescript type definitions
Stars: ✭ 46 (+109.09%)
Mutual labels:  jsx
react-starter
ARCHIVED: Please use @neutrinojs/create-project
Stars: ✭ 32 (+45.45%)
Mutual labels:  jsx

typescript-transform-jsx

npm version Greenkeeper badge Maintainability

Conventional Commits code style: prettier Built with Spacemacs

Typescript transform jsx to string

Table of Contents

Motivation

  • Typesafe templates
  • Transform jsx to string in compilation time
  • Fast runtime

See examples

Install

$ npm i -D typescript-transform-jsx

Usage with ttypescript

Add it to plugins in your tsconfig.json

{
  "compilerOptions": {
    "jsx": "react-native",
    "plugins": [{ "transform": "typescript-transform-jsx" }]
  }
}

See https://github.com/LeDDGroup/typescript-transform-jsx/tree/master/examples/example-ttypescript

Setup

Set the jsx flag to react-native or preserve in your tsconfig file. Then create a types.ts with the following content:

declare namespace JSX {
  type Element = string;
  interface ElementChildrenAttribute {
    children: any;
  }
  interface IntrinsicElements {
    [element: string]: {
      [property: string]: any;
    };
  }
}

This will declare custom JSX so you don't need react typings.

Example

interface Person {
  name: string;
  age: number;
}

const App = (props: { persons: Person[] }) => (
  <ul>
    {props.persons.map(person => (
      <li>
        {person.name} is {person.age} years old
      </li>
    ))}
  </ul>
);

Gets compiled to:

const App = props =>
  `<ul>${props.persons
    .map(person => `<li>${person.name} is ${person.age} years old</li>`)
    .join("")}</ul>`;

Roadmap/Caveats

  • Always handle children property implicitly

  • Self closing tags will be treated as such, (ie no children handling on the props)

  • Using spread operators on html elements require esnext environment because it compiles down to Object.entries expression:

// input
const props = { class: "container" };
<div {...props} />;
// output
const props = { class: "container" };
`<div ${Object.entries(...props).map(
  ([key, value]) => `${key}="${value}"`
)}></div>`;

Contributing

If you have any question or idea of a feature create an issue in github or make an PR.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].