Skip to content

Commit db0aa24

Browse files
authored
Merge pull request #545 from evcohen/fix--isSemanticRoleElement
Prevent Error when JSXSpreadAttribute is passed to isSemanticRoleElement
2 parents 33a7d69 + 4f79558 commit db0aa24

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

__tests__/src/rules/role-has-required-aria-props-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ ruleTester.run('role-has-required-aria-props', rule, {
5555
{ code: '<div role={role || "foobar"} />' },
5656
{ code: '<div role="row" />' },
5757
{ code: '<span role="checkbox" aria-checked="false" aria-labelledby="foo" tabindex="0"></span>' },
58+
{ code: '<input role="checkbox" aria-checked="false" aria-labelledby="foo" tabindex="0" {...props} type="checkbox" />' },
5859
{ code: '<input type="checkbox" role="switch" />' },
5960
].concat(basicValidityTests).map(parserOptionsMapper),
6061

__tests__/src/util/isSemanticRoleElement-test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,22 @@ describe('isSemanticRoleElement', () => {
2727
JSXAttributeMock('role', 'switch'),
2828
])).toBe(false);
2929
});
30+
it('should not throw on JSXSpreadAttribute', () => {
31+
expect(() => {
32+
isSemanticRoleElement('input', [
33+
JSXAttributeMock('type', 'checkbox'),
34+
JSXAttributeMock('role', 'checkbox'),
35+
JSXAttributeMock('aria-checked', 'false'),
36+
JSXAttributeMock('aria-labelledby', 'foo'),
37+
JSXAttributeMock('tabindex', '0'),
38+
{
39+
type: 'JSXSpreadAttribute',
40+
argument: {
41+
type: 'Identifier',
42+
name: 'props',
43+
},
44+
},
45+
]);
46+
}).not.toThrow();
47+
});
3048
});

src/util/isSemanticRoleElement.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ const isSemanticRoleElement = (
2222
&& (concept.attributes || []).every(
2323
cAttr => attributes.some(
2424
(attr) => {
25+
if (!attr.type || attr.type !== 'JSXAttribute') {
26+
return false;
27+
}
2528
const namesMatch = cAttr.name === propName(attr);
2629
let valuesMatch;
2730
if (cAttr.value !== undefined) {

0 commit comments

Comments
 (0)