jsx-ast-transformer
Transforms JSX AST into regular JS AST
- ~5.5kb size
- ~2.5kb minified + gzipped
Usage
We suggest you to load the module via require
until the stabilization of ES modules in Node.js:
const transform = ;
Now you can transform all JSX elements into JS calls like this:
let ast = ;
Where
jsx_ast
{Object} - ESTree-compilant JSX AST to transform to regular JS ASTfactory
{String} - factory function to use, e.g.h
,m
,React.createElement
Please note that this tool only converts JSX AST into regular ES5-compliant JavaScript AST. If you want to transpile your source code, check out mxn-jsx-transpiler or use a code like:
// Acorn & Astringconst acorn = ;const acornJsx = ;const generate = ; // JSX AST Transformerconst transform = ; // Create parserlet parser = acornParser; let code = 'let a = <Greeting firstName="Maximilian" lastName="Pierpont" age={1 + 2 + 3 + 4} />;'; let ast = parser; // Transform ASTlet ast_new = ; // Generate codelet transformedCode = ;
License
This module is released under the MIT license.