Skip to content
A 100% compliant, self-hosted javascript parser - https://meriyah.github.io/meriyah
TypeScript JavaScript
Branch: master
Clone or download
Latest commit bbfc5c2 Nov 13, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci Support Node 6 Sep 7, 2019
.github/ISSUE_TEMPLATE docs(all): update bug_reports.md May 11, 2019
.vscode feat(parser): 'export' '*' 'as' IdentifierName 'from' ModuleSpecifier… Nov 5, 2019
bench chore(all): updated package.json May 31, 2019
scripts Merge pull request #13 from meriyah/chore/tslint-to-eslint Jul 1, 2019
src fix(parser): fixes #58 Nov 13, 2019
test test(parser): fixed module export tests Nov 7, 2019
.editorconfig feat(lexer): added lexer souce code May 7, 2019
.eslintrc.js Support Node 6 Sep 7, 2019
.gitignore
.mocharc.json Allow fast testing of specific files Nov 3, 2019
.npmrc feat(lexer): added lexer souce code May 7, 2019
.prettierignore feat(lexer): added lexer souce code May 7, 2019
LICENSE.md feat(lexer): added lexer souce code May 7, 2019
README.md Add onToken support based on Cherow Oct 18, 2019
_config.yml Set theme jekyll-theme-cayman May 21, 2019
package-lock.json chore(all): v. 1.8.6 Oct 20, 2019
package.json fix(parser): fixes #58 Nov 13, 2019
prettier.config.js feat(lexer): added lexer souce code May 7, 2019
tsconfig.json Allow fast testing of specific files Nov 3, 2019

README.md

Meriyah

100% compliant, self-hosted javascript parser with high focus on both performance and stability. Stable and already used in production.

Meriyah NPM GitHub license Total alerts Circle License


Demo

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
  • JSX support via option
  • Optionally track syntactic node locations
  • Emits an ESTree-compatible abstract syntax tree.
  • No backtracking
  • Low memory usage
  • Very well tested (~99 000 unit tests with full code coverage)
  • Lightweight - ~90 KB minified

ESNext features

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

Installation

npm install meriyah --save-dev

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.

This is the available options:

{
  // The flag to allow module code
  module: false;

  // The flag to enable stage 3 support (ESNext)
  next: false;

  // The flag to enable start and end offsets to each node
  ranges: false;

  // Enable web compability
  webcompat: false;

  // The flag to enable line/column location information to each node
  loc: false;

  // The flag to attach raw property to each literal and identifier node
  raw: false;

  // Enabled directives
  directives: false;

  // The flag to allow return in the global scope
  globalReturn: false;

  // The flag to enable implied strict mode
  impliedStrict: false;

  // Allows comment extraction. Accepts either a function or array
  onComment: []

  // Allows token extraction. Accepts either a function or array
  onToken: []

  // Enable non-standard parenthesized expression node
  preserveParens: false;

  // Enable lexical binding and scope tracking
  lexical: false;

  // Adds a source attribute in every node’s loc object when the locations option is `true`
  source: false;

  // Distinguish Identifier from IdentifierPattern
  identifierPattern: false;

   // Enable React JSX parsing
  jsx: false

  // Allow edge cases that deviate from the spec
  specDeviation: false
}

Example usage:

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
                }
            }
        }
    ]
}
You can’t perform that action at this time.