All Projects → clayrisser → React Ast

clayrisser / React Ast

Licence: mit
render abstract syntax trees with react

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to React Ast

Astq
Abstract Syntax Tree (AST) Query Engine
Stars: ✭ 89 (-44.37%)
Mutual labels:  ast, tree, syntax
I18nize React
Internationalize react apps within a lunch break
Stars: ✭ 389 (+143.13%)
Mutual labels:  babel, ast, abstract-syntax-tree
coAST
Universal and language-independent abstract syntax tree
Stars: ✭ 30 (-81.25%)
Mutual labels:  syntax, ast, abstract-syntax-tree
Modiscript
Acche din aa gaye
Stars: ✭ 888 (+455%)
Mutual labels:  ast, tree, syntax
asty
Abstract Syntax Tree (AST) Data Structure
Stars: ✭ 28 (-82.5%)
Mutual labels:  syntax, tree, ast
Naomi
Sublime Text enhanced syntax highlighting for JavaScript ES6/ES7/ES2015/ES2016/ES2017+, Babel, FlowType, React JSX, Styled Components, HTML5, SCSS3, PHP 7, phpDoc, PHPUnit, MQL4. Basic: Git config files.
Stars: ✭ 544 (+240%)
Mutual labels:  babel, syntax
Metric Parser
📜 AST-based advanced mathematical parser written by Typescript.
Stars: ✭ 26 (-83.75%)
Mutual labels:  ast, tree
Spoon
Spoon is a metaprogramming library to analyze and transform Java source code (up to Java 15). 🥄 is made with ❤️, 🍻 and ✨. It parses source files to build a well-designed AST with powerful analysis and transformation API.
Stars: ✭ 1,078 (+573.75%)
Mutual labels:  ast, abstract-syntax-tree
Deps Report
Generate reports about dependencies and dependents of your JavaScript/TypeScript files through an AST. It supports import and require statements.
Stars: ✭ 76 (-52.5%)
Mutual labels:  ast, abstract-syntax-tree
Javaparser
Java 1-15 Parser and Abstract Syntax Tree for Java, including preview features to Java 13
Stars: ✭ 3,972 (+2382.5%)
Mutual labels:  ast, abstract-syntax-tree
Astexplorer.app
https://astexplorer.net with ES Modules support and Hot Reloading
Stars: ✭ 65 (-59.37%)
Mutual labels:  babel, ast
Babel Plugin React Persist
Automatically useCallback() & useMemo(); memoize inline functions
Stars: ✭ 91 (-43.12%)
Mutual labels:  babel, ast
Astexplorer
A web tool to explore the ASTs generated by various parsers.
Stars: ✭ 4,330 (+2606.25%)
Mutual labels:  babel, ast
Node Dependency Tree
Get the dependency tree of a module
Stars: ✭ 383 (+139.38%)
Mutual labels:  ast, tree
Cgen
C/C++ source generation from an AST
Stars: ✭ 107 (-33.12%)
Mutual labels:  ast, abstract-syntax-tree
Babel
🐠 Babel is a compiler for writing next generation JavaScript.
Stars: ✭ 40,109 (+24968.13%)
Mutual labels:  babel, ast
Ast Pretty Print
A pretty printer for AST-like structures
Stars: ✭ 129 (-19.37%)
Mutual labels:  babel, ast
Rewrite
Semantic code search and transformation
Stars: ✭ 134 (-16.25%)
Mutual labels:  ast, abstract-syntax-tree
tiny-wheels
一套基于原生JavaScript开发的组件库,无依赖、体积小、简单易用
Stars: ✭ 60 (-62.5%)
Mutual labels:  babel, tree
Reshape
💠 transform html with javascript plugins
Stars: ✭ 314 (+96.25%)
Mutual labels:  babel, ast

react-ast

npm GitHub stars

render abstract syntax trees using react

Please ★ this repo if you found it useful ★ ★ ★

Abstract syntax trees are difficult to work with by nature. This is a react renderer that makes interacting with abstract syntax trees and rendering code a breeze.

React AST is the ultimate meta programming tool that uses react to render abstract syntax trees. It can be used to build powerful unopinionated code generators and babel plugins that are easy to read and can scale without creating a rats nest of unreadable code.

You can read a post I wrote about this project at the link below.

Render Abstract Syntax Trees with React

Built by Silicon Hills LLC

index

Silicon Hills offers premium Node and React develpoment and support services. Get in touch at nuevesolutions.com.

Features

  • works with babel ast
  • supports typescript

Installation

npm install --save react-ast

Dependencies

Usage

Render Code

import React, { FC } from 'react';
import {
  Export,
  Expression,
  Function,
  Identifier,
  Import,
  Interface,
  JSX,
  ReactNode,
  Return,
  TypeAnnotation,
  TypeReference,
  Var,
  VarKind
} from 'react-ast';

const code = render(
  <>
    <Import default="React" imports={['FC']} from="react" />
    <Export>
      <Interface name="HelloProps" />
    </Export>
    <Var kind={VarKind.Const} typeAnnotation="FC<HelloProps>" name="Hello">
      <Function
        arrow
        params={[
          <Identifier
            typeAnnotation={
              <TypeAnnotation>
                <TypeReference name="HelloProps" />
              </TypeAnnotation>
            }
          >
            props
          </Identifier>
        ]}
      >
        <Return>
          <JSX />
        </Return>
      </Function>
    </Var>
    <Expression properties="Hello.defaultProps">{{}}</Expression>
    <Export default>
      <Identifier>Hello</Identifier>
    </Export>
  </>
);

console.log(code);

The rendered code

import React, { FC } from 'react';
export interface HelloProps {}

const Hello: FC<HelloProps> = (props: HelloProps) => {
  return <></>;
};

Hello.defaultProps = {};
export default Hello;

Render AST

Sometimes you might want to render the ast instead of rendering the code.

import React from 'react';
import { ClassDeclaration, renderAst } from 'react-ast';

const ast = renderAst(<Class name="Hello" />);

console.log(ast);

The rendered AST

{ type: 'File',
  program:
   { type: 'Program',
     body: [ [Object] ],
     directives: [],
     sourceType: 'script',
     interpreter: null },
  comments: [],
  tokens: [] }

Support

Submit an issue

Development

You can validate the AST at astexplorer.net with the following settings.

Language ParserSettings Transform
JavaScript babylon7 babelv7

Enabled the following babylon7 plugins

  • jsx
  • typescript
  • asyncGenerators
  • classProperties
  • decorators
  • doExpressions
  • dynamicImport
  • functionBind
  • functionSent
  • numericSeparator
  • objectRestSpread
  • optionalCatchBinding
  • optionalChaining

Contributing

Review the guidelines for contributing

License

MIT License

Jam Risser © 2019

Changelog

Review the changelog

Credits

Support on Liberapay

A ridiculous amount of coffee ☕ ☕ ☕ was consumed in the process of building this project.

Add some fuel if you'd like to keep me going!

Liberapay receiving Liberapay patrons

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].