isAbstractRole.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports["default"] = void 0;
  7. var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
  8. var _ariaQuery = require("aria-query");
  9. var _jsxAstUtils = require("jsx-ast-utils");
  10. var abstractRoles = new Set((0, _toConsumableArray2["default"])(_ariaQuery.roles.keys()).filter(function (role) {
  11. return _ariaQuery.roles.get(role)["abstract"];
  12. }));
  13. var DOMElements = (0, _toConsumableArray2["default"])(_ariaQuery.dom.keys());
  14. var isAbstractRole = function isAbstractRole(tagName, attributes) {
  15. // Do not test higher level JSX components, as we do not know what
  16. // low-level DOM element this maps to.
  17. if (DOMElements.indexOf(tagName) === -1) {
  18. return false;
  19. }
  20. var role = (0, _jsxAstUtils.getLiteralPropValue)((0, _jsxAstUtils.getProp)(attributes, 'role'));
  21. return abstractRoles.has(role);
  22. };
  23. var _default = isAbstractRole;
  24. exports["default"] = _default;