eslint-plugin-mocha
Version:
Eslint rules for mocha.
27 lines • 1.27 kB
JavaScript
import { filterWithArgs, flatMapWithArgs, mapWithArgs } from '../list.js';
import { getUniqueBaseNames } from '../mocha/path.js';
import { initialReferenceToResolvedReference } from './resolved-reference.js';
function matchIdentifierName(reference, nameToMatch) {
return reference.identifier.name === nameToMatch;
}
function findGlobalVariableReferences(globalScope, name) {
const variable = globalScope.set.get(name);
if (variable !== undefined && variable.defs.length === 0) {
return variable.references;
}
return filterWithArgs(globalScope.through, matchIdentifierName, name);
}
function resolveGlobalReferencesByBaseName(baseName, globalScope, sourceCode) {
const referencesByName = findGlobalVariableReferences(globalScope, baseName);
return mapWithArgs(referencesByName, initialReferenceToResolvedReference, sourceCode);
}
export function findGlobalReferencesByName(context, names) {
const { sourceCode } = context;
const { globalScope } = sourceCode.scopeManager;
const baseNames = getUniqueBaseNames(names);
if (globalScope === null) {
return [];
}
return flatMapWithArgs(baseNames, resolveGlobalReferencesByBaseName, globalScope, sourceCode);
}
//# sourceMappingURL=find-global-references.js.map