isSemanticRoleElement.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports["default"] = void 0;
  6. var _axobjectQuery = require("axobject-query");
  7. var _jsxAstUtils = require("jsx-ast-utils");
  8. var isSemanticRoleElement = function isSemanticRoleElement(elementType, attributes) {
  9. var roleAttr = (0, _jsxAstUtils.getProp)(attributes, 'role');
  10. var res = false;
  11. var roleAttrValue = (0, _jsxAstUtils.getLiteralPropValue)(roleAttr);
  12. _axobjectQuery.elementAXObjects.forEach(function (axObjects, concept) {
  13. if (res) {
  14. return;
  15. }
  16. if (concept.name === elementType && (concept.attributes || []).every(function (cAttr) {
  17. return attributes.some(function (attr) {
  18. if (!attr.type || attr.type !== 'JSXAttribute') {
  19. return false;
  20. }
  21. var namesMatch = cAttr.name === (0, _jsxAstUtils.propName)(attr);
  22. var valuesMatch;
  23. if (cAttr.value !== undefined) {
  24. valuesMatch = cAttr.value === (0, _jsxAstUtils.getLiteralPropValue)(attr);
  25. }
  26. if (!namesMatch) {
  27. return false;
  28. }
  29. return namesMatch && valuesMatch !== undefined ? valuesMatch : true;
  30. });
  31. })) {
  32. axObjects.forEach(function (name) {
  33. if (res) {
  34. return;
  35. }
  36. var roles = _axobjectQuery.AXObjectRoles.get(name);
  37. if (roles) {
  38. roles.forEach(function (role) {
  39. if (res === true) {
  40. return;
  41. }
  42. if (role.name === roleAttrValue) {
  43. res = true;
  44. }
  45. });
  46. }
  47. });
  48. }
  49. });
  50. return res;
  51. };
  52. var _default = isSemanticRoleElement;
  53. exports["default"] = _default;