Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

47 lignes
1.5 KiB

  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = mayContainChildComponent;
  6. var _jsxAstUtils = require('jsx-ast-utils');
  7. function mayContainChildComponent(root, componentName) {
  8. var maxDepth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
  9. function traverseChildren(node, depth) {
  10. // Bail when maxDepth is exceeded.
  11. if (depth > maxDepth) {
  12. return false;
  13. }
  14. if (node.children) {
  15. /* $FlowFixMe */
  16. for (var i = 0; i < node.children.length; i += 1) {
  17. /* $FlowFixMe */
  18. var childNode = node.children[i];
  19. // Assume an expression container renders a label. It is the best we can
  20. // do in this case.
  21. if (childNode.type === 'JSXExpressionContainer') {
  22. return true;
  23. }
  24. // Check for comonents with the provided name.
  25. if (childNode.type === 'JSXElement' && childNode.openingElement && (0, _jsxAstUtils.elementType)(childNode.openingElement) === componentName) {
  26. return true;
  27. }
  28. if (traverseChildren(childNode, depth + 1)) {
  29. return true;
  30. }
  31. }
  32. }
  33. return false;
  34. }
  35. return traverseChildren(root, 1);
  36. } /**
  37. * Returns true if it can positively determine that the element lacks an
  38. * accessible label. If no determination is possible, it returns false. Treat
  39. * false as an unknown value. The element might still have an accessible label,
  40. * but this module cannot determine it positively.
  41. *
  42. *
  43. */