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