@@ -23,7 +23,27 @@ for (let i = 0; i < keys.length; i++) {
23
23
if ( relation . module === 'HTML' ) {
24
24
const concept = relation . concept ;
25
25
if ( concept ) {
26
- elementRoles . push ( [ concept , [ key ] ] ) ;
26
+ const elementRoleRelation : ?ElementARIARoleRelationTuple = elementRoles . find ( relation => ariaRoleRelationConceptEquals ( relation [ 0 ] , concept ) ) ;
27
+ let roles : RoleSet ;
28
+
29
+ if ( elementRoleRelation ) {
30
+ roles = elementRoleRelation [ 1 ] ;
31
+ } else {
32
+ roles = [ ] ;
33
+ }
34
+ let isUnique = true ;
35
+ for ( let i = 0 ; i < roles . length ; i ++ ) {
36
+ if ( roles [ i ] === key ) {
37
+ isUnique = false ;
38
+ break ;
39
+ }
40
+ }
41
+ if ( isUnique ) {
42
+ roles . push ( key ) ;
43
+ }
44
+ if ( ! elementRoleRelation ) {
45
+ elementRoles . push ( [ concept , roles ] ) ;
46
+ }
27
47
}
28
48
}
29
49
}
@@ -63,6 +83,38 @@ const elementRoleMap: TAriaQueryMap<
63
83
} ,
64
84
} ;
65
85
86
+ function ariaRoleRelationConceptEquals ( a : ARIARoleRelationConcept , b : ARIARoleRelationConcept ) : boolean {
87
+ return (
88
+ a . name === b . name &&
89
+ ariaRoleRelationConstraintsEquals ( a . constraints , b . constraints ) &&
90
+ ariaRoleRelationConceptAttributeEquals ( a . attributes , b . attributes )
91
+ )
92
+ }
93
+
94
+ function ariaRoleRelationConstraintsEquals ( a ?: ARIARoleRelationConcept [ 'constraints' ] , b ?: ARIARoleRelationConcept [ 'constraints' ] ) : boolean {
95
+ if ( a === undefined && b !== undefined ) {
96
+ return false ;
97
+ }
98
+
99
+ if ( a !== undefined && b === undefined ) {
100
+ return false ;
101
+ }
102
+
103
+ if ( a !== undefined && b !== undefined ) {
104
+ if ( a . length !== b . length ) {
105
+ return false ;
106
+ }
107
+
108
+ for ( let i = 0 ; i < a . length ; i ++ ) {
109
+ if ( a [ i ] !== b [ i ] ) {
110
+ return false ;
111
+ }
112
+ }
113
+ }
114
+
115
+ return true ;
116
+ }
117
+
66
118
function ariaRoleRelationConceptAttributeEquals (
67
119
a ?: Array < ARIARoleRelationConceptAttribute > ,
68
120
b ?: Array < ARIARoleRelationConceptAttribute > ,
0 commit comments