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:
commit
24ea1afe78
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
9
test/validator/samples/a11y-not-on-components/input.html
Normal file
9
test/validator/samples/a11y-not-on-components/input.html
Normal file
@ -0,0 +1,9 @@
|
||||
<Widget scope="foo">
|
||||
<input autofocus>
|
||||
</Widget>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
components: { Widget },
|
||||
};
|
||||
</script>
|
10
test/validator/samples/a11y-not-on-components/warnings.json
Normal file
10
test/validator/samples/a11y-not-on-components/warnings.json
Normal file
@ -0,0 +1,10 @@
|
||||
[
|
||||
{
|
||||
"message": "A11y: Avoid using autofocus",
|
||||
"loc": {
|
||||
"column": 8,
|
||||
"line": 2
|
||||
},
|
||||
"pos": 29
|
||||
}
|
||||
]
|
Loading…
Reference in New Issue
Block a user