JSPM

meriyah

0.1.11
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 420716
  • Score
    100M100P100Q180372F
  • License ISC

Fast and lightweight, standard-compliant javascript parser written in ECMAScript

Package Exports

  • meriyah

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 (meriyah) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

NPM version Code Quality: Javascript Total Alerts CircleCI

A 100% compliant, self-hosted javascript parser with high focus on both performance and stability.

Features

  • Conforms to the standard ECMAScript® 2020 (ECMA-262 10th Edition) language specification
  • Support TC39 proposals via option
  • Support for additional ECMAScript features for Web Browsers
  • Optionally track syntactic node locations (WIP)
  • Emits an ESTree-compatible abstract syntax tree.
  • No backtracking
  • Reduced memory usage
  • Very well tested (~71k unit tests with full code coverage))
  • Lightweight - ~71 KB minified

ESNext features

Note: These features need to be enabled with the next option.

API

Meriyah 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.

The parse method exposed by meriyah takes an optional options object which allows you to specify whether to parse in script mode (the default) or in module mode.

Here is a quick example to parse a script:

import { parseScript } from './meriyah';

parseScript('({x: [y] = 0} = 1)');

This will return when serialized in json:

{
    type: "Program",
    sourceType: "script",
    body: [
        {
            type: "ExpressionStatement",
            expression: {
                type: "AssignmentExpression",
                left: {
                    type: "ObjectPattern",
                    properties: [
                        {
                            type: "Property",
                            key: {
                                type: "Identifier",
                                name: "x"
                            },
                            value: {
                                type: "AssignmentPattern",
                                left: {
                                    type: "ArrayPattern",
                                    elements: [
                                        {
                                            "type": "Identifier",
                                            "name": "y"
                                        }
                                    ]
                                },
                                right: {
                                    type: "Literal",
                                    value: 0
                                }
                            },
                            kind: "init",
                            computed: false,
                            method: false,
                            shorthand: false
                        }
                    ]
                },
                operator: "=",
                right: {
                    type: "Literal",
                    value: 1
                }
            }
        }
    ]
}

Options

The second argument allows you to specify various options:

Option Description
directives Enable directive prologue to each literal node
globalReturn Allow return in the global scope
impliedStrict Enable strict mode (initial enforcement)
module Allow parsing with module goal
next Allow parsing with ESNext features
raw Attach raw property to each literal node
webcompat Enable web compability