Skip to content

Commit

Permalink
refactor: Moved some inplace JSDoc imports out into custom typedefs
Browse files Browse the repository at this point in the history
  • Loading branch information
srijan-paul authored and srijanpaul-deepsource committed Mar 12, 2022
1 parent 1bc22a9 commit 582c660
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
4 changes: 3 additions & 1 deletion espree.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ import { getLatestEcmaVersion, getSupportedEcmaVersions } from "./lib/options.js
/**
* @typedef {import("acorn")} acorn
* @typedef {import("./lib/options").ParserOptions} ParserOptions
* @typedef {import("./lib/token-translator").EsprimaToken} EsprimaToken
* @typedef {import("./lib/token-translator").TokenRange} TokenRange
*/


Expand Down Expand Up @@ -107,7 +109,7 @@ const parsers = {
* Tokenizes the given code.
* @param {string} code The code to tokenize.
* @param {ParserOptions} options Options defining how to tokenize.
* @returns {import("./lib/token-translator.js").EsprimaToken[]} An array of tokens.
* @returns {EsprimaToken[]} An array of tokens.
* @throws {SyntaxError} If the input code is invalid.
* @private
*/
Expand Down
3 changes: 2 additions & 1 deletion lib/espree.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { normalizeOptions } from "./options.js";

/**
* @typedef {import("acorn")} acorn
* @typedef {import("./token-translator").Range} Range
*/

const STATE = Symbol("espree's internal state");
Expand All @@ -16,7 +17,7 @@ const ESPRIMA_FINISH_NODE = Symbol("espree's esprimaFinishNode");
* @property {string} text Contents of the comment.
* @property {number|undefined} start Start column of a comment.
* @property {number|undefined} end End column of the comment.
* @property {[number, number]|undefined} range The [start, end] range of a comment.
* @property {Range|undefined} range The [start, end] range of a comment.
* @property {acorn.Position} startLoc End location of the comment.
* @property {acorn.Position} endLoc End location of the comment.
*/
Expand Down
6 changes: 5 additions & 1 deletion lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ function normalizeSourceType(sourceType = "script") {
throw new Error("Invalid sourceType.");
}

/**
* @typedef {import("./features").EcmaFeatures} EcmaFeatures
*/

/**
* @typedef {Object} ParserOptions
* @property {boolean} range Whether to include the range information for each node.
Expand All @@ -90,7 +94,7 @@ function normalizeSourceType(sourceType = "script") {
* @property {number|"latest"} ecmaVersion The ECMAScript version to use (between 3 and 13, or 2015 and 2022, or "latest").
* @property {boolean} allowReserved Only allowed when `ecmaVersion` is set to 3.
* @property {"script"|"module"|"commonjs"} sourceType The kind of the source string being parsed.
* @property {import("./features").EcmaFeatures} ecmaFeatures The additional features to enable.
* @property {EcmaFeatures} ecmaFeatures The additional features to enable.
*/

/**
Expand Down
6 changes: 5 additions & 1 deletion lib/token-translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@
* @property {acorn.Position} end The end position.
*/

/**
* @typedef {[number, number]} Range
*/

/**
* @typedef {Object} EsprimaToken
* @property {string} type The type of this token.
* @property {string} value The string content of the token.
* @property {Location|undefined} loc Location in source text.
* @property {number|undefined} start start column.
* @property {number|undefined} end end column.
* @property {[number, number]|undefined} range [start, end] range
* @property {Range|undefined} range [start, end] range
*/

// Esprima Token Types
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
"files": [
"lib",
"dist/espree.cjs",
"dist/espree.d.ts",
"espree.js"
],
"types": "dist/espree.d.ts",
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
},
Expand Down

0 comments on commit 582c660

Please sign in to comment.