Skip to content

Commit 332fecc

Browse files
MichaelDeBoeyljharb
authored andcommitted
refactor: remove es-iterator-helpers dependency
1 parent 474a4b9 commit 332fecc

9 files changed

+19
-49
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010

1111
import { roles } from 'aria-query';
1212
import { RuleTester } from 'eslint';
13-
import iterFrom from 'es-iterator-helpers/Iterator.from';
14-
import map from 'es-iterator-helpers/Iterator.prototype.map';
15-
import toArray from 'es-iterator-helpers/Iterator.prototype.toArray';
1613

1714
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
1815
import parsers from '../../__util__/helpers/parsers';
@@ -42,7 +39,7 @@ const componentsSettings = {
4239
};
4340

4441
// Create basic test cases using all valid role types.
45-
const basicValidityTests = toArray(map(iterFrom(roles.keys()), (role) => {
42+
const basicValidityTests = roles.keys().map((role) => {
4643
const {
4744
requiredProps: requiredPropKeyValues,
4845
} = roles.get(role);
@@ -52,7 +49,7 @@ const basicValidityTests = toArray(map(iterFrom(roles.keys()), (role) => {
5249
return {
5350
code: `<div role="${role.toLowerCase()}" ${propChain} />`,
5451
};
55-
}));
52+
});
5653

5754
ruleTester.run('role-has-required-aria-props', rule, {
5855
valid: parsers.all([].concat(

__tests__/src/rules/role-supports-aria-props-test.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ import {
1212
roles,
1313
} from 'aria-query';
1414
import { RuleTester } from 'eslint';
15-
import iterFrom from 'es-iterator-helpers/Iterator.from';
16-
import filter from 'es-iterator-helpers/Iterator.prototype.filter';
17-
import map from 'es-iterator-helpers/Iterator.prototype.map';
18-
import toArray from 'es-iterator-helpers/Iterator.prototype.toArray';
1915

2016
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
2117
import parsers from '../../__util__/helpers/parsers';
@@ -48,15 +44,14 @@ const componentsSettings = {
4844
},
4945
};
5046

51-
const nonAbstractRoles = toArray(filter(iterFrom(roles.keys()), (role) => roles.get(role).abstract === false));
47+
const nonAbstractRoles = roles.keys().filter((role) => roles.get(role).abstract === false);
5248

5349
const createTests = (rolesNames) => rolesNames.reduce((tests, role) => {
5450
const {
5551
props: propKeyValues,
5652
} = roles.get(role);
5753
const validPropsForRole = Object.keys(propKeyValues);
58-
const invalidPropsForRole = filter(
59-
map(iterFrom(aria.keys()), (attribute) => attribute.toLowerCase()),
54+
const invalidPropsForRole = aria.keys().map((attribute) => attribute.toLowerCase()).filter(
6055
(attribute) => validPropsForRole.indexOf(attribute) === -1,
6156
);
6257
const normalRole = role.toLowerCase();
@@ -65,10 +60,10 @@ const createTests = (rolesNames) => rolesNames.reduce((tests, role) => {
6560
tests[0].concat(validPropsForRole.map((prop) => ({
6661
code: `<div role="${normalRole}" ${prop.toLowerCase()} />`,
6762
}))),
68-
tests[1].concat(toArray(map(invalidPropsForRole, (prop) => ({
63+
tests[1].concat(invalidPropsForRole.map((prop) => ({
6964
code: `<div role="${normalRole}" ${prop.toLowerCase()} />`,
7065
errors: [errorMessage(prop.toLowerCase(), normalRole, 'div', false)],
71-
})))),
66+
}))),
7267
];
7368
}, [[], []]);
7469

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
"axe-core": "^4.10.0",
8282
"axobject-query": "^4.1.0",
8383
"damerau-levenshtein": "^1.0.8",
84-
"es-iterator-helpers": "^1.1.0",
8584
"hasown": "^2.0.2",
8685
"jsx-ast-utils": "^3.3.5",
8786
"language-tags": "^1.0.9",

src/rules/aria-role.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
import { dom, roles } from 'aria-query';
1111
import { getLiteralPropValue, propName } from 'jsx-ast-utils';
12-
import iterFrom from 'es-iterator-helpers/Iterator.from';
13-
import filter from 'es-iterator-helpers/Iterator.prototype.filter';
1412

1513
import getElementType from '../util/getElementType';
1614
import { generateObjSchema } from '../util/schemas';
@@ -31,7 +29,7 @@ const schema = generateObjSchema({
3129
},
3230
});
3331

34-
const validRoles = new Set(filter(iterFrom(roles.keys()), (role) => roles.get(role).abstract === false));
32+
const validRoles = new Set(roles.keys().filter((role) => roles.get(role).abstract === false));
3533

3634
export default {
3735
meta: {

src/rules/interactive-supports-focus.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ import getTabIndex from '../util/getTabIndex';
3535
// ----------------------------------------------------------------------------
3636

3737
const schema = generateObjSchema({
38-
// TODO: convert to use iterFilter and iterFrom
39-
tabbable: enumArraySchema([...roles.keys()].filter((name) => (
38+
tabbable: enumArraySchema(roles.keys().filter((name) => (
4039
!roles.get(name).abstract
4140
&& roles.get(name).superClass.some((klasses) => klasses.includes('widget'))
4241
))),

src/rules/role-supports-aria-props.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import {
1818
getPropValue,
1919
propName,
2020
} from 'jsx-ast-utils';
21-
import iterFrom from 'es-iterator-helpers/Iterator.from';
22-
import filter from 'es-iterator-helpers/Iterator.prototype.filter';
2321

2422
import { generateObjSchema } from '../util/schemas';
2523
import getElementType from '../util/getElementType';
@@ -64,11 +62,11 @@ export default {
6462
return;
6563
}
6664

67-
// Make sure it has no aria-* properties defined outside of its property set.
65+
// Make sure it has no aria-* properties defined outside its property set.
6866
const {
6967
props: propKeyValues,
7068
} = roles.get(roleValue);
71-
const invalidAriaPropsForRole = new Set(filter(iterFrom(aria.keys()), (attribute) => !(attribute in propKeyValues)));
69+
const invalidAriaPropsForRole = new Set(aria.keys().filter((attribute) => !(attribute in propKeyValues)));
7270

7371
node.attributes.filter((prop) => (
7472
getPropValue(prop) != null // Ignore the attribute if its value is null or undefined.

src/util/isAbstractRole.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ import {
33
roles,
44
} from 'aria-query';
55
import { getProp, getLiteralPropValue } from 'jsx-ast-utils';
6-
import iterFrom from 'es-iterator-helpers/Iterator.from';
7-
import filter from 'es-iterator-helpers/Iterator.prototype.filter';
86

9-
const abstractRoles = new Set(filter(iterFrom(roles.keys()), (role) => roles.get(role).abstract));
7+
const abstractRoles = new Set(roles.keys().filter((role) => roles.get(role).abstract));
108

119
const DOMElements = new Set(dom.keys());
1210

src/util/isInteractiveElement.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ import {
1212
elementAXObjects,
1313
} from 'axobject-query';
1414
import flatMap from 'array.prototype.flatmap';
15-
import iterFrom from 'es-iterator-helpers/Iterator.from';
16-
// import iterFlatMap from 'es-iterator-helpers/Iterator.prototype.flatMap';
17-
import filter from 'es-iterator-helpers/Iterator.prototype.filter';
18-
import some from 'es-iterator-helpers/Iterator.prototype.some';
1915

2016
import attributesComparator from './attributesComparator';
2117

@@ -54,21 +50,18 @@ const interactiveRoles = new Set(roleKeys
5450
'toolbar',
5551
));
5652

57-
// TODO: convert to use iterFlatMap and iterFrom
5853
const interactiveElementRoleSchemas = flatMap(
5954
elementRoleEntries,
6055
([elementSchema, rolesArr]) => (rolesArr.some((role): boolean => interactiveRoles.has(role)) ? [elementSchema] : []),
6156
);
6257

63-
// TODO: convert to use iterFlatMap and iterFrom
6458
const nonInteractiveElementRoleSchemas = flatMap(
6559
elementRoleEntries,
6660
([elementSchema, rolesArr]) => (rolesArr.every((role): boolean => nonInteractiveRoles.has(role)) ? [elementSchema] : []),
6761
);
6862

69-
const interactiveAXObjects = new Set(filter(iterFrom(AXObjects.keys()), (name) => AXObjects.get(name).type === 'widget'));
63+
const interactiveAXObjects = new Set(AXObjects.keys().filter((name) => AXObjects.get(name).type === 'widget'));
7064

71-
// TODO: convert to use iterFlatMap and iterFrom
7265
const interactiveElementAXObjectSchemas = flatMap(
7366
[...elementAXObjects],
7467
([elementSchema, AXObjectsArr]) => (AXObjectsArr.every((role): boolean => interactiveAXObjects.has(role)) ? [elementSchema] : []),
@@ -84,18 +77,18 @@ function checkIsInteractiveElement(tagName, attributes): boolean {
8477

8578
// Check in elementRoles for inherent interactive role associations for
8679
// this element.
87-
const isInherentInteractiveElement = some(iterFrom(interactiveElementRoleSchemas), elementSchemaMatcher);
80+
const isInherentInteractiveElement = interactiveElementRoleSchemas.some(elementSchemaMatcher);
8881
if (isInherentInteractiveElement) {
8982
return true;
9083
}
9184
// Check in elementRoles for inherent non-interactive role associations for
9285
// this element.
93-
const isInherentNonInteractiveElement = some(iterFrom(nonInteractiveElementRoleSchemas), elementSchemaMatcher);
86+
const isInherentNonInteractiveElement = nonInteractiveElementRoleSchemas.some(elementSchemaMatcher);
9487
if (isInherentNonInteractiveElement) {
9588
return false;
9689
}
9790
// Check in elementAXObjects for AX Tree associations for this element.
98-
const isInteractiveAXElement = some(iterFrom(interactiveElementAXObjectSchemas), elementSchemaMatcher);
91+
const isInteractiveAXElement = interactiveElementAXObjectSchemas.some(elementSchemaMatcher);
9992
if (isInteractiveAXElement) {
10093
return true;
10194
}

src/util/isNonInteractiveElement.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ import {
1313
} from 'axobject-query';
1414
import type { Node } from 'ast-types-flow';
1515
import flatMap from 'array.prototype.flatmap';
16-
import iterFrom from 'es-iterator-helpers/Iterator.from';
17-
// import iterFlatMap from 'es-iterator-helpers/Iterator.prototype.flatMap';
18-
import filter from 'es-iterator-helpers/Iterator.prototype.filter';
19-
import some from 'es-iterator-helpers/Iterator.prototype.some';
2016

2117
import attributesComparator from './attributesComparator';
2218

@@ -61,21 +57,18 @@ const interactiveRoles = new Set(roleKeys
6157
'toolbar',
6258
));
6359

64-
// TODO: convert to use iterFlatMap and iterFrom
6560
const interactiveElementRoleSchemas = flatMap(
6661
elementRoleEntries,
6762
([elementSchema, rolesArr]) => (rolesArr.some((role): boolean => interactiveRoles.has(role)) ? [elementSchema] : []),
6863
);
6964

70-
// TODO: convert to use iterFlatMap and iterFrom
7165
const nonInteractiveElementRoleSchemas = flatMap(
7266
elementRoleEntries,
7367
([elementSchema, rolesArr]) => (rolesArr.every((role): boolean => nonInteractiveRoles.has(role)) ? [elementSchema] : []),
7468
);
7569

76-
const nonInteractiveAXObjects = new Set(filter(iterFrom(AXObjects.keys()), (name) => ['window', 'structure'].includes(AXObjects.get(name).type)));
70+
const nonInteractiveAXObjects = new Set(AXObjects.keys().filter((name) => ['window', 'structure'].includes(AXObjects.get(name).type)));
7771

78-
// TODO: convert to use iterFlatMap and iterFrom
7972
const nonInteractiveElementAXObjectSchemas = flatMap(
8073
[...elementAXObjects],
8174
([elementSchema, AXObjectsArr]) => (AXObjectsArr.every((role): boolean => nonInteractiveAXObjects.has(role)) ? [elementSchema] : []),
@@ -91,18 +84,18 @@ function checkIsNonInteractiveElement(tagName, attributes): boolean {
9184
}
9285
// Check in elementRoles for inherent non-interactive role associations for
9386
// this element.
94-
const isInherentNonInteractiveElement = some(iterFrom(nonInteractiveElementRoleSchemas), elementSchemaMatcher);
87+
const isInherentNonInteractiveElement = nonInteractiveElementRoleSchemas.some(elementSchemaMatcher);
9588
if (isInherentNonInteractiveElement) {
9689
return true;
9790
}
9891
// Check in elementRoles for inherent interactive role associations for
9992
// this element.
100-
const isInherentInteractiveElement = some(iterFrom(interactiveElementRoleSchemas), elementSchemaMatcher);
93+
const isInherentInteractiveElement = interactiveElementRoleSchemas.some(elementSchemaMatcher);
10194
if (isInherentInteractiveElement) {
10295
return false;
10396
}
10497
// Check in elementAXObjects for AX Tree associations for this element.
105-
const isNonInteractiveAXElement = some(iterFrom(nonInteractiveElementAXObjectSchemas), elementSchemaMatcher);
98+
const isNonInteractiveAXElement = nonInteractiveElementAXObjectSchemas.some(elementSchemaMatcher);
10699
if (isNonInteractiveAXElement) {
107100
return true;
108101
}

0 commit comments

Comments
 (0)