diff --git a/docs/.nojekyll b/docs/.nojekyll new file mode 100644 index 00000000..e69de29b diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 00000000..a03d1c3e --- /dev/null +++ b/docs/README.md @@ -0,0 +1,164 @@ +[![npm version](https://img.shields.io/npm/v/espree.svg)](https://www.npmjs.com/package/espree) +[![Build Status](https://travis-ci.org/eslint/espree.svg?branch=master)](https://travis-ci.org/eslint/espree) +[![npm downloads](https://img.shields.io/npm/dm/espree.svg)](https://www.npmjs.com/package/espree) +[![Bountysource](https://www.bountysource.com/badge/tracker?tracker_id=9348450)](https://www.bountysource.com/trackers/9348450-eslint?utm_source=9348450&utm_medium=shield&utm_campaign=TRACKER_BADGE) + +# Espree + +Espree started out as a fork of [Esprima](http://esprima.org) v1.2.2, the last stable published released of Esprima before work on ECMAScript 6 began. Espree is now built on top of [Acorn](https://github.com/ternjs/acorn), which has a modular architecture that allows extension of core functionality. The goal of Espree is to produce output that is similar to Esprima with a similar API so that it can be used in place of Esprima. + +## Usage + +Install: + +``` +npm i espree +``` + +And in your Node.js code: + +```javascript +const espree = require("espree"); + +const ast = espree.parse(code); +``` + +There is a second argument to `parse()` that allows you to specify various options: + +```javascript +const espree = require("espree"); + +// Optional second options argument with the following default settings +const ast = espree.parse(code, { + + // attach range information to each node + range: false, + + // attach line/column location information to each node + loc: false, + + // create a top-level comments array containing all comments + comment: false, + + // create a top-level tokens array containing all tokens + tokens: false, + + // Set to 3, 5 (default), 6, 7, 8, 9, or 10 to specify the version of ECMAScript syntax you want to use. + // You can also set to 2015 (same as 6), 2016 (same as 7), 2017 (same as 8), 2018 (same as 9), 2019 (same as 10), or 2020 (same as 11) to use the year-based naming. + ecmaVersion: 5, + + // specify which type of script you're parsing ("script" or "module") + sourceType: "script", + + // specify additional language features + ecmaFeatures: { + + // enable JSX parsing + jsx: false, + + // enable return in global scope + globalReturn: false, + + // enable implied strict mode (if ecmaVersion >= 5) + impliedStrict: false + } +}); +``` + +## Esprima Compatibility Going Forward + +The primary goal is to produce the exact same AST structure and tokens as Esprima, and that takes precedence over anything else. (The AST structure being the [ESTree](https://github.com/estree/estree) API with JSX extensions.) Separate from that, Espree may deviate from what Esprima outputs in terms of where and how comments are attached, as well as what additional information is available on AST nodes. That is to say, Espree may add more things to the AST nodes than Esprima does but the overall AST structure produced will be the same. + +Espree may also deviate from Esprima in the interface it exposes. + +## Contributing + +Issues and pull requests will be triaged and responded to as quickly as possible. We operate under the [ESLint Contributor Guidelines](http://eslint.org/docs/developer-guide/contributing), so please be sure to read them before contributing. If you're not sure where to dig in, check out the [issues](https://github.com/eslint/espree/issues). + +Espree is licensed under a permissive BSD 2-clause license. + +## Build Commands + +* `npm test` - run all linting and tests +* `npm run lint` - run all linting +* `npm run browserify` - creates a version of Espree that is usable in a browser + +## Differences from Espree 2.x + +* The `tokenize()` method does not use `ecmaFeatures`. Any string will be tokenized completely based on ECMAScript 6 semantics. +* Trailing whitespace no longer is counted as part of a node. +* `let` and `const` declarations are no longer parsed by default. You must opt-in by using an `ecmaVersion` newer than `5` or setting `sourceType` to `module`. +* The `esparse` and `esvalidate` binary scripts have been removed. +* There is no `tolerant` option. We will investigate adding this back in the future. + +## Known Incompatibilities + +In an effort to help those wanting to transition from other parsers to Espree, the following is a list of noteworthy incompatibilities with other parsers. These are known differences that we do not intend to change. + +### Esprima 1.2.2 + +* Esprima counts trailing whitespace as part of each AST node while Espree does not. In Espree, the end of a node is where the last token occurs. +* Espree does not parse `let` and `const` declarations by default. +* Error messages returned for parsing errors are different. +* There are two addition properties on every node and token: `start` and `end`. These represent the same data as `range` and are used internally by Acorn. + +### Esprima 2.x + +* Esprima 2.x uses a different comment attachment algorithm that results in some comments being added in different places than Espree. The algorithm Espree uses is the same one used in Esprima 1.2.2. + +## Frequently Asked Questions + +### Why another parser + +[ESLint](http://eslint.org) had been relying on Esprima as its parser from the beginning. While that was fine when the JavaScript language was evolving slowly, the pace of development increased dramatically and Esprima had fallen behind. ESLint, like many other tools reliant on Esprima, has been stuck in using new JavaScript language features until Esprima updates, and that caused our users frustration. + +We decided the only way for us to move forward was to create our own parser, bringing us inline with JSHint and JSLint, and allowing us to keep implementing new features as we need them. We chose to fork Esprima instead of starting from scratch in order to move as quickly as possible with a compatible API. + +With Espree 2.0.0, we are no longer a fork of Esprima but rather a translation layer between Acorn and Esprima syntax. This allows us to put work back into a community-supported parser (Acorn) that is continuing to grow and evolve while maintaining an Esprima-compatible parser for those utilities still built on Esprima. + +### Have you tried working with Esprima? + +Yes. Since the start of ESLint, we've regularly filed bugs and feature requests with Esprima and will continue to do so. However, there are some different philosophies around how the projects work that need to be worked through. The initial goal was to have Espree track Esprima and eventually merge the two back together, but we ultimately decided that building on top of Acorn was a better choice due to Acorn's plugin support. + +### Why don't you just use Acorn? + +Acorn is a great JavaScript parser that produces an AST that is compatible with Esprima. Unfortunately, ESLint relies on more than just the AST to do its job. It relies on Esprima's tokens and comment attachment features to get a complete picture of the source code. We investigated switching to Acorn, but the inconsistencies between Esprima and Acorn created too much work for a project like ESLint. + +We are building on top of Acorn, however, so that we can contribute back and help make Acorn even better. + +### What ECMAScript 6 features do you support? + +All of them. + +### What ECMAScript 7/2016 features do you support? + +There is only one ECMAScript 2016 syntax change: the exponentiation operator. Espree supports this. + +### What ECMAScript 2017 features do you support? + +There are two ECMAScript 2017 syntax changes: `async` functions, and trailing commas in function declarations and calls. Espree supports both of them. + +### What ECMAScript 2018 features do you support? + +There are seven ECMAScript 2018 syntax changes: + +* Invalid escape sequences in tagged template literals +* Rest/spread properties +* Async iteration +* RegExp `s` flag +* RegExp named capture groups +* RegExp lookbehind assertions +* RegExp Unicode property escapes + +Espree supports all of them. + +### What ECMAScript 2019 features do you support? + +Because ECMAScript 2019 is still under development, we are implementing features as they are finalized. Currently, Espree supports: + +* Optional `catch` binding +* JSON superset (`\u2028` and `\u2029` in string literals) + +### How do you determine which experimental features to support? + +In general, we do not support experimental JavaScript features. We may make exceptions from time to time depending on the maturity of the features. diff --git a/docs/_sidebar.md b/docs/_sidebar.md new file mode 100644 index 00000000..ad4b03b4 --- /dev/null +++ b/docs/_sidebar.md @@ -0,0 +1,4 @@ +- [**Demo**](https://astexplorer.net/) +- [**Home**](/) +- [**Tokens**](tokens.md) +- [**AST**](ast/literal.md) diff --git a/docs/assets/css/style.css b/docs/assets/css/style.css new file mode 100644 index 00000000..7e210a5a --- /dev/null +++ b/docs/assets/css/style.css @@ -0,0 +1,198 @@ +/* +CUSTOM THEME ON TOP OF DEFAULT DOCSIFY THEME +*/ + +:root { + --theme-color: #4b32c3; +} +.markdown-section p { + font-size: 1.125rem; + line-height: 1.7; +} +.nav { + width: var(--toc-width, 15rem); + align-self: flex-start; + flex: 0 0 auto; +} +.page_toc { + max-width: 18rem; + top: calc(9.5rem); + width: 20rem; + overflow: auto; +} +.nav .page_toc p:nth-child(1) { + color: #78757a; + font-size: 0.875rem; + letter-spacing: 0.075em; + margin-top: 0rem; + text-transform: uppercase; +} +.sidebar { + -webkit-flex-shrink: 0; + -ms-flex-negative: 0; + flex-shrink: 0; + width: 312px; + height: 100vh; + padding: 24px; + border-right: 1px solid #dee2e7; + overflow-y: auto; + position: -webkit-sticky; + position: sticky; + top: 0; +} +.sidebar > .app-name { + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + -webkit-box-pack: justify; + -webkit-justify-content: space-between; + -ms-flex-pack: justify; + justify-content: space-between; + margin-bottom: 32px; +} +.sidebar .app-name .app-name-link:hover { + background-color: #4b32c3; + color: white; +} +.sidebar ul li > a { + padding: 0px 10px; + border-radius: 4px; + border-top-right-radius: 0; + border-bottom-right-radius: 0; + padding: 0px 10px; + border-radius: 4px; + border-top-right-radius: 0; + border-bottom-right-radius: 0; + margin: 0; + font-weight: 400; + -webkit-letter-spacing: 0.1em; + -moz-letter-spacing: 0.1em; + -ms-letter-spacing: 0.1em; + letter-spacing: 0.1em; + color: inherit; +} +.sidebar ul li.active > a { + background: #f5f5f5; +} + +.sidebar li > p { + margin: 0; + font-weight: bold; + -webkit-letter-spacing: 0.142em; + -moz-letter-spacing: 0.142em; + -ms-letter-spacing: 0.142em; + letter-spacing: 0.142em; + text-transform: uppercase; + color: inherit; +} +.sidebar .app-name .app-name-link { + background-color: #907af9; + border-radius: 4px; + border-width: 0; + cursor: pointer; + display: -webkit-inline-box; + display: -webkit-inline-flex; + display: -ms-inline-flexbox; + display: inline-flex; + -webkit-box-pack: center; + -webkit-justify-content: center; + -ms-flex-pack: center; + justify-content: center; + padding: 0 12px; + font-family: 'Source Sans Pro', sans-serif; + line-height: 1.54; + font-weight: 600; + outline: 0; + -webkit-text-decoration: none; + text-decoration: none; + white-space: nowrap; + width: 100%; +} +.markdown-section h1 { + font-size: 2.5rem; + font-weight: 400; + line-height: 1.1; + color: #2f353f; +} +.search { + margin-bottom: 20px; + padding: 6px; + border-bottom: none; +} +.search input { + width: 100%; + background-color: #f5f5f5; + padding-left: 2rem; +} + +/* CHANGELOG PLUGIN STYLING */ + +#CHANGELOG, +.app-nav { + background-color: transparent !important; +} + +@media screen and (max-width: 768px) { + #CHANGELOG:hover { + background: #fff2dc; + } + + #CHANGELOG { + margin: 1rem; + position: absolute; + left: 0; + } +} + +/* PAGINATION PLUGIN STYLING */ + +.pagination-item--next, +.pagination-item--previous { + width: 45%; + padding: 10px; + border: 1px solid var(--theme-color); + border-radius: 4px; + max-width: 45%; +} + +@media screen and (max-width: 768px) { + .pagination-item--next, + .pagination-item--previous { + width: 100%; + padding: 10px; + border: 1px solid var(--theme-color); + border-radius: 4px; + max-width: 100%; + } +} + +/* TOC PLUGIN STYLING */ + +.markdown-section { + margin: 0 auto; + max-width: 65%; + padding: 30px 15px 40px 15px; + position: relative; +} + +.page_toc { + width: unset; +} + +@media screen and (max-width: 1300px) { + .markdown-section { + margin: 0 48px; + max-width: 100%; + padding: 30px 15px 40px 15px; + position: relative; + } + + .page_toc { + display: none; + } +} diff --git a/docs/assets/img/android-icon-144x144.png b/docs/assets/img/android-icon-144x144.png new file mode 100644 index 00000000..98aa6079 Binary files /dev/null and b/docs/assets/img/android-icon-144x144.png differ diff --git a/docs/assets/img/android-icon-192x192.png b/docs/assets/img/android-icon-192x192.png new file mode 100644 index 00000000..19c120ea Binary files /dev/null and b/docs/assets/img/android-icon-192x192.png differ diff --git a/docs/assets/img/android-icon-36x36.png b/docs/assets/img/android-icon-36x36.png new file mode 100644 index 00000000..be6fcf03 Binary files /dev/null and b/docs/assets/img/android-icon-36x36.png differ diff --git a/docs/assets/img/android-icon-48x48.png b/docs/assets/img/android-icon-48x48.png new file mode 100644 index 00000000..03fa9cb6 Binary files /dev/null and b/docs/assets/img/android-icon-48x48.png differ diff --git a/docs/assets/img/android-icon-72x72.png b/docs/assets/img/android-icon-72x72.png new file mode 100644 index 00000000..94881fd5 Binary files /dev/null and b/docs/assets/img/android-icon-72x72.png differ diff --git a/docs/assets/img/android-icon-96x96.png b/docs/assets/img/android-icon-96x96.png new file mode 100644 index 00000000..9fb20e0f Binary files /dev/null and b/docs/assets/img/android-icon-96x96.png differ diff --git a/docs/assets/img/apple-icon-114x114.png b/docs/assets/img/apple-icon-114x114.png new file mode 100644 index 00000000..654baa3b Binary files /dev/null and b/docs/assets/img/apple-icon-114x114.png differ diff --git a/docs/assets/img/apple-icon-120x120.png b/docs/assets/img/apple-icon-120x120.png new file mode 100644 index 00000000..c7861ff9 Binary files /dev/null and b/docs/assets/img/apple-icon-120x120.png differ diff --git a/docs/assets/img/apple-icon-144x144.png b/docs/assets/img/apple-icon-144x144.png new file mode 100644 index 00000000..98aa6079 Binary files /dev/null and b/docs/assets/img/apple-icon-144x144.png differ diff --git a/docs/assets/img/apple-icon-152x152.png b/docs/assets/img/apple-icon-152x152.png new file mode 100644 index 00000000..479dd2e2 Binary files /dev/null and b/docs/assets/img/apple-icon-152x152.png differ diff --git a/docs/assets/img/apple-icon-180x180.png b/docs/assets/img/apple-icon-180x180.png new file mode 100644 index 00000000..65f9a28e Binary files /dev/null and b/docs/assets/img/apple-icon-180x180.png differ diff --git a/docs/assets/img/apple-icon-57x57.png b/docs/assets/img/apple-icon-57x57.png new file mode 100644 index 00000000..6f51daed Binary files /dev/null and b/docs/assets/img/apple-icon-57x57.png differ diff --git a/docs/assets/img/apple-icon-60x60.png b/docs/assets/img/apple-icon-60x60.png new file mode 100644 index 00000000..d10d7cf2 Binary files /dev/null and b/docs/assets/img/apple-icon-60x60.png differ diff --git a/docs/assets/img/apple-icon-72x72.png b/docs/assets/img/apple-icon-72x72.png new file mode 100644 index 00000000..94881fd5 Binary files /dev/null and b/docs/assets/img/apple-icon-72x72.png differ diff --git a/docs/assets/img/apple-icon-76x76.png b/docs/assets/img/apple-icon-76x76.png new file mode 100644 index 00000000..ef81a2b4 Binary files /dev/null and b/docs/assets/img/apple-icon-76x76.png differ diff --git a/docs/assets/img/apple-icon-precomposed.png b/docs/assets/img/apple-icon-precomposed.png new file mode 100644 index 00000000..fcfced15 Binary files /dev/null and b/docs/assets/img/apple-icon-precomposed.png differ diff --git a/docs/assets/img/apple-icon.png b/docs/assets/img/apple-icon.png new file mode 100644 index 00000000..fcfced15 Binary files /dev/null and b/docs/assets/img/apple-icon.png differ diff --git a/docs/assets/img/browserconfig.xml b/docs/assets/img/browserconfig.xml new file mode 100644 index 00000000..c5541482 --- /dev/null +++ b/docs/assets/img/browserconfig.xml @@ -0,0 +1,2 @@ + +#ffffff \ No newline at end of file diff --git a/docs/assets/img/favicon-16x16.png b/docs/assets/img/favicon-16x16.png new file mode 100644 index 00000000..44babfa4 Binary files /dev/null and b/docs/assets/img/favicon-16x16.png differ diff --git a/docs/assets/img/favicon-32x32.png b/docs/assets/img/favicon-32x32.png new file mode 100644 index 00000000..d9bbad5c Binary files /dev/null and b/docs/assets/img/favicon-32x32.png differ diff --git a/docs/assets/img/favicon-96x96.png b/docs/assets/img/favicon-96x96.png new file mode 100644 index 00000000..9fb20e0f Binary files /dev/null and b/docs/assets/img/favicon-96x96.png differ diff --git a/docs/assets/img/favicon.512x512.png b/docs/assets/img/favicon.512x512.png new file mode 100644 index 00000000..ee761fbb Binary files /dev/null and b/docs/assets/img/favicon.512x512.png differ diff --git a/docs/assets/img/favicon.ico b/docs/assets/img/favicon.ico new file mode 100644 index 00000000..476ef7b2 Binary files /dev/null and b/docs/assets/img/favicon.ico differ diff --git a/docs/assets/img/logo.svg b/docs/assets/img/logo.svg new file mode 100644 index 00000000..55a983f2 --- /dev/null +++ b/docs/assets/img/logo.svg @@ -0,0 +1,17 @@ + + + + + + + + + \ No newline at end of file diff --git a/docs/assets/img/manifest.json b/docs/assets/img/manifest.json new file mode 100644 index 00000000..013d4a6a --- /dev/null +++ b/docs/assets/img/manifest.json @@ -0,0 +1,41 @@ +{ + "name": "App", + "icons": [ + { + "src": "\/android-icon-36x36.png", + "sizes": "36x36", + "type": "image\/png", + "density": "0.75" + }, + { + "src": "\/android-icon-48x48.png", + "sizes": "48x48", + "type": "image\/png", + "density": "1.0" + }, + { + "src": "\/android-icon-72x72.png", + "sizes": "72x72", + "type": "image\/png", + "density": "1.5" + }, + { + "src": "\/android-icon-96x96.png", + "sizes": "96x96", + "type": "image\/png", + "density": "2.0" + }, + { + "src": "\/android-icon-144x144.png", + "sizes": "144x144", + "type": "image\/png", + "density": "3.0" + }, + { + "src": "\/android-icon-192x192.png", + "sizes": "192x192", + "type": "image\/png", + "density": "4.0" + } + ] +} \ No newline at end of file diff --git a/docs/assets/img/ms-icon-144x144.png b/docs/assets/img/ms-icon-144x144.png new file mode 100644 index 00000000..98aa6079 Binary files /dev/null and b/docs/assets/img/ms-icon-144x144.png differ diff --git a/docs/assets/img/ms-icon-150x150.png b/docs/assets/img/ms-icon-150x150.png new file mode 100644 index 00000000..bc81f7c9 Binary files /dev/null and b/docs/assets/img/ms-icon-150x150.png differ diff --git a/docs/assets/img/ms-icon-310x310.png b/docs/assets/img/ms-icon-310x310.png new file mode 100644 index 00000000..0c5800d9 Binary files /dev/null and b/docs/assets/img/ms-icon-310x310.png differ diff --git a/docs/assets/img/ms-icon-70x70.png b/docs/assets/img/ms-icon-70x70.png new file mode 100644 index 00000000..801dff5c Binary files /dev/null and b/docs/assets/img/ms-icon-70x70.png differ diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 00000000..684bdcab --- /dev/null +++ b/docs/index.html @@ -0,0 +1,187 @@ + + + + + + espree - An Esprima-compatible JavaScript parser built on Acorn + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + +