Skip to content

Commit

Permalink
Fix defect in calling code when building the ElementRoleMap
Browse files Browse the repository at this point in the history
As discovered in #554

Address the defect introduced f7f6120#r143856081

This change depends on #558 which when applied (as in this PR makes the teset cases pass)
  • Loading branch information
samccone committed Jul 7, 2024
1 parent f5b8f4c commit d5024d2
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion src/elementRoleMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,27 @@ for (let i = 0; i < keys.length; i++) {
if (relation.module === 'HTML') {
const concept = relation.concept;
if (concept) {
elementRoles.push([concept, [key]]);
const elementRoleRelation: ?ElementARIARoleRelationTuple = elementRoles.find(relation => ariaRoleRelationConceptEquals(relation[0], concept));
let roles: RoleSet;

if (elementRoleRelation) {
roles = elementRoleRelation[1];
} else {
roles = [];
}
let isUnique = true;
for (let i = 0; i < roles.length; i++) {
if (roles[i] === key) {
isUnique = false;
break;
}
}
if (isUnique) {
roles.push(key);
}
if (!elementRoleRelation) {
elementRoles.push([concept, roles]);
}
}
}
}
Expand Down Expand Up @@ -63,6 +83,38 @@ const elementRoleMap: TAriaQueryMap<
},
};

function ariaRoleRelationConceptEquals(a: ARIARoleRelationConcept, b: ARIARoleRelationConcept): boolean {
return (
a.name === b.name &&
ariaRoleRelationConstraintsEquals(a.constraints, b.constraints) &&
ariaRoleRelationConceptAttributeEquals(a.attributes, b.attributes)
)
}

function ariaRoleRelationConstraintsEquals(a?: ARIARoleRelationConcept['constraints'], b?: ARIARoleRelationConcept['constraints']): boolean {
if (a === undefined && b !== undefined) {
return false;
}

if (a !== undefined && b === undefined) {
return false;
}

if (a !== undefined && b !== undefined) {
if (a.length != b.length) {
return false;
}

for (let i = 0; i < a.length; i++) {
if (a[i] !== b[i]) {
return false;
}
}
}

return true;
}

function ariaRoleRelationConceptAttributeEquals(
a?: Array<ARIARoleRelationConceptAttribute>,
b?: Array<ARIARoleRelationConceptAttribute>,
Expand Down

0 comments on commit d5024d2

Please sign in to comment.