@jsxtools/eslint-plugin-jsx-a11y
Version:
Static AST checker for accessibility rules on JSX elements for flat ESLint Config.
29 lines (26 loc) • 896 B
JavaScript
import minimatch from 'minimatch';
import { elementType } from './module/jsx-ast-utils.js';
function mayContainChildComponent(root, componentName, maxDepth = 1, elementType$1 = 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(elementType$1(childNode.openingElement), componentName)) {
return true;
}
if (traverseChildren(childNode, depth + 1)) {
return true;
}
}
}
return false;
}
return traverseChildren(root, 1);
}
export { mayContainChildComponent as default };