GithubHelp home page GithubHelp logo

happy-ferret / meriyah Goto Github PK

View Code? Open in Web Editor NEW

This project forked from meriyah/meriyah

0.0 1.0 0.0 5.69 MB

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

License: ISC License

TypeScript 99.81% JavaScript 0.19%

meriyah's Introduction

Meriyah

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
  • Emits an ESTree-compatible abstract syntax tree.
  • No backtracking
  • Reduced memory usage
  • Very well tested (~81 000 unit tests with full code coverage))
  • Lightweight - ~76 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)
lexical Enable lexical binding and scope tracking
loc Enable line/column location information to each node
module Allow parsing with module goal
next Allow parsing with ESNext features
parenthesizedExpr Enable non-standard parenthesized expression node
raw Attach raw property to each literal node
ranges Append start and end offsets to each node
source Adds a source attribute in every node’s loc object when the locations option is true.
webcompat Enable web compability

ECMAScript compability

Out of the box Meriyah is 100% ECMA spec compatible, but it's main focus is on performance. Therefore, you must enable several options by your own choice to make sure your code parses with 100% ECMA spec compability.

Also note that support for additional ECMAScript features for Web Browsers (annexB) isn't enabled by default as in other parsers, but you can instead parse with and without web compability .

This is done because AnnexB is an extension of the language, and also Test262 have this off by default and has it own web compat tests separated from the main tests.

Lexical binding and scope tracking has to be enabled with the lexical option.

meriyah's People

Contributors

kflash avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.