All Projects → meriyah → Meriyah

meriyah / Meriyah

Licence: isc
A 100% compliant, self-hosted javascript parser - https://meriyah.github.io/meriyah

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
ecmascript
72 projects
esnext
17 projects

Projects that are alternatives of or similar to Meriyah

Escaya
An blazing fast 100% spec compliant, incremental javascript parser written in Typescript
Stars: ✭ 217 (-68.55%)
Mutual labels:  tc39, ast, parser, parsing, performance
Esprima
ECMAScript parsing infrastructure for multipurpose analysis
Stars: ✭ 6,391 (+826.23%)
Mutual labels:  ast, parser, parsing
Libdparse
Library for lexing and parsing D source code
Stars: ✭ 91 (-86.81%)
Mutual labels:  ast, parser, parsing
Ratel Core
High performance JavaScript to JavaScript compiler with a Rust core
Stars: ✭ 367 (-46.81%)
Mutual labels:  ast, parser, performance
Graphql Go Tools
Tools to write high performance GraphQL applications using Go/Golang.
Stars: ✭ 96 (-86.09%)
Mutual labels:  ast, parser, parsing
Buntis
A 100% compliant, self-hosted typescript parser that emits an ESTree-compatible AST
Stars: ✭ 90 (-86.96%)
Mutual labels:  tc39, parsing, performance
Cherow
Very fast and lightweight, standards-compliant, self-hosted javascript parser with high focus on both performance and stability
Stars: ✭ 1,539 (+123.04%)
Mutual labels:  tc39, parsing, performance
Seafox
A blazing fast 100% spec compliant, self-hosted javascript parser written in Typescript
Stars: ✭ 425 (-38.41%)
Mutual labels:  tc39, parser, parsing
Astroid
A common base representation of python source code for pylint and other projects
Stars: ✭ 310 (-55.07%)
Mutual labels:  ast, parser
Kgt
BNF wrangling and railroad diagrams
Stars: ✭ 312 (-54.78%)
Mutual labels:  parser, parsing
Estree
The ESTree Spec
Stars: ✭ 3,867 (+460.43%)
Mutual labels:  ast, parsing
Exprtk
C++ Mathematical Expression Parsing And Evaluation Library
Stars: ✭ 301 (-56.38%)
Mutual labels:  ast, parser
Bblfshd
A self-hosted server for source code parsing
Stars: ✭ 297 (-56.96%)
Mutual labels:  ast, parser
Jsqlparser
JSqlParser parses an SQL statement and translate it into a hierarchy of Java classes. The generated hierarchy can be navigated using the Visitor Pattern
Stars: ✭ 3,405 (+393.48%)
Mutual labels:  ast, parser
Binjs Ref
Reference implementation for the JavaScript Binary AST format
Stars: ✭ 399 (-42.17%)
Mutual labels:  parsing, performance
Astexplorer
A web tool to explore the ASTs generated by various parsers.
Stars: ✭ 4,330 (+527.54%)
Mutual labels:  ast, parser
Nearley
📜🔜🌲 Simple, fast, powerful parser toolkit for JavaScript.
Stars: ✭ 3,089 (+347.68%)
Mutual labels:  parser, parsing
Javaparser
Java 1-15 Parser and Abstract Syntax Tree for Java, including preview features to Java 13
Stars: ✭ 3,972 (+475.65%)
Mutual labels:  ast, parser
Php Parser
🌿 NodeJS PHP Parser - extract AST or tokens (PHP5 and PHP7)
Stars: ✭ 400 (-42.03%)
Mutual labels:  ast, parser
Tenko
An 100% spec compliant ES2021 JavaScript parser written in JS
Stars: ✭ 490 (-28.99%)
Mutual labels:  ast, parser

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® 2021 (ECMA-262 11th 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, end offsets and range: [start, end] to each node
  ranges: false;

  // Enable web compatibility
  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
}

onComment and onToken

If an array is supplied, comments/tokens will be pushed to the array, the item in the array contains start/end/range information when ranges flag is true, it will also contain loc information when loc flag is true.

If a function callback is supplied, the signature must be

function onComment(type: string, value: string, start: number, end: number, loc: SourceLocation): void {}

function onToken(token: string, start: number, end: number, loc: SourceLocation): void {}

Note the start/end/loc information are provided to the function callback regardless of the settings on ranges and loc flags. onComment callback has one extra argument value: string for the body string of the comment.

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
                }
            }
        }
    ]
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].