babylon-jsx
Transform JSX in a babylon AST to call expressions
Last updated 3 years ago by marionebl .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install babylon-jsx 
SYNC missed versions from official npm registry.

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.

Current Tags

  • 1.0.0                                ...           latest (3 years ago)

1 Versions

  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 1
This Week 13
This Month 110
Last Day 3
Last Week 42
Last Month 131
Dependencies (3)
Dev Dependencies (15)

Copyright 2014 - 2016 © taobao.org |