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

lesx-jsx

将jsx语法转化为纯粹的React.createElement,无其他多余代码;同时,支持jsx-control-statement控制流标签。

TODO

必须由babel-core的实现转化为lesx-parserbabel-traversebabel-generator三步曲实现。(因为后面需要被转化的代码肯定不会包含script/style之类的标签,所以没必要)

因为babel的插件机制特别恶心,以上操作无法转,要实现也只能到babel-core的核心代码里实现!

如果需要转换script/style之类的特殊标签,需要如下引用:

const lesxJsx = require('lesx-jsx/lib/transform-with-spec-tags');

Installation

Grab it from npm

npm install lesx-jsx

Usage

const lesxJsx = require('lesx-jsx');

const source = `
    <div x="x" {...y} z>
        123
        <If condition={ test }>
            <span>Truth</span>
        </If>
    </div>
`;


const code = lesxJsx(source);


console.log('code:', code);

/**
React.createElement(
    "div",
    Object.assign({ x: "x" }, y, { z: true }),
    "123",
    test ? React.createElement(
        "span",
        null,
        "Truth"
    ) : null
);
*/

Current Tags

  • 0.0.5                                ...           latest (2 years ago)

5 Versions

  • 0.0.5                                ...           2 years ago
  • 0.0.4                                ...           2 years ago
  • 0.0.3                                ...           2 years ago
  • 0.0.2                                ...           2 years ago
  • 0.0.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 12
Dependencies (18)

Copyright 2014 - 2017 © taobao.org |