Skip to content

Commit 945f61e

Browse files
committed
fix: tweak element_invalid_self_closing_tag to exclude namespace
1 parent c0832fd commit 945f61e

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

.changeset/quick-pumpkins-study.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: tweak element_invalid_self_closing_tag to exclude namespace

packages/svelte/src/compiler/phases/2-analyze/validation.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,11 +636,14 @@ const validation = {
636636
}
637637
}
638638

639+
// Strip off any namespace from the beginning of the node name.
640+
const node_name = node.name.replace(/[a-zA-Z-]*:/g, '');
641+
639642
if (
640643
context.state.analysis.source[node.end - 2] === '/' &&
641644
context.state.options.namespace !== 'foreign' &&
642-
!VoidElements.includes(node.name) &&
643-
!SVGElements.includes(node.name)
645+
!VoidElements.includes(node_name) &&
646+
!SVGElements.includes(node_name)
644647
) {
645648
w.element_invalid_self_closing_tag(node, node.name);
646649
}

packages/svelte/tests/validator/samples/invalid-self-closing-tag/input.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<!-- valid -->
22
<link />
33
<svg><g /></svg>
4+
<enhanced:img />
5+
46

57
<!-- invalid -->
68
<div />

packages/svelte/tests/validator/samples/invalid-self-closing-tag/warnings.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
"code": "element_invalid_self_closing_tag",
44
"message": "Self-closing HTML tags for non-void elements are ambiguous — use `<div ...></div>` rather than `<div ... />`",
55
"start": {
6-
"line": 6,
6+
"line": 8,
77
"column": 0
88
},
99
"end": {
10-
"line": 6,
10+
"line": 8,
1111
"column": 7
1212
}
1313
},
1414
{
1515
"code": "element_invalid_self_closing_tag",
1616
"message": "Self-closing HTML tags for non-void elements are ambiguous — use `<my-thing ...></my-thing>` rather than `<my-thing ... />`",
1717
"start": {
18-
"line": 7,
18+
"line": 9,
1919
"column": 0
2020
},
2121
"end": {
22-
"line": 7,
22+
"line": 9,
2323
"column": 12
2424
}
2525
}

0 commit comments

Comments
 (0)