Permalink
Cannot retrieve contributors at this time
50 lines (48 sloc)
1.79 KB
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
codeql-action/node_modules/eslint-plugin-jsx-a11y/lib/util/mayContainChildComponent.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports["default"] = mayContainChildComponent; | |
var _jsxAstUtils = require("jsx-ast-utils"); | |
var _minimatch = _interopRequireDefault(require("minimatch")); | |
/** | |
* Returns true if it can positively determine that the element lacks an | |
* accessible label. If no determination is possible, it returns false. Treat | |
* false as an unknown value. The element might still have an accessible label, | |
* but this module cannot determine it positively. | |
* | |
* | |
*/ | |
function mayContainChildComponent(root, componentName) { | |
var maxDepth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; | |
var elementType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _jsxAstUtils.elementType; | |
function traverseChildren(node, depth) { | |
// Bail when maxDepth is exceeded. | |
if (depth > maxDepth) { | |
return false; | |
} | |
if (node.children) { | |
/* $FlowFixMe */ | |
for (var i = 0; i < node.children.length; i += 1) { | |
/* $FlowFixMe */ | |
var childNode = node.children[i]; | |
// Assume an expression container renders a label. It is the best we can | |
// do in this case. | |
if (childNode.type === 'JSXExpressionContainer') { | |
return true; | |
} | |
// Check for comonents with the provided name. | |
if (childNode.type === 'JSXElement' && childNode.openingElement && (0, _minimatch["default"])(elementType(childNode.openingElement), componentName)) { | |
return true; | |
} | |
if (traverseChildren(childNode, depth + 1)) { | |
return true; | |
} | |
} | |
} | |
return false; | |
} | |
return traverseChildren(root, 1); | |
} | |
module.exports = exports.default; |