JSPM

cherow

04.12.20181101
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 11083
  • Score
    100M100P100Q131563F
  • License ISC

Fast and lightweight, standard-compliant javascript 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

NPM version Gitter chat Build Status Build status CircleCI Coverage Status

Active development branch

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

Features

ESNext features

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

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

Alt text

Benchmark #2

Note! This Jazzle parser couldn't parse the TypeScript library, so the results is not 100%.

Alt text