JSPM

cherow

1.0.0-beta1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 24459
  • Score
    100M100P100Q130698F
  • License ISC

Fast, standard-compliant ECMAScript parser written in ECMAScript

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 (beta)

NPM version Gitter chat Build status CircleCI Coverage Status

A very fast, standards-compliant, self-hosted ECMAScript parser with high focus on both performance and stability.

It strictly follows the ECMAScript® 2018 Language Specification and should parse according to these specifications.

Demo and Benchmark

Features

  • Full support for ECMAScript® 2017 (ECMA-262 8th Edition)
  • ECmaScript Next (Stage 3 proposals)
  • Skips hashbang comment nodes by default
  • Skips BOM (U+FEFF) by default
  • Early error tolerant parsing
  • Optional tracking of syntax node location (index-based and line-column)
  • Heavily tested (~53 000 unit tests with full code coverage))

ESNext features

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

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;');

This will return when serialized in json:

{
    "type": "Program",
    "body": [
        {
            "type": "VariableDeclaration",
            "declarations": [
                {
                    "type": "VariableDeclarator",
                    "init": {
                        "type": "Literal",
                        "value": 123
                    },
                    "id": {
                        "type": "Identifier",
                        "name": "fooBar"
                    }
                }
            ],
            "kind": "const"
        }
    ],
    "sourceType": "script"
}

Options

Cherow supports several options as listed below, and they can be used as the second argument during parsing:

parseScript('1', { ranges: true, loc: true });`:
Option Description
comments Create a top-level comments array containing all comments
early Create a top-level error array containing all "skipped" early errors
globalReturn Allow return statement in global scope
loc Attach line/column location information to each node
ranges Attach range information to each node
next Allow experimental ECMAScript features (Stage 3 proposals)
plugins Array containing the parameterized plugins that you want to enable
source Correlate output AST nodes with their source filename
raw Attach raw property on literal nodes (Esprima and Acorn feature)

Comments

Single line, multiline and HTML comments are supported by Cherow, and the parser can be instructed to collect comments by setting the comments option to true, or attach the comments to the AST node by setting attachComment to true.

A top-level comments array containing all comments will be attached to the root node (Program), and the type of each comment can either be LineComment for a single-line comment (//) or BlockComment for a MultiLineComment (/* */).

Early error tolerant parsing

The tolerant algorithm used by Cherow deviates slightly from both Esprima and Acorn due to the parsers complexity, and it's primarily for early errors, and other errors that are basically valid syntax but just not allowed.

A top-level errors array containing all "skipped" errors will be attached to the root node (Program),

Bug reporting

If you caught a bug, don't hesitate to report it in the issue tracker. From the moment I respond to you, it will take maximum 30 minutes before the bug is fixed. Note that I will try to respond to you within one hour. Sometimes it can take a bit longer. I'm not allways online. And if I find out it will take more then 30 minutes to solve your issue, you will be notified.

I know how irritating it can be if you are writing code and encounter bugs in your dependencies. And even more frustrating if you need to wait weeks or days.

Contribution

If you feel something could've been done better, please do feel free to file a pull request with the changes.

Read our guidelines here