jsx-transpiler
This is fork of jsx-recast that uses native and fast AST tools:
- acorn-jsx for parsing JSX code to JSX AST.
- estraverse for traversal over AST.
- estraverse-fb for enabling traversal over JSX nodes and transforming them to JS nodes.
- escodegen for generating JS code and source map from AST.
Purpose
Parses and compiles JSX code to JavaScript AST or code.
For example, this:
compiles to this:
;
Benefits
- Attaches comments to AST in
esprima
/escodegen
/etc.-compatible way (extraleadingComments
+trailingComments
properties) whenattachComment
option is set (feature ofesprima@1.2
). - When comments are enabled, uses them for parsing and applying
/** @jsx CustomDOM */
annotation. - Stores original locations in transformed nodes so source maps work for JSX elements, attributes etc.
Installation
$ npm install jsx-transpiler
Usage
As JSX -> JS AST transformer
jsx;
$ node> var jsxAst = jsxJSX AST> jsxJS AST
As JSX -> JS code with source map transformer
$ node> var jsx = > jsx "code": ... "map": ...
browserify plugin
As$ browserify -t jsx-transpiler $file