Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attributes is not iterable error when using aria-query 5.2.1 #2916

Closed
jaswilli opened this issue Jun 17, 2023 · 0 comments · Fixed by #2917
Closed

attributes is not iterable error when using aria-query 5.2.1 #2916

jaswilli opened this issue Jun 17, 2023 · 0 comments · Fixed by #2917
Labels

Comments

@jaswilli
Copy link
Contributor

jaswilli commented Jun 17, 2023

This error is similar to #2912 but the manifestation is different, where this error comes from an input with a type that doesn't match any of aria-query's mappings. A minimal reproduction is simply:

echo '<input type="password">' | npx ember-template-lint --verbose - --
  -:-  error  attributes is not iterable  undefined
TypeError: attributes is not iterable
    at getImplicitRole (file:///Users/jtw/.npm/_npx/279f7d8bf6868ccd/node_modules/ember-template-lint/lib/rules/no-unsupported-role-attributes.js:18:31)
    at NoUnsupportedRoleAttributes.ElementNode (file:///Users/jtw/.npm/_npx/279f7d8bf6868ccd/node_modules/ember-template-lint/lib/rules/no-unsupported-role-attributes.js:52:18)
    at file:///Users/jtw/.npm/_npx/279f7d8bf6868ccd/node_modules/ember-template-lint/lib/rules/_base.js:323:46
    at visitNode (/Users/jtw/.npm/_npx/279f7d8bf6868ccd/node_modules/@glimmer/syntax/dist/commonjs/es2017/lib/traversal/traverse.js:86:14)
    at visitArray (/Users/jtw/.npm/_npx/279f7d8bf6868ccd/node_modules/@glimmer/syntax/dist/commonjs/es2017/lib/traversal/traverse.js:179:18)
    at visitKey (/Users/jtw/.npm/_npx/279f7d8bf6868ccd/node_modules/@glimmer/syntax/dist/commonjs/es2017/lib/traversal/traverse.js:155:5)
    at visitNode (/Users/jtw/.npm/_npx/279f7d8bf6868ccd/node_modules/@glimmer/syntax/dist/commonjs/es2017/lib/traversal/traverse.js:107:7)
    at traverse (/Users/jtw/.npm/_npx/279f7d8bf6868ccd/node_modules/@glimmer/syntax/dist/commonjs/es2017/lib/traversal/traverse.js:220:3)
    at transform (/Users/jtw/.npm/_npx/279f7d8bf6868ccd/node_modules/ember-template-recast/lib/index.js:68:27)
    at Linter.verify (file:///Users/jtw/.npm/_npx/279f7d8bf6868ccd/node_modules/ember-template-lint/lib/linter.js:381:11)

ember-template-lint's behavior prior to aria-query@5.2.1 was that inside getImplicitRole all of the key.attributes were iterable, they just didn't match and the return clause was never hit and we got the default behavior, which was to return a button. With how the data has changed in 5.2.1 some of the keys have no attributes defined so we get the error above.

Here's the relevant section of code:

function getImplicitRole(element, typeAttribute) {
if (element === 'input') {
for (let key of elementRoles.keys()) {
if (key.name === element) {
let attributes = key.attributes;
for (let attribute of attributes) {
if (attribute.name === 'type' && attribute.value === typeAttribute) {
return elementRoles.get(key)[0];
}
}
}
}
}
const key = elementRoles.keys().find((key) => key.name === element);
const implicitRoles = key && elementRoles.get(key);
return implicitRoles && implicitRoles[0];
}

I'm happy to work up a PR for a workaround but I'm a little confused about whether or not the current behavior where an input with a typeAttribute that doesn't match any of the aria-query element role mappings gets "defaulted" to a button is correct? Following the "it's gotten us this far" rule I suppose staying the course is fine and we can just keep returning button but if that existing behavior is a bug and what we really want is to fall back to something like an input of type text then I'm also happy to make that change.

jaswilli added a commit to jaswilli/ember-template-lint that referenced this issue Jun 17, 2023
Handle the case where aria-query's role mapping data does not have an
attributes property defined.

Resolves ember-template-lint#2916
@bmish bmish added the bug label Jun 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants