From 33c2ba2fb3e71ce3613c4d1184f5453ef88c5fd5 Mon Sep 17 00:00:00 2001 From: Anix Date: Wed, 22 Apr 2020 12:59:43 +0000 Subject: [PATCH 1/3] Docs: documenting public API --- README.md | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 91 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a03d1c3e..988575d7 100644 --- a/README.md +++ b/README.md @@ -23,14 +23,101 @@ const espree = require("espree"); const ast = espree.parse(code); ``` -There is a second argument to `parse()` that allows you to specify various options: +## API + +### `parse()` + +`parse` parses the given code and returns a abstract syntax tree (AST). It takes two paramenter. + +- `code` [string]() - the code which needs to be parsed. +- `options (Optional)` [Object]() - read more about this [here](#options) ```javascript const espree = require("espree"); -// Optional second options argument with the following default settings -const ast = espree.parse(code, { +const ast = espree.parse(code, options); +``` + +**Example :** + +```js +const ast = espree.parse('let foo = "bar"', { ecmaVersion: 6 }); +console.log(ast); +``` + +
Output +

+ +``` +Node { + type: 'Program', + start: 0, + end: 15, + body: [ + Node { + type: 'VariableDeclaration', + start: 0, + end: 15, + declarations: [Array], + kind: 'let' + } + ], + sourceType: 'script' +} +``` + +

+
+ +### `tokenize()` + +`tokenize` returns the tokens of a give code. It takes two paramenter. + +- `code` [string]() - the code which needs to be parsed. +- `options (Optional)` [Object]() - read more about this [here](#options) + +Even if `options` is empty or undefined or `options.tokens` is `false`, it assigns it to `true` in order to get the `tokens` array + +**Example :** + +```js +const tokens = espree.tokenize('let foo = "bar"', { ecmaVersion: 6 }); +console.log(tokens); +``` + +
Output +

+ +``` +Token { type: 'Keyword', value: 'let', start: 0, end: 3 }, +Token { type: 'Identifier', value: 'foo', start: 4, end: 7 }, +Token { type: 'Punctuator', value: '=', start: 8, end: 9 }, +Token { type: 'String', value: '"bar"', start: 10, end: 15 } +``` + +

+
+ +### `version` + +Returns the current `espree` version + +### `VisitorKeys` + +Returns all visitor keys for traversing the AST from [eslint-visitor-keys](https://github.com/eslint/eslint-visitor-keys) + +### `latestEcmaVersion` + +Returns the latest ECMAScript supported by `espree` + +### `supportedEcmaVersions` + +Returns an array of all supported ECMAScript version + +## Options +```js +const options = { // attach range information to each node range: false, @@ -62,7 +149,7 @@ const ast = espree.parse(code, { // enable implied strict mode (if ecmaVersion >= 5) impliedStrict: false } -}); +} ``` ## Esprima Compatibility Going Forward From 14d7276320dd2c3a40a470d808e148f43c8b6424 Mon Sep 17 00:00:00 2001 From: Anix Date: Wed, 22 Apr 2020 13:10:26 +0000 Subject: [PATCH 2/3] Chore: created script to sync README --- Makefile.js | 8 +++-- docs/README.md | 95 +++++++++++++++++++++++++++++++++++++++++++++++--- package.json | 1 + 3 files changed, 97 insertions(+), 7 deletions(-) diff --git a/Makefile.js b/Makefile.js index 077624eb..7486680c 100644 --- a/Makefile.js +++ b/Makefile.js @@ -23,6 +23,7 @@ const path = require("path"); const NODE_MODULES = "./node_modules/", TEMP_DIR = "./tmp/", BUILD_DIR = "./build/", + DOCS_DIR = "./docs", // Utilities - intentional extra space at the end of each string MOCHA = `${NODE_MODULES}mocha/bin/_mocha `, @@ -92,9 +93,10 @@ target.test = function() { }; target.docs = function() { - echo("Generating documentation"); - nodeCLI.exec("jsdoc", "-d jsdoc lib"); - echo("Documentation has been output to /jsdoc"); + echo("Syncing README.md from root with docs/README.md"); + rm("-r", `${DOCS_DIR}/README.md`); + cp("README.md", DOCS_DIR); + echo("Done. "); }; target.browserify = function() { diff --git a/docs/README.md b/docs/README.md index a03d1c3e..988575d7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -23,14 +23,101 @@ const espree = require("espree"); const ast = espree.parse(code); ``` -There is a second argument to `parse()` that allows you to specify various options: +## API + +### `parse()` + +`parse` parses the given code and returns a abstract syntax tree (AST). It takes two paramenter. + +- `code` [string]() - the code which needs to be parsed. +- `options (Optional)` [Object]() - read more about this [here](#options) ```javascript const espree = require("espree"); -// Optional second options argument with the following default settings -const ast = espree.parse(code, { +const ast = espree.parse(code, options); +``` + +**Example :** + +```js +const ast = espree.parse('let foo = "bar"', { ecmaVersion: 6 }); +console.log(ast); +``` + +
Output +

+ +``` +Node { + type: 'Program', + start: 0, + end: 15, + body: [ + Node { + type: 'VariableDeclaration', + start: 0, + end: 15, + declarations: [Array], + kind: 'let' + } + ], + sourceType: 'script' +} +``` + +

+
+ +### `tokenize()` + +`tokenize` returns the tokens of a give code. It takes two paramenter. + +- `code` [string]() - the code which needs to be parsed. +- `options (Optional)` [Object]() - read more about this [here](#options) + +Even if `options` is empty or undefined or `options.tokens` is `false`, it assigns it to `true` in order to get the `tokens` array + +**Example :** + +```js +const tokens = espree.tokenize('let foo = "bar"', { ecmaVersion: 6 }); +console.log(tokens); +``` + +
Output +

+ +``` +Token { type: 'Keyword', value: 'let', start: 0, end: 3 }, +Token { type: 'Identifier', value: 'foo', start: 4, end: 7 }, +Token { type: 'Punctuator', value: '=', start: 8, end: 9 }, +Token { type: 'String', value: '"bar"', start: 10, end: 15 } +``` + +

+
+ +### `version` + +Returns the current `espree` version + +### `VisitorKeys` + +Returns all visitor keys for traversing the AST from [eslint-visitor-keys](https://github.com/eslint/eslint-visitor-keys) + +### `latestEcmaVersion` + +Returns the latest ECMAScript supported by `espree` + +### `supportedEcmaVersions` + +Returns an array of all supported ECMAScript version + +## Options +```js +const options = { // attach range information to each node range: false, @@ -62,7 +149,7 @@ const ast = espree.parse(code, { // enable implied strict mode (if ecmaVersion >= 5) impliedStrict: false } -}); +} ``` ## Esprima Compatibility Going Forward diff --git a/package.json b/package.json index 7eb1e66a..0e04a5f7 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "generate-regex": "node tools/generate-identifier-regex.js", "test": "npm run-script lint && node Makefile.js test", "lint": "node Makefile.js lint", + "sync-docs": "node Makefile.js docs", "browserify": "node Makefile.js browserify", "generate-release": "eslint-generate-release", "generate-alpharelease": "eslint-generate-prerelease alpha", From 86e837f79e288de4faa0d540f4197a57c76558e7 Mon Sep 17 00:00:00 2001 From: Anix Date: Wed, 22 Apr 2020 13:24:44 +0000 Subject: [PATCH 3/3] Chore: changed subMaxLevel to 3 --- docs/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.html b/docs/index.html index 684bdcab..2523f817 100644 --- a/docs/index.html +++ b/docs/index.html @@ -135,7 +135,7 @@ name: 'espree', repo: 'eslint/espree', loadSidebar: true, - subMaxLevel: 2, + subMaxLevel: 3, maxLevel: 3, auto2top: true, search: {