-
-
Notifications
You must be signed in to change notification settings - Fork 354
/
is-shadowed.js
36 lines (30 loc) · 950 Bytes
/
is-shadowed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict';
const isSameNode = require('./is-same-node');
/**
* Finds the eslint-scope reference in the given scope.
* @param {Object} scope The scope to search.
* @param {ASTNode} node The identifier node.
* @returns {Reference|undefined} Returns the found reference or null if none were found.
*/
function findReference(scope, node) {
const references = scope.references
.filter(reference => isSameNode(reference.identifier, node));
if (references.length === 1) {
return references[0];
}
}
/**
* Checks if the given identifier node is shadowed in the given scope.
* @param {Object} scope The current scope.
* @param {string} node The identifier node to check
* @returns {boolean} Whether or not the name is shadowed.
*/
function isShadowed(scope, node) {
const reference = findReference(scope, node);
return (
reference &&
reference.resolved &&
reference.resolved.defs.length > 0
);
}
module.exports = isShadowed;