Skip to content

Commit a51b3df

Browse files
feat: support migration of self closing tags (#13479)
1 parent 073ef17 commit a51b3df

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

.changeset/real-camels-pay.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+
feat: support migration of self closing tags

packages/svelte/src/compiler/migrate/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { extract_identifiers } from '../utils/ast.js';
1414
import { migrate_svelte_ignore } from '../utils/extract_svelte_ignore.js';
1515
import { determine_slot } from '../utils/slot.js';
1616
import { validate_component_options } from '../validate-options.js';
17+
import { is_svg, is_void } from '../../utils.js';
1718

1819
const regex_style_tags = /(<style[^>]+>)([\S\s]*?)(<\/style>)/g;
1920
const style_placeholder = '/*$$__STYLE_CONTENT__$$*/';
@@ -580,6 +581,15 @@ const template = {
580581
},
581582
RegularElement(node, { state, next }) {
582583
handle_events(node, state);
584+
// Strip off any namespace from the beginning of the node name.
585+
const node_name = node.name.replace(/[a-zA-Z-]*:/g, '');
586+
587+
if (state.analysis.source[node.end - 2] === '/' && !is_void(node_name) && !is_svg(node_name)) {
588+
let trimmed_position = node.end - 2;
589+
while (state.str.original.charAt(trimmed_position - 1) === ' ') trimmed_position--;
590+
state.str.remove(trimmed_position, node.end - 1);
591+
state.str.appendRight(node.end, `</${node.name}>`);
592+
}
583593
next();
584594
},
585595
SvelteElement(node, { state, next }) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div />
2+
<div title="preserve" />
3+
<input type="text" />
4+
<hr />
5+
<f:table />
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div></div>
2+
<div title="preserve"></div>
3+
<input type="text" />
4+
<hr />
5+
<f:table></f:table>

0 commit comments

Comments
 (0)