https://github.com/saber2pr/jsx-ast-parser
Jsx Parser By Parser Combinators.
https://github.com/saber2pr/jsx-ast-parser
jsx-parser parser-combinators typescript-parsec
Last synced: about 1 year ago
JSON representation
Jsx Parser By Parser Combinators.
- Host: GitHub
- URL: https://github.com/saber2pr/jsx-ast-parser
- Owner: Saber2pr
- Created: 2021-09-12T11:57:05.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-10-09T05:10:59.000Z (over 4 years ago)
- Last Synced: 2024-10-12T04:12:29.289Z (over 1 year ago)
- Topics: jsx-parser, parser-combinators, typescript-parsec
- Language: TypeScript
- Homepage: https://jsx-ast-viewer.vercel.app/
- Size: 582 KB
- Stars: 12
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# @saber2pr/jsx-ast-parser
[](https://www.npmjs.com/package/@saber2pr/jsx-ast-parser)
[](https://codecov.io/gh/Saber2pr/jsx-ast-parser)
> jsx parser by parser combinators.
```bash
yarn add @saber2pr/jsx-ast-parser
```
### Usage
```ts
import {
parser,
transformer,
compiler,
traverser,
} from '@saber2pr/jsx-ast-parser'
const code = `
world`
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' } ]
```
#### Help
1. [Api Docs](https://saber2pr.top/jsx-ast-parser/)
2. [Jsx Ast Viewer](https://jsx-ast-viewer.vercel.app/)
- Profile
- [see parser output ast.json](./public/ast.json)
- [see transformer output jsx.json](./public/jsx.json)
- [see compiler output out.jsx](./public/out.jsx)
### Feature
#### Overview Grammar BNF
[jsx.bnf](./public/jsx.bnf)
#### Syntax currently supported
- [ ] parser
- [ ] jsx
- [x] jsx opened
- [x] jsx self closing
- [ ] jsx props
- [x] jsx props string-value
- [x] jsx props number-value, bool-value
- [x] jsx props object
- [x] jsx props object-array
- [x] jsx props string-array, number-array
- [x] jsx props arrow function
- [x] jsx props arrow function scope statements
- [x] jsx props function
- [x] jsx props function scope statements
- [ ] statement
- [x] call chain
- [x] arrow function
- [x] comment
- [ ] arithmetic
- [x] function
- [x] define
- [x] assign
- [x] if else
- [ ] for
- [ ] while
- [ ] try catch
- [x] return
- [ ] deconstruct
- [ ] as
- [ ] transformer
- [x] transform jsx
- [ ] traverser
- [ ] traverse ast
- [x] traverse jsx
- [ ] compiler
- [ ] compile ast
- [x] compile jsx
### Why
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.