-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathmatchesElementRole.ts
43 lines (35 loc) · 1.09 KB
/
matchesElementRole.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import type { AST } from "vue-eslint-parser";
import type { ARIARoleRelationConcept } from "aria-query";
import getElementType from "./getElementType";
import getElementAttributeValue from "./getElementAttributeValue";
function matchesElementRole(
node: AST.VElement,
elementRole: ARIARoleRelationConcept
) {
const { name, attributes } = elementRole;
if (name !== getElementType(node)) {
return false;
}
return (attributes || []).every((attribute) => {
const value = getElementAttributeValue(node, attribute.name);
if (attribute.value) {
return value === attribute.value;
}
if (attribute.constraints) {
// TODO: We shouldn't have to cast this to any. Are we using the wrong
// comparison function here? Is this maybe for an old version of
// aria-query?
const constraint = attribute.constraints[0] as any;
switch (constraint) {
case "set":
return value;
case "undefined":
return !value;
default:
return null;
}
}
return value;
});
}
export default matchesElementRole;