From ee1e0fa768bfc388b328eec24fb8038103d8be46 Mon Sep 17 00:00:00 2001 From: tanhauhau Date: Tue, 12 Jul 2022 22:35:32 +0800 Subject: [PATCH] clean up test --- src/compiler/compile/nodes/Element.ts | 11 +++++------ .../a11y-label-has-associated-control-2/input.svelte | 12 ++++++++++++ .../warnings.json | 1 + .../a11y-label-has-associated-control/label.svelte | 3 --- 4 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 test/validator/samples/a11y-label-has-associated-control-2/input.svelte create mode 100644 test/validator/samples/a11y-label-has-associated-control-2/warnings.json delete mode 100644 test/validator/samples/a11y-label-has-associated-control/label.svelte diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts index e9a17af85737..fb19d13f8746 100644 --- a/src/compiler/compile/nodes/Element.ts +++ b/src/compiler/compile/nodes/Element.ts @@ -616,17 +616,16 @@ export default class Element extends Node { } if (this.name === 'label') { - const has_input_child = (children) => { - const has_input = children.some(i => (i instanceof Element && a11y_labelable.has(i.name))); - if (has_input) { + const has_input_child = (children: INode[]) => { + if (children.some(child => (child instanceof Element && (a11y_labelable.has(child.name) || child.name === 'slot')))) { return true; } - for (const c of children) { - if (!c.children || c.children.length === 0) { + for (const child of children) { + if (!('children' in child) || child.children.length === 0) { continue; } - if (has_input_child(c.children)) { + if (has_input_child(child.children)) { return true; } } diff --git a/test/validator/samples/a11y-label-has-associated-control-2/input.svelte b/test/validator/samples/a11y-label-has-associated-control-2/input.svelte new file mode 100644 index 000000000000..124888c089ad --- /dev/null +++ b/test/validator/samples/a11y-label-has-associated-control-2/input.svelte @@ -0,0 +1,12 @@ + + + + + + + + + +G diff --git a/test/validator/samples/a11y-label-has-associated-control-2/warnings.json b/test/validator/samples/a11y-label-has-associated-control-2/warnings.json new file mode 100644 index 000000000000..fe51488c7066 --- /dev/null +++ b/test/validator/samples/a11y-label-has-associated-control-2/warnings.json @@ -0,0 +1 @@ +[] diff --git a/test/validator/samples/a11y-label-has-associated-control/label.svelte b/test/validator/samples/a11y-label-has-associated-control/label.svelte deleted file mode 100644 index de26d50782d1..000000000000 --- a/test/validator/samples/a11y-label-has-associated-control/label.svelte +++ /dev/null @@ -1,3 +0,0 @@ -