Skip to content

Commit

Permalink
use aria-query and move warnings to compiler_warnings file
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau committed Jul 11, 2022
1 parent dee764b commit 6fd4aae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/compiler/compile/compiler_warnings.ts
Expand Up @@ -107,6 +107,10 @@ export default {
code: 'a11y-unknown-role',
message: `A11y: Unknown role '${role}'` + (suggestion ? ` (did you mean '${suggestion}'?)` : '')
}),
a11y_no_abstract_role: (role: string | boolean) => ({
code: 'a11y-no-abstract-role',
message: `A11y: abstract role '${role}' is forbidden`
}),
a11y_no_redundant_roles: (role: string | boolean) => ({
code: 'a11y-no-redundant-roles',
message: `A11y: Redundant role '${role}'`
Expand Down
12 changes: 3 additions & 9 deletions src/compiler/compile/nodes/Element.ts
Expand Up @@ -32,9 +32,7 @@ const aria_attribute_set = new Set(aria_attributes);

const aria_roles = 'alert alertdialog application article banner blockquote button caption cell checkbox code columnheader combobox complementary contentinfo definition deletion dialog directory document emphasis feed figure form generic graphics-document graphics-object graphics-symbol grid gridcell group heading img link list listbox listitem log main marquee math meter menu menubar menuitem menuitemcheckbox menuitemradio navigation none note option paragraph presentation progressbar radio radiogroup region row rowgroup rowheader scrollbar search searchbox separator slider spinbutton status strong subscript superscript switch tab table tablist tabpanel term textbox time timer toolbar tooltip tree treegrid treeitem'.split(' ');
const aria_role_set = new Set(aria_roles);

const aria_roles_abstract = 'command composite input landmark range roletype section sectionhead select structure widget window'.split(' ');
const aria_roles_abstract_set = new Set(aria_roles_abstract);
const aria_role_abstract_set = new Set(roles.keys().filter(role => roles.get(role).abstract));

const a11y_required_attributes = {
a: ['href'],
Expand Down Expand Up @@ -483,12 +481,8 @@ export default class Element extends Node {

const value = attribute.get_static_value();

if (value && aria_roles_abstract_set.has(value as string)) {
const message = `A11y: abstract role '${value}' is forbidden`;
component.warn(attribute, {
code: 'a11y-no-abstract-role',
message
});
if (value && aria_role_abstract_set.has(value as ARIARoleDefintionKey)) {
component.warn(attribute, compiler_warnings.a11y_no_abstract_role(value));
} else if (value && !aria_role_set.has(value as string)) {
// @ts-ignore
const match = fuzzymatch(value, aria_roles);
Expand Down

0 comments on commit 6fd4aae

Please sign in to comment.