Skip to content

Commit aa075bd

Browse files
MichaelDeBoeyljharb
authored andcommitted
[Refactor] remove no-longer-needed es-iterator-helpers
aria-query v5 returns arrays now, not iterators
1 parent e5dda96 commit aa075bd

9 files changed

+22
-52
lines changed

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

+2-5
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

+7-12
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ import {
1414
import { RuleTester } from 'eslint';
1515
import { version as eslintVersion } from 'eslint/package.json';
1616
import semver from 'semver';
17-
import iterFrom from 'es-iterator-helpers/Iterator.from';
18-
import filter from 'es-iterator-helpers/Iterator.prototype.filter';
19-
import map from 'es-iterator-helpers/Iterator.prototype.map';
20-
import toArray from 'es-iterator-helpers/Iterator.prototype.toArray';
2117

2218
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
2319
import parsers from '../../__util__/helpers/parsers';
@@ -50,27 +46,26 @@ const componentsSettings = {
5046
},
5147
};
5248

53-
const nonAbstractRoles = toArray(filter(iterFrom(roles.keys()), (role) => roles.get(role).abstract === false));
49+
const nonAbstractRoles = roles.keys().filter((role) => roles.get(role).abstract === false);
5450

5551
const createTests = (rolesNames) => rolesNames.reduce((tests, role) => {
5652
const {
5753
props: propKeyValues,
5854
} = roles.get(role);
5955
const validPropsForRole = Object.keys(propKeyValues);
60-
const invalidPropsForRole = filter(
61-
map(iterFrom(aria.keys()), (attribute) => attribute.toLowerCase()),
62-
(attribute) => validPropsForRole.indexOf(attribute) === -1,
63-
);
56+
const invalidPropsForRole = aria.keys()
57+
.map((attribute) => attribute.toLowerCase())
58+
.filter((attribute) => validPropsForRole.indexOf(attribute) === -1);
6459
const normalRole = role.toLowerCase();
6560

6661
return [
6762
tests[0].concat(validPropsForRole.map((prop) => ({
6863
code: `<div role="${normalRole}" ${prop.toLowerCase()} />`,
6964
}))),
70-
tests[1].concat(toArray(map(invalidPropsForRole, (prop) => ({
65+
tests[1].concat(invalidPropsForRole.map((prop) => ({
7166
code: `<div role="${normalRole}" ${prop.toLowerCase()} />`,
7267
errors: [errorMessage(prop.toLowerCase(), normalRole, 'div', false)],
73-
})))),
68+
}))),
7469
];
7570
}, [[], []]);
7671

@@ -413,7 +408,7 @@ ruleTester.run('role-supports-aria-props', rule, {
413408
}
414409
/>
415410
);
416-
411+
417412
const Hello = (props) => <div>{props.frag}</div>;
418413
`,
419414
} : [],

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
"axobject-query": "^4.1.0",
8484
"damerau-levenshtein": "^1.0.8",
8585
"emoji-regex": "^9.2.2",
86-
"es-iterator-helpers": "^1.1.0",
8786
"hasown": "^2.0.2",
8887
"jsx-ast-utils": "^3.3.5",
8988
"language-tags": "^1.0.9",

src/rules/aria-role.js

+1-3
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

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ import getTabIndex from '../util/getTabIndex';
3636
// ----------------------------------------------------------------------------
3737

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

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

+2-4
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

+1-3
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

+4-11
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ import {
1313
} from 'axobject-query';
1414
import includes from 'array-includes';
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

@@ -55,21 +51,18 @@ const interactiveRoles = new Set(roleKeys
5551
'toolbar',
5652
));
5753

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

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

70-
const interactiveAXObjects = new Set(filter(iterFrom(AXObjects.keys()), (name) => AXObjects.get(name).type === 'widget'));
64+
const interactiveAXObjects = new Set(AXObjects.keys().filter((name) => AXObjects.get(name).type === 'widget'));
7165

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

8679
// Check in elementRoles for inherent interactive role associations for
8780
// this element.
88-
const isInherentInteractiveElement = some(iterFrom(interactiveElementRoleSchemas), elementSchemaMatcher);
81+
const isInherentInteractiveElement = interactiveElementRoleSchemas.some(elementSchemaMatcher);
8982
if (isInherentInteractiveElement) {
9083
return true;
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 false;
9790
}
9891
// Check in elementAXObjects for AX Tree associations for this element.
99-
const isInteractiveAXElement = some(iterFrom(interactiveElementAXObjectSchemas), elementSchemaMatcher);
92+
const isInteractiveAXElement = interactiveElementAXObjectSchemas.some(elementSchemaMatcher);
10093
if (isInteractiveAXElement) {
10194
return true;
10295
}

src/util/isNonInteractiveElement.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ import {
1414
import type { Node } from 'ast-types-flow';
1515
import includes from 'array-includes';
1616
import flatMap from 'array.prototype.flatmap';
17-
import iterFrom from 'es-iterator-helpers/Iterator.from';
18-
// import iterFlatMap from 'es-iterator-helpers/Iterator.prototype.flatMap';
19-
import filter from 'es-iterator-helpers/Iterator.prototype.filter';
20-
import some from 'es-iterator-helpers/Iterator.prototype.some';
2117

2218
import attributesComparator from './attributesComparator';
2319

@@ -62,21 +58,18 @@ const interactiveRoles = new Set(roleKeys
6258
'toolbar',
6359
));
6460

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

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

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

79-
// TODO: convert to use iterFlatMap and iterFrom
8073
const nonInteractiveElementAXObjectSchemas = flatMap(
8174
[...elementAXObjects],
8275
([elementSchema, AXObjectsArr]) => (AXObjectsArr.every((role): boolean => nonInteractiveAXObjects.has(role)) ? [elementSchema] : []),
@@ -92,18 +85,18 @@ function checkIsNonInteractiveElement(tagName, attributes): boolean {
9285
}
9386
// Check in elementRoles for inherent non-interactive role associations for
9487
// this element.
95-
const isInherentNonInteractiveElement = some(iterFrom(nonInteractiveElementRoleSchemas), elementSchemaMatcher);
88+
const isInherentNonInteractiveElement = nonInteractiveElementRoleSchemas.some(elementSchemaMatcher);
9689
if (isInherentNonInteractiveElement) {
9790
return true;
9891
}
9992
// Check in elementRoles for inherent interactive role associations for
10093
// this element.
101-
const isInherentInteractiveElement = some(iterFrom(interactiveElementRoleSchemas), elementSchemaMatcher);
94+
const isInherentInteractiveElement = interactiveElementRoleSchemas.some(elementSchemaMatcher);
10295
if (isInherentInteractiveElement) {
10396
return false;
10497
}
10598
// Check in elementAXObjects for AX Tree associations for this element.
106-
const isNonInteractiveAXElement = some(iterFrom(nonInteractiveElementAXObjectSchemas), elementSchemaMatcher);
99+
const isNonInteractiveAXElement = nonInteractiveElementAXObjectSchemas.some(elementSchemaMatcher);
107100
if (isNonInteractiveAXElement) {
108101
return true;
109102
}

0 commit comments

Comments
 (0)