Transform JSX in a babylon AST to call expressions
babylon-jsx
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);
API
transformJSX
Convert JSX in a babel ast to CallExpressions
Parameters
ast
{Object} - babel ast to transform JSX inpragma
{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.