File tree Expand file tree Collapse file tree 1 file changed +15
-7
lines changed Expand file tree Collapse file tree 1 file changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -13,14 +13,22 @@ import {
1313const exceptions : { [ type : string ] : string [ ] } = { nav : [ "navigation" ] } ;
1414
1515function 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 || [ ] ;
2229
23- return null ;
30+ // The types for this are wrong, it's actually a string[]
31+ return roleSet as unknown as string [ ] ;
2432}
2533
2634const rule : Rule . RuleModule = {
You can’t perform that action at this time.
0 commit comments