babylon-jsx

1.0.0 • Public • Published

Transform JSX in a babylon AST to call expressions

babylon-jsx stability

npm version Travis branch AppVeyor branch

Based on babel's transform-react-jsx.

  • Transform JSX spread to ES2015 spread
  • No babel needed
  • Cut some cruft

Installation

Grab it from npm

npm install babylon-jsx

Usage

const babylon = require('babylon');
const babylonJsx = require('babylon-jsx');
const generate = require('babel-generator');
 
const source = `
  <div x="x" {...y} z>
    children
  </div>
`;
 
const ast = parse(source, {plugins: ['jsx']});
const transformed = babylonJsx(ast, 'React.createElement');
generate(transformed);
// => React.createElement(Component, {...{ y: 2 }, ...x, ...{ z: true }});

API

transformJSX

Convert JSX in a babel ast to CallExpressions

Parameters

  • ast {Object} - babel ast to transform JSX in
  • pragma {String} - pragma to use, e.g. React.createElement

Differences to babel

babylon-jsx produces output that differs from that created by transform-react-jsx.

  • Pragmas like // @dom h are ignored
  • No extend helper is injected
  • JSX spread is transformed to ES2015 object spread
  • All produced call expressions are printed on a single line

Built by (c) Mario Nebl. Released under the MIT license.

Readme

Keywords

Package Sidebar

Install

npm i babylon-jsx

Weekly Downloads

16

Version

1.0.0

License

MIT

Last publish

Collaborators

  • marionebl