UNPKG

@jsxtools/eslint-plugin-jsx-a11y

Version:

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

28 lines (25 loc) 887 B
const jsxAstUtils = require('./module/jsx-ast-utils.cjs'); const isHiddenFromScreenReader = require('./isHiddenFromScreenReader.cjs'); function hasAccessibleChild(node, elementType) { return node.children.some((child) => { switch (child.type) { case "Literal": return !!child.value; case "JSXText": return !!child.value; case "JSXElement": return !isHiddenFromScreenReader( elementType(child.openingElement), child.openingElement.attributes ); case "JSXExpressionContainer": if (child.expression.type === "Identifier") { return child.expression.name !== "undefined"; } return true; default: return false; } }) || jsxAstUtils.hasAnyProp(node.openingElement.attributes, ["dangerouslySetInnerHTML", "children"]); } module.exports = hasAccessibleChild;