-
-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: added JS doc comments and tsconfig #530
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,24 @@ import TokenTranslator from "./token-translator.js"; | |
import { normalizeOptions } from "./options.js"; | ||
|
||
|
||
/** | ||
* @typedef {import("acorn")} acorn | ||
* @typedef {import("./token-translator").Range} Range | ||
* @typedef {import("./token-translator").Location} Location | ||
*/ | ||
|
||
const STATE = Symbol("espree's internal state"); | ||
const ESPRIMA_FINISH_NODE = Symbol("espree's esprimaFinishNode"); | ||
|
||
/** | ||
* @typedef {Object} EsprimaComment | ||
* @property {"Block"|"Line"} type Type of the comment, can either be "Block" (multiline) or "Line" (single line). | ||
* @property {string} text Contents of the comment. | ||
* @property {number|undefined} start Start index of the comment in source code. | ||
* @property {number|undefined} end End index of the comment in source code. | ||
* @property {Range|undefined} range The [start, end] range of a comment. | ||
* @property {Location} loc Location of the comment. | ||
*/ | ||
|
||
/** | ||
* Converts an Acorn comment to a Esprima comment. | ||
|
@@ -15,7 +30,7 @@ const ESPRIMA_FINISH_NODE = Symbol("espree's esprimaFinishNode"); | |
* @param {int} end The index at which the comment ends. | ||
* @param {Location} startLoc The location at which the comment starts. | ||
* @param {Location} endLoc The location at which the comment ends. | ||
* @returns {Object} The comment object. | ||
* @returns {EsprimaComment} The comment object. | ||
* @private | ||
*/ | ||
function convertAcornCommentToEsprimaComment(block, text, start, end, startLoc, endLoc) { | ||
|
@@ -40,7 +55,12 @@ function convertAcornCommentToEsprimaComment(block, text, start, end, startLoc, | |
return comment; | ||
} | ||
|
||
export default () => Parser => { | ||
/** | ||
* Takes an acorn Parser class and returns a new Parser extending from it. | ||
* @param {typeof acorn.Parser} Parser A base acorn parser class. | ||
* @returns {typeof acorn.Parser} An espree parser extending the base acorn parser. | ||
*/ | ||
function extendAcornParser(Parser) { | ||
const tokTypes = Object.assign({}, Parser.acorn.tokTypes); | ||
|
||
if (Parser.acornJsx) { | ||
|
@@ -232,7 +252,7 @@ export default () => Parser => { | |
|
||
/** | ||
* Overwrites the default raise method to throw Esprima-style errors. | ||
* @param {int} pos The position of the error. | ||
* @param {number} pos The position of the error. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just wondering, this isn't related to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, this was presumably done to simplify the fact that TS (and JS) doesn't distinguish regular integers and the number type. I think it would be ideal to preserve this though so as to clarify the intent, e.g., for autocomplete. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But then passing a number wouldn't satisfy TS's typechecker, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
* @param {string} message The error message. | ||
* @throws {SyntaxError} A syntax error. | ||
* @returns {void} | ||
|
@@ -249,7 +269,7 @@ export default () => Parser => { | |
|
||
/** | ||
* Overwrites the default raise method to throw Esprima-style errors. | ||
* @param {int} pos The position of the error. | ||
* @param {number} pos The position of the error. | ||
* @param {string} message The error message. | ||
* @throws {SyntaxError} A syntax error. | ||
* @returns {void} | ||
|
@@ -260,7 +280,7 @@ export default () => Parser => { | |
|
||
/** | ||
* Overwrites the default unexpected method to throw Esprima-style errors. | ||
* @param {int} pos The position of the error. | ||
* @param {number} pos The position of the error. | ||
* @throws {SyntaxError} A syntax error. | ||
* @returns {void} | ||
*/ | ||
|
@@ -305,8 +325,8 @@ export default () => Parser => { | |
|
||
/** | ||
* Performs last-minute Esprima-specific compatibility checks and fixes. | ||
* @param {ASTNode} result The node to check. | ||
* @returns {ASTNode} The finished node. | ||
* @param {acorn.Node} result The node to check. | ||
* @returns {acorn.Node} The finished node. | ||
*/ | ||
[ESPRIMA_FINISH_NODE](result) { | ||
|
||
|
@@ -325,4 +345,7 @@ export default () => Parser => { | |
return result; | ||
} | ||
}; | ||
}; | ||
|
||
} | ||
|
||
export default () => extendAcornParser; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,16 +12,20 @@ | |
"require": "./dist/espree.cjs", | ||
"default": "./dist/espree.cjs" | ||
}, | ||
"./dist/espree.cjs" | ||
"./dist/espree.cjs", | ||
"./dist/lib" | ||
], | ||
"./package.json": "./package.json" | ||
}, | ||
"version": "9.3.1", | ||
"files": [ | ||
"lib", | ||
"dist/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" | ||
}, | ||
|
@@ -31,14 +35,15 @@ | |
}, | ||
"license": "BSD-2-Clause", | ||
"dependencies": { | ||
"acorn": "^8.7.0", | ||
"acorn-jsx": "^5.3.1", | ||
"acorn": "^8.7.1", | ||
"acorn-jsx": "^5.3.2", | ||
"eslint-visitor-keys": "^3.3.0" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^17.1.0", | ||
"@rollup/plugin-json": "^4.1.0", | ||
"@rollup/plugin-node-resolve": "^11.2.0", | ||
"@types/estree": "^0.0.51", | ||
"c8": "^7.11.0", | ||
"chai": "^4.3.4", | ||
"eslint": "^7.22.0", | ||
|
@@ -52,7 +57,9 @@ | |
"mocha": "^8.3.1", | ||
"npm-run-all": "^4.1.5", | ||
"rollup": "^2.41.2", | ||
"shelljs": "^0.3.0" | ||
"shelljs": "^0.3.0", | ||
"typescript": "^4.5.4", | ||
"unicode-6.3.0": "^0.7.5" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we're not using this dependency. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're using it in |
||
}, | ||
"keywords": [ | ||
"ast", | ||
|
@@ -69,7 +76,7 @@ | |
"test": "npm-run-all -p unit lint", | ||
"lint": "eslint \"*.?(c)js\" lib/ tests/lib/", | ||
"fixlint": "npm run lint -- --fix", | ||
"build": "rollup -c rollup.config.js", | ||
"build": "rollup -c rollup.config.js && tsc --build", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need the |
||
"update-version": "node tools/update-version.js", | ||
"pretest": "npm run build", | ||
"prepublishOnly": "npm run update-version && npm run build", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"include": ["lib/**/*", "espree.js"], | ||
"compilerOptions": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, good point There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure it has any effects - we don't have ts code, and didn't enable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, you could be right, I thought there might be some stricter behavior/validation it might enable. Regardless, it probably wouldn't hurt to use it, especially in case we add |
||
"allowJs": true, | ||
aladdin-add marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"declaration": true, | ||
"emitDeclarationOnly": true, | ||
"outDir": "dist", | ||
"declarationMap": true, | ||
"strict": true | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.