diff --git a/src/compile/nodes/Element.ts b/src/compile/nodes/Element.ts index b38ee5b6fb..ac2b81b3e7 100644 --- a/src/compile/nodes/Element.ts +++ b/src/compile/nodes/Element.ts @@ -224,7 +224,21 @@ export default class Element extends Node { } if (this.name === 'figcaption') { - if (this.parent.name !== 'figure') { + let { parent } = this; + let is_figure_parent = false; + + while (parent) { + if (parent.name === 'figure') { + is_figure_parent = true; + break; + } + if (parent.type === 'Element') { + break; + } + parent = parent.parent; + } + + if (!is_figure_parent) { this.component.warn(this, { code: `a11y-structure`, message: `A11y:
must be an immediate child of
` diff --git a/test/validator/samples/a11y-figcaption-in-non-element-block/input.svelte b/test/validator/samples/a11y-figcaption-in-non-element-block/input.svelte new file mode 100644 index 0000000000..9d4b6ded4d --- /dev/null +++ b/test/validator/samples/a11y-figcaption-in-non-element-block/input.svelte @@ -0,0 +1,10 @@ + + +
+ a picture of a foo + {#if caption} +
{caption}
+ {/if} +
diff --git a/test/validator/samples/a11y-figcaption-in-non-element-block/warnings.json b/test/validator/samples/a11y-figcaption-in-non-element-block/warnings.json new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/test/validator/samples/a11y-figcaption-in-non-element-block/warnings.json @@ -0,0 +1 @@ +[]