UNPKG

eslint-plugin-mocha

Version:

Eslint rules for mocha.

41 lines 1.24 kB
import { hasProperty, isRecord } from "../record.js"; import { isFunction } from "./node-types.js"; function getNodeProperty(node, key) { if (!isRecord(node)) { return undefined; } const record = node; return hasProperty(record, key) ? record[key] : undefined; } function isNode(value) { return isRecord(value) && hasProperty(value, 'type'); } export function visitChildNodes(sourceCode, node, visitor) { const visitorKeys = sourceCode.visitorKeys[node.type]; if (visitorKeys === undefined) { return; } for (const key of visitorKeys) { const value = getNodeProperty(node, key); if (Array.isArray(value)) { value.forEach(function (item) { if (isNode(item)) { visitor(item); } }); } else if (isNode(value)) { visitor(value); } } } export function visitWithoutNestedFunctions(sourceCode, node, visitor) { visitor(node); if (isFunction(node)) { return; } visitChildNodes(sourceCode, node, function (childNode) { visitWithoutNestedFunctions(sourceCode, childNode, visitor); }); } //# sourceMappingURL=visit-child-nodes.js.map