hasAccessibleChild.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports["default"] = hasAccessibleChild;
  7. var _jsxAstUtils = require("jsx-ast-utils");
  8. var _isHiddenFromScreenReader = _interopRequireDefault(require("./isHiddenFromScreenReader"));
  9. function hasAccessibleChild(node) {
  10. return node.children.some(function (child) {
  11. switch (child.type) {
  12. case 'Literal':
  13. case 'JSXText':
  14. return Boolean(child.value);
  15. case 'JSXElement':
  16. return !(0, _isHiddenFromScreenReader["default"])((0, _jsxAstUtils.elementType)(child.openingElement), child.openingElement.attributes);
  17. case 'JSXExpressionContainer':
  18. if (child.expression.type === 'Identifier') {
  19. return child.expression.name !== 'undefined';
  20. }
  21. return true;
  22. default:
  23. return false;
  24. }
  25. }) || (0, _jsxAstUtils.hasAnyProp)(node.openingElement.attributes, ['dangerouslySetInnerHTML', 'children']);
  26. }