Cherow is a very fast, standard-compliant ECMAScript parser written in ECMAScript.

Strictly follows the ECMAScript® 2018 Language Specification and should parse according to these specifications

It’s safe to use in production.

Note! if you find a bug, open a issue ticket and we will try our best to solve it within 30 – 60 minutes.

A online demo can be found here.

Features

ESNext features

Stage 3 features support. This need to be enabled with the next option

  • Import()
  • Asynchronous Iteration
  • Rest/Spread Properties
  • Optional catch binding
  • Regular Expression’s new DotAll flag

Options

API

Cherow can be used to perform syntactic analysis of JavaScript program.

Note! there does not exist an sourceType: module option for parsing module code. According the ECMAScript specs you should use either parseScript or parseModule.

// Parsing script
cherow.parseScript('const fooBar = 123;');

// Parsing module code
cherow.parseModule('const fooBar = 123;');
Copy the code

Comments

Single line, multiline and HTML comments are supported, and can be collected as well. Shebang comment node – #! foo – are skipped by default, and can’t be collected.

Acorn and Esprima differences

The main difference between Cherow and Acorn and Esprima is that the mention libraries either doesn’t parse everything according to TC39, or they doesn’t fail as they should according to the ECMAScript specs.

Cherow parses everything after the specs, and fails 90% after the specs (work in progress).

ESTree

Cherow outputs a sensible syntax tree format as standardized by ESTree project, and does not add any “extra” properties to any of its nodes.

However there is a small difference from other parsers because Cherow outputs a await property on the ForStatement node. This because of the Asynchronous Iteration implementation.

Contribution

You are welcome to contribute. As a golden rule – always run benchmarks to verify that you haven’t created any bottlenecks or did something that you shouldn’t.

Terms of contribution:

  • Think twice before you try to implement anything
  • Minimum 1.5 mill OPS/SEC for light weight cases, and 800K-1 mill OPS/SEC for “heavy” cases
  • Avoid duplicating the source code
  • Create tests that cover what you have implemented