diff options
| author | Node.js GitHub Bot <github-bot@iojs.org> | 2023-04-08 00:12:53 +0000 |
|---|---|---|
| committer | Node.js GitHub Bot <github-bot@iojs.org> | 2023-04-10 06:11:48 +0000 |
| commit | 270e24f0f7e8a6692f5fa17516458428255897a1 (patch) | |
| tree | ddbe925840ed64c9881d31ef2e4ff8b7282cde16 /tools/node_modules/eslint/lib/source-code/source-code.js | |
| parent | 2d1934aa9638e5691f3334a590294c70a5b983eb (diff) | |
| download | node-new-270e24f0f7e8a6692f5fa17516458428255897a1.tar.gz | |
tools: update eslint to 8.38.0
PR-URL: https://github.com/nodejs/node/pull/47475
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Diffstat (limited to 'tools/node_modules/eslint/lib/source-code/source-code.js')
| -rw-r--r-- | tools/node_modules/eslint/lib/source-code/source-code.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/node_modules/eslint/lib/source-code/source-code.js b/tools/node_modules/eslint/lib/source-code/source-code.js index 7e1630cc73..abaefa8999 100644 --- a/tools/node_modules/eslint/lib/source-code/source-code.js +++ b/tools/node_modules/eslint/lib/source-code/source-code.js @@ -15,6 +15,12 @@ const Traverser = require("../shared/traverser"); //------------------------------------------------------------------------------ +// Type Definitions +//------------------------------------------------------------------------------ + +/** @typedef {import("eslint-scope").Variable} Variable */ + +//------------------------------------------------------------------------------ // Private //------------------------------------------------------------------------------ @@ -639,6 +645,42 @@ class SourceCode extends TokenStore { return this.scopeManager.scopes[0]; } + /** + * Gets all of the declared variables in the scope associated + * with `node`. This is a convenience method that passes through + * to the same method on the `scopeManager`. + * @param {ASTNode} node The node from which to retrieve the scope to check. + * @returns {Array<Variable>} An array of variable nodes representing + * the declared variables in the scope associated with `node`. + */ + getDeclaredVariables(node) { + return this.scopeManager.getDeclaredVariables(node); + } + + /* eslint-disable class-methods-use-this -- node is owned by SourceCode */ + /** + * Gets all the ancestors of a given node + * @param {ASTNode} node The node + * @returns {Array<ASTNode>} All the ancestor nodes in the AST, not including the provided node, starting + * from the root node at index 0 and going inwards to the parent node. + * @throws {TypeError} When `node` is missing. + */ + getAncestors(node) { + + if (!node) { + throw new TypeError("Missing required argument: node."); + } + + const ancestorsStartingAtParent = []; + + for (let ancestor = node.parent; ancestor; ancestor = ancestor.parent) { + ancestorsStartingAtParent.push(ancestor); + } + + return ancestorsStartingAtParent.reverse(); + } + /* eslint-enable class-methods-use-this -- node is owned by SourceCode */ + } module.exports = SourceCode; |
