Cherow is a very fast, standards-compliant ECMAScript parser written in ECMAScript.
It strictly follows the ECMAScript® 2017 Language Specification and should parse according to these specifications.
It's safe to use in production.
Note! If you find a bug, we will try our best to reply to you within 30 - 60 minutes, but our focus now are on the refactoring so the bug will be solved soon as the refactoring have been completed.
- Full support for ECMAScript® 2017 (ECMA-262 8th Edition)
- Stage 3 proposals (experimental)
- Support for JSX, a syntax extension for React
- Skips shebang comment nodes by default
- Optimized for handheld devices
- Optional tracking of syntax node location (index-based and line-column)
- 5600 unit tests
Stage 3
features support. These need to be enabled with the next
option.
- Import()
- Asynchronous Iteration
- Rest/Spread Properties
- Optional catch binding
- BigInt
- Regular Expression's new
DotAll
flag - Import.meta
These need to be enabled with the v8
option.
- Do expressions
next
- EnablesECMAScript Next
support and let you use proposals atstage 3
or higher such asDynamic Import
raw
- Enables the raw property on literal nodes (Esprima and Acorn feature)comments
- Enables option to collect comments. Optional; Either array or function. Works like Acorn onCommentranges
- Enables the start and characters offsets on the AST nodelocations
- Enables location trackingjsx
- Enables JSX
Cherow can be used to perform syntactic analysis of JavaScript programs.
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;');
// Parsing script
cherow.parseScript('const fooBar = 123;', { ranges: true, raw: true, next: true});
Single line, multiline and HTML comments are supported, and can be collected as well. Shebang comment nodes (#!foo
) are
skipped by default, and can't be collected.
Collecting comments works just the same way as for Acorn.
// Function
cherow.parseScript('// foo',
{
comments: function(type, comment, start, end) {}
}
);
// Array
const commentArray = [];
cherow.parseScript('// foo',
{
comments: commentArray
}
);
The main difference between Cherow and Acorn/Esprima is that the latter libraries either don't parse everything according to TC39, or they don'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).
The most important thing for an ECMAScript parser is performance, especially when it is a dependency in other libraries. Poor performance will slow down the main library.
Cherow has been developed from scratch with only one goal - performance.
You can run your own performance tests.
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 an await
property on the ForStatement
node.
This because of the Asynchronous Iteration
implementation.
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
- Avoid duplicating the source code
- Create tests that cover what you have implemented