This project is an AST explorer for React JSX written in TypeScript. It parses a TSX file with Babel and prints a readable tree of:
- JSX elements and fragments
- props
- text nodes
- expression containers
- nested JSX inside expressions such as
map, conditionals, and logical&& - source locations
-
Install dependencies:
pnpm install
-
Run the explorer against the demo file:
pnpm start
-
Watch the file while you edit:
pnpm watch
Explore the default file:
pnpm startExplore a specific file:
pnpm start -- src/App.tsxPrint the source code before the tree:
pnpm start -- --codeHide the summary:
pnpm start -- --no-summaryHide line and column locations:
pnpm start -- --no-locThe sample src/App.tsx includes:
- fragments
- custom components
- props with expressions
- conditional rendering
maprendering- nested JSX inside expression containers
Open that file and change the JSX to see how the AST tree changes.