Jsx Parser By Parser Combinators.
jsx parser by parser combinators.
yarn add @saber2pr/jsx-ast-parser
import {
parser,
transformer,
compiler,
traverser,
} from '@saber2pr/jsx-ast-parser'
const code = `<div className="hello">world</div>`
const ast = parser.parse(code) // parse ast from code string
const jsx = transformer.transform(ast) // transform ast to jsx
// compile jsx to source code
compiler.compile(jsx) === code // true
// find jsx node
traverser.findNode(jsx, node => transformer.isTextElement(node)) // [ { tagName: 'text', nodeValue: 'world' } ]
It started as a project for me to learn the principles of compilation, but now I'm confident I can make it better! I will continue to provide analysis tools for JSX code.