UNPKG

@jsxtools/eslint-plugin-jsx-a11y

Version:

Static AST checker for accessibility rules on JSX elements for flat ESLint Config.

29 lines (26 loc) 914 B
const minimatch = require('minimatch'); const jsxAstUtils = require('./module/jsx-ast-utils.cjs'); function mayContainChildComponent(root, componentName, maxDepth = 1, elementType = jsxAstUtils.elementType) { function traverseChildren(node, depth) { if (depth > maxDepth) { return false; } if (node.children) { for (let i = 0; i < node.children.length; i += 1) { const childNode = node.children[i]; if (childNode.type === "JSXExpressionContainer") { return true; } if (childNode.type === "JSXElement" && childNode.openingElement && minimatch.default(elementType(childNode.openingElement), componentName)) { return true; } if (traverseChildren(childNode, depth + 1)) { return true; } } } return false; } return traverseChildren(root, 1); } module.exports = mayContainChildComponent;