GithubHelp home page GithubHelp logo

kataw's Introduction

kataw

This repo exist only to show off an alternative and improved AST than ESTree and Babel AST.

It's conforms to latest ECMA specs, and the AST is designed to fullfill this goals with high performance:

  • CST
  • Error handling / recovery
  • Incremental parsing
  • Transformation
  • Linter
  • Minification
  • JSX
  • Typescript
  • Pretty printing

None of these files are not completely up to date with my private code and will not be improved further.

I use this AST in my private project that includes all the bullet point above.

Strict mode and module goal

Strict mode should be enabled with the |= NodeFlags.Strict flag. All AST nodes will contain this mask.

Module goal is also strict mode, but a module boolean property can be enabled on the RootNode.

Async and generators

You will know if you parse in either async or yield context based on for example the AsyncFunctionDeclaration AST node.

See the ECMA specs for this

The NodeKind flags also let you do either kind & NodeKind.IsGenerator or kind & NodeKind.IsAsync for async and generator nodes.

NodeKind

The NodeKind flags allow you to do an quick comparison of AST nodes instead of using an huge switch statement that consumes memory.

For example kind & NodeKind.IsExpression, kind & NodeKind.IsStatement, kind & NodeKind.IsBindingPattern or kind & NodeKind.IsFunctionDeclaration

Comments

Comments isn't a part of this AST. Start and end values exist on each AST node. That's all info you need too extract the comments from the source file on the RootNode.

AnnexB

AnnexB is can be set as an boolean property on the IfStatement and LabelledStatement AST node.

CST

This AST supports what I choose to call a "hybrid CST". It's contains enough info to give you a perfect pretty printing.

The CST info is set using NodeFlags.

Demo

There exist an demo for this AST. It's an subset of my own private parser. The demo includes only pretty printing and AST, and it doesn't work 110%. I "ripped out" some parts to prevent it from being used to other things than an demo.

TypeScript parsing is enabled, and TS types are removed in the pretty printing.

Transformers has not been added, but maybe I can add a transformer demo later on. The transformer works like Babel. It transpiles from ES2021 to older ECMA versions.

Contribution

If you have ideas on how to improve this AST further - contribution is welcome.

kataw's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.