File tree 1 file changed +15
-7
lines changed
1 file changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -13,14 +13,22 @@ import {
13
13
const exceptions : { [ type : string ] : string [ ] } = { nav : [ "navigation" ] } ;
14
14
15
15
function getImplicitRoleSet ( node : AST . VElement ) : any [ ] | null {
16
- for ( const [ elementRole , roleSet ] of elementRoles . entries ( ) ) {
17
- if ( matchesElementRole ( node , elementRole ) ) {
18
- // The types for this are wrong, it's actually a string[]
19
- return roleSet as unknown as any [ ] ;
20
- }
21
- }
16
+ const matchingRoles = elementRoles . entries ( )
17
+ . filter ( ( [ consept ] ) => {
18
+ return matchesElementRole ( node , consept ) ;
19
+ } )
20
+ . sort ( ( [ a ] , [ b ] ) => {
21
+ // try ordering by the concept that is more difficult to match first.
22
+ // the number of attributes needed to "match" is used here as a proxy of
23
+ // that difficulty.
24
+ return ( b . attributes ?. length ?? 0 ) - ( a . attributes ?. length ?? 0 ) ;
25
+ } ) ;
26
+
27
+ const [ preferedRole ] = matchingRoles ;
28
+ const [ , roleSet = null ] = preferedRole || [ ] ;
22
29
23
- return null ;
30
+ // The types for this are wrong, it's actually a string[]
31
+ return roleSet as unknown as string [ ] ;
24
32
}
25
33
26
34
const rule : Rule . RuleModule = {
You can’t perform that action at this time.
0 commit comments