JSPM

  • Created
  • Published
  • Downloads 34
  • Score
    100M100P100Q48624F
  • License ISC

A insane fast CST based Javascript toolchain

Package Exports

  • kataw

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (kataw) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Kataw

An insane fast Javascript toolchain.

Kataw NPM GitHub license Meriyah NPM


WIP

Kataw is a javascript toolchain with high focus on performance, and it's main goal is to unify functionality that has previously been separate tools.

It's core is an ECMAScript friendly CST that allows you to parse ECMAScript® 2022 (ECMA-262 12th Edition) language specification. Each CST node contains several properties, and the flags property contains the CST info.

The CST info can be extracted from the CST node through public API methods. Click here for a complete list over all the public API methods.

Many of these APIs have the advantage that they allow you to "retrieve" info that is not otherwise available with a standard AST parser.

One example is that you only need to use kataw.isStatementNode to find out if the current CST node is a statement node. With an AST parser you must use a switch statement with 60 switch cases.

Another example is how easy it is to find out if a keyword node contains an escaped keyword. You only need to use kataw.hasUnicodeEscape. You can narrow this down further if you use kataw.isChildLess. A keyword doesn't have any child nodes.

A third benefit with this CST parser is that it is running in recovery mode by default and can be used in any editor. A build-in diagnostic system reports diagnostics if an error handler have been used. The diagnostics are dynamic. It means all the diagnostics are informative, and they will will change based on the context you are parsing in. The diagnostics have been designed like this so you can quickly understand what the problem is and correct it.

These features used together gives you more options to adjust, modify and customize the CST tree compared to a regular AST parser and you can also write fewer code lines and at the same time experience insane performance.

CST parser features

  • Error recovery by default (like Acorn loose), but it reconstruct the CST tree correctly

  • Optional error reporting (require a callback as the parsers 3rd argument)

  • Dynamic error, hint and warning diagnostics (depends on the context you are parsing in)

  • Public API methods to extract info from the CST nodes

  • 100% correct comment extraction and attachment algorithm

  • Can parse types and type annotations (Kataw has it's own type system)

  • Can be used in any editors

  • Scalable

  • Performance

Current state

  • The CST parser can be used in production

This is what the future plans are for Kataw

All this features are still WIP.

  • typechecking (like Typescript and Flow)

  • transform current ECMA code to older ECMA versions (like Babel)

  • global API to perform AST manipulation and tree walkers

  • Pretty printing (like Prettier)

  • Grammar checker

  • Linting (like ESLint)

  • Minify (Like Terser)

Future

  • A "hook system" for adding additional rules for the linter and the grammar checker will be published.

  • Hooks to support experimental syntax and ECMA proposals in an sandboxed envirnonment