Socket
Socket
Sign inDemoInstall

babylon-jsx

Package Overview
Dependencies
24
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babylon-jsx

Transform JSX in a babylon AST to call expressions


Version published
Maintainers
1
Install size
4.35 MB
Created

Readme

Source

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.

Keywords

FAQs

Last updated on 27 Sep 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc