From abaa4413dfc45805aa83c96e33e203666d737afb Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Wed, 24 Jul 2024 19:35:22 +0100 Subject: [PATCH] fix: tweak element_invalid_self_closing_tag to exclude namespace (#12585) --- .changeset/quick-pumpkins-study.md | 5 +++++ .../svelte/src/compiler/phases/2-analyze/validation.js | 7 +++++-- .../samples/invalid-self-closing-tag/input.svelte | 2 ++ .../samples/invalid-self-closing-tag/warnings.json | 8 ++++---- 4 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 .changeset/quick-pumpkins-study.md diff --git a/.changeset/quick-pumpkins-study.md b/.changeset/quick-pumpkins-study.md new file mode 100644 index 0000000000..ba887164df --- /dev/null +++ b/.changeset/quick-pumpkins-study.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: tweak element_invalid_self_closing_tag to exclude namespace diff --git a/packages/svelte/src/compiler/phases/2-analyze/validation.js b/packages/svelte/src/compiler/phases/2-analyze/validation.js index 29758b6b2f..a874d97fd9 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/validation.js +++ b/packages/svelte/src/compiler/phases/2-analyze/validation.js @@ -636,11 +636,14 @@ const validation = { } } + // Strip off any namespace from the beginning of the node name. + const node_name = node.name.replace(/[a-zA-Z-]*:/g, ''); + if ( context.state.analysis.source[node.end - 2] === '/' && context.state.options.namespace !== 'foreign' && - !VoidElements.includes(node.name) && - !SVGElements.includes(node.name) + !VoidElements.includes(node_name) && + !SVGElements.includes(node_name) ) { w.element_invalid_self_closing_tag(node, node.name); } diff --git a/packages/svelte/tests/validator/samples/invalid-self-closing-tag/input.svelte b/packages/svelte/tests/validator/samples/invalid-self-closing-tag/input.svelte index 8b09b6f9a3..376c9f79bd 100644 --- a/packages/svelte/tests/validator/samples/invalid-self-closing-tag/input.svelte +++ b/packages/svelte/tests/validator/samples/invalid-self-closing-tag/input.svelte @@ -1,6 +1,8 @@ + +
diff --git a/packages/svelte/tests/validator/samples/invalid-self-closing-tag/warnings.json b/packages/svelte/tests/validator/samples/invalid-self-closing-tag/warnings.json index 09a47f17a3..40b87ec7c8 100644 --- a/packages/svelte/tests/validator/samples/invalid-self-closing-tag/warnings.json +++ b/packages/svelte/tests/validator/samples/invalid-self-closing-tag/warnings.json @@ -3,11 +3,11 @@ "code": "element_invalid_self_closing_tag", "message": "Self-closing HTML tags for non-void elements are ambiguous — use `
` rather than `
`", "start": { - "line": 6, + "line": 8, "column": 0 }, "end": { - "line": 6, + "line": 8, "column": 7 } }, @@ -15,11 +15,11 @@ "code": "element_invalid_self_closing_tag", "message": "Self-closing HTML tags for non-void elements are ambiguous — use `` rather than ``", "start": { - "line": 7, + "line": 9, "column": 0 }, "end": { - "line": 7, + "line": 9, "column": 12 } }