Esprima .NET (BSD license) is a .NET port of the esprima.org project. It is a standard-compliant ECMAScript parser (also popularly known as JavaScript).
Branch: dev
Clone or download
AmateurMemetics and sebastienros Tidy up arrow functions (#91)
IFunction now uses INode meaning StatementBlock | Expression, so
ArrowFunctionExpression can implement IFunction.
Latest commit 29659c4 Feb 14, 2019

README.md

Build status NuGet

Esprima .NET (BSD license) is a .NET port of the esprima.org project. It is a standard-compliant ECMAScript parser (also popularly known as JavaScript).

Features

API

Esprima can be used to perform lexical analysis (tokenization) or syntactic analysis (parsing) of a JavaScript program.

A simple C# example:

var parser = new JavaScriptParser("const answer = 42");
var program = parser.ParseProgram();

Will return this when serialized in json:

{
    "type": "Program",
    "body": [
        {
            "type": "VariableDeclaration",
            "declarations": [
                {
                    "type": "VariableDeclarator",
                    "id": {
                        "type": "Identifier",
                        "name": "answer"
                    },
                    "init": {
                        "type": "Literal",
                        "value": 42,
                        "raw": "42"
                    }
                }
            ],
            "kind": "const"
        }
    ],
    "sourceType": "script"
}

Benchmarks

Here is a list of common JavaScript libraries and the time it takes to parse them, compared to the time it took for the same script using the original Esprima in Chrome.

Script Size Esprima .NET Esprima (Chrome)
underscore-1.5.2 43 KB 3.9 ms 6.6 ms
backbone-1.1.0 60 KB 4.4 ms 6.1 ms
mootools-1.4.5 163 KB 33.2 ms 29.8 ms
jquery-1.9.1 271 KB 44.2 ms 36.2 ms
yui-3.12.0 341 KB 27.6 ms 33.4 ms
jquery.mobile-1.4.2 456 K 65.4 ms 159.1 ms
angular-1.2.5 721 KB 56.6 ms 98.4 ms