source: frontend/node_modules/eslint-plugin-jsx-a11y/lib/util/mayContainChildComponent.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 2 weeks ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.8 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports["default"] = mayContainChildComponent;
7var _jsxAstUtils = require("jsx-ast-utils");
8var _minimatch = _interopRequireDefault(require("minimatch"));
9function _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
19function 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}
50module.exports = exports.default;
Note: See TracBrowser for help on using the repository browser.