Package Exports
- cherow
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 (cherow) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Cherow
Active development branch
A very fast and lightweight, standards-compliant, self-hosted javascript parser with high focus on both performance and stability.
Features
- Conforms to the standard ECMAScript® 2018 (ECMA-262 9th Edition) language specification
- Supports Stage 3 proposals via option
- Optionally track syntactic node locations
- Emits an ESTree-compatible abstract syntax tree.
- Very well tested (~43 000 unit tests with full code coverage))
- Lightweight - 62 KB minified
ESNext features
Stage 3
features support. These need to be enabled with the next
option.
- Import()
- Class field declarations for JavaScript
- Numeric Separators
- Private methods and getter/setters for JavaScript classes
- Optional catch binding
- JSON Superset
- BigInt
- Import.meta
Builds
Cherow contains 3 different builds:
Name | Description |
---|---|
Stable |
Stable release |
Next |
Has the next option enabled by default, and support all latest ECMAScript proposals. |
Bleeding |
The active development branch. You can and will expect bugs with this branch because it's not stable |
API
Cherow generates AST according to ESTree AST format, and can be used to perform syntactic analysis (parsing) of a JavaScript program, and with ES2015 and later a JavaScript program can be either a script or a module and this is achieved by choosing parseScript
function to parse a script and parseModule
function to parse a module.
Here is a quick example:
cherow.parseScript('const fooBar = 123;', { ranges: true });
This will return when serialized in json:
{
"type": "Program",
"sourceType": "script",
"body": [
{
"type": "VariableDeclaration",
"declarations": [
{
"type": "VariableDeclarator",
"init": {
"type": "Literal",
"value": 123,
"start": 15,
"end": 18
},
"id": {
"type": "Identifier",
"name": "fooBar",
"start": 6,
"end": 12
},
"start": 6,
"end": 18
}
],
"kind": "const",
"start": 0,
"end": 19
}
],
"start": 0,
"end": 19
}
Options
There is a second argument to both methods that allows you to specify various options:
Option | Description |
---|---|
delegate |
Accepts a callback function to be invoked for each syntax node (as the node is constructed) |
loc |
Attach line/column location information to each node |
ranges |
Append start and end offsets to each node |
globalReturn |
Allow return in the global scope |
skipShebang |
Allow to skip shebang - '#' |
impliedStrict |
Enable implied strict mode |
next |
Enable stage 3 support (ESNext) |
tolerant |
Create a top-level error array containing all "skipped" errors |
source |
Set to true to record the source file in every node's loc object when the loc option is set. |
raw |
Attach raw property to each literal node |
rawIdentifier |
Attach raw property to each identifier node |
node |
Allow to bypass scoping when run in a NodejS environment |
Modules
In Cherow this replace the traditional plugin system, and let you import the parser instance and develop your own functions with it, and / or re-use existing one.
Example:
import { parser, scanSignedInteger, parseScript, parserModule } from 'cherow';
function doWhatYouWant(parser, context) {
// do some magic with numbers
value = scanSignedInteger(parser, context); / '+', '-'
// ...
}
Performance
Benchmark #1
Benchmark #2
Note! This Jazzle parser couldn't parse the TypeScript library, so the results is not 100%.