UNPKG

eslint-plugin-mocha

Version:

Eslint rules for mocha.

28 lines 1.34 kB
import { extractMemberExpressionPath } from "./member-expression.js"; import { getParentNode } from "./node-types.js"; function getNextReferenceNode(node) { const parent = getParentNode(node); if (parent.type === 'MemberExpression') { return parent; } if (parent.type !== 'CallExpression') { return null; } const grandparent = getParentNode(parent); return grandparent.type === 'MemberExpression' ? grandparent : null; } export function findParentNodeAndPathForIdentifier(sourceCode, node) { let currentNode = node; let nextReferenceNode = getNextReferenceNode(currentNode); while (nextReferenceNode !== null) { currentNode = nextReferenceNode; nextReferenceNode = getNextReferenceNode(currentNode); } return { node: getParentNode(currentNode), path: extractMemberExpressionPath(sourceCode, currentNode) }; } export function initialReferenceToResolvedReference(reference, sourceCode) { // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- due to the bad typing of eslint core, the type is missing the parent property but it has this property const { node, path } = findParentNodeAndPathForIdentifier(sourceCode, reference.identifier); return { node, path, resolvedPath: path }; } //# sourceMappingURL=resolved-reference.js.map