| [9af201e] | 1 | [](https://www.npmjs.com/package/esprima)
|
|---|
| 2 | [](https://www.npmjs.com/package/esprima)
|
|---|
| 3 | [](https://travis-ci.org/jquery/esprima)
|
|---|
| 4 | [](https://codecov.io/github/jquery/esprima)
|
|---|
| 5 |
|
|---|
| 6 | **Esprima** ([esprima.org](http://esprima.org), BSD license) is a high performance,
|
|---|
| 7 | standard-compliant [ECMAScript](http://www.ecma-international.org/publications/standards/Ecma-262.htm)
|
|---|
| 8 | parser written in ECMAScript (also popularly known as
|
|---|
| 9 | [JavaScript](https://en.wikipedia.org/wiki/JavaScript)).
|
|---|
| 10 | Esprima is created and maintained by [Ariya Hidayat](https://twitter.com/ariyahidayat),
|
|---|
| 11 | with the help of [many contributors](https://github.com/jquery/esprima/contributors).
|
|---|
| 12 |
|
|---|
| 13 | ### Features
|
|---|
| 14 |
|
|---|
| 15 | - Full support for ECMAScript 2017 ([ECMA-262 8th Edition](http://www.ecma-international.org/publications/standards/Ecma-262.htm))
|
|---|
| 16 | - Sensible [syntax tree format](https://github.com/estree/estree/blob/master/es5.md) as standardized by [ESTree project](https://github.com/estree/estree)
|
|---|
| 17 | - Experimental support for [JSX](https://facebook.github.io/jsx/), a syntax extension for [React](https://facebook.github.io/react/)
|
|---|
| 18 | - Optional tracking of syntax node location (index-based and line-column)
|
|---|
| 19 | - [Heavily tested](http://esprima.org/test/ci.html) (~1500 [unit tests](https://github.com/jquery/esprima/tree/master/test/fixtures) with [full code coverage](https://codecov.io/github/jquery/esprima))
|
|---|
| 20 |
|
|---|
| 21 | ### API
|
|---|
| 22 |
|
|---|
| 23 | Esprima can be used to perform [lexical analysis](https://en.wikipedia.org/wiki/Lexical_analysis) (tokenization) or [syntactic analysis](https://en.wikipedia.org/wiki/Parsing) (parsing) of a JavaScript program.
|
|---|
| 24 |
|
|---|
| 25 | A simple example on Node.js REPL:
|
|---|
| 26 |
|
|---|
| 27 | ```javascript
|
|---|
| 28 | > var esprima = require('esprima');
|
|---|
| 29 | > var program = 'const answer = 42';
|
|---|
| 30 |
|
|---|
| 31 | > esprima.tokenize(program);
|
|---|
| 32 | [ { type: 'Keyword', value: 'const' },
|
|---|
| 33 | { type: 'Identifier', value: 'answer' },
|
|---|
| 34 | { type: 'Punctuator', value: '=' },
|
|---|
| 35 | { type: 'Numeric', value: '42' } ]
|
|---|
| 36 |
|
|---|
| 37 | > esprima.parseScript(program);
|
|---|
| 38 | { type: 'Program',
|
|---|
| 39 | body:
|
|---|
| 40 | [ { type: 'VariableDeclaration',
|
|---|
| 41 | declarations: [Object],
|
|---|
| 42 | kind: 'const' } ],
|
|---|
| 43 | sourceType: 'script' }
|
|---|
| 44 | ```
|
|---|
| 45 |
|
|---|
| 46 | For more information, please read the [complete documentation](http://esprima.org/doc). |
|---|