0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 17:30:59 +01:00

Merge pull request #1112 from sveltejs/gh-1110

do not run a11y validation on child component elements
This commit is contained in:
Rich Harris 2018-01-18 08:14:11 -05:00 committed by GitHub
commit 24ea1afe78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 8 deletions

View File

@ -19,14 +19,29 @@ export default function validateHtml(validator: Validator, html: Node) {
const elementStack: Node[] = [];
function visit(node: Node) {
a11y(validator, node, elementStack);
if (node.type === 'Element') {
if (meta.has(node.name)) {
return meta.get(node.name)(validator, node, refs, refCallees);
}
validateElement(validator, node, refs, refCallees, stack, elementStack);
const isComponent =
node.name === ':Self' ||
node.name === ':Component' ||
validator.components.has(node.name);
validateElement(
validator,
node,
refs,
refCallees,
stack,
elementStack,
isComponent
);
if (!isComponent) {
a11y(validator, node, elementStack);
}
} else if (node.type === 'EachBlock') {
if (validator.helpers.has(node.context)) {
let c = node.expression.end;

View File

@ -11,11 +11,9 @@ export default function validateElement(
refs: Map<string, Node[]>,
refCallees: Node[],
stack: Node[],
elementStack: Node[]
elementStack: Node[],
isComponent: Boolean
) {
const isComponent =
node.name === ':Self' || node.name === ':Component' || validator.components.has(node.name);
if (isComponent) {
validator.used.components.add(node.name);
}

View File

@ -11,6 +11,6 @@ export default function validateHead(validator: Validator, node: Node, refs: Map
node.children.forEach(node => {
if (node.type !== 'Element') return; // TODO handle {{#if}} and friends?
validateElement(validator, node, refs, refCallees, [], []);
validateElement(validator, node, refs, refCallees, [], [], false);
});
}

View File

@ -0,0 +1,9 @@
<Widget scope="foo">
<input autofocus>
</Widget>
<script>
export default {
components: { Widget },
};
</script>

View File

@ -0,0 +1,10 @@
[
{
"message": "A11y: Avoid using autofocus",
"loc": {
"column": 8,
"line": 2
},
"pos": 29
}
]