Turn React.createElement
calls back into JSX syntax.
This is useful for
- Converting projects that started out in the opinion that “we need no stinking compilers”
- Converting already-compiled JS into something maintainable (E.g. CJSX syntax → coffee-react-transform → decaffeinate → react-createelement-to-jsx → JSX syntax)
$ npm install babel-plugin-transform-react-createelement-to-jsx
.babelrc
{
"plugins": [ "transform-react-createelement-to-jsx" ]
}
$ babel --no-babelrc --plugins transform-react-createelement-to-jsx script.js
import babel from '@babel/core'
babel.transform('code', {
plugins: ['transform-react-createelement-to-jsx'],
})
If you want to help with corner cases, here are helpful resources:
- Babylon AST spec needed to understand the AST we traverse
- JSX AST spec extension of the above, needed to understand what we emit
- babel-types API helpful tests and factories for AST nodes