Skip to content

Commit 1be9120

Browse files
committed
tweak
1 parent 84f15d0 commit 1be9120

File tree

1 file changed

+18
-22
lines changed
  • packages/svelte/src/compiler/phases/3-transform/client/transform-template

1 file changed

+18
-22
lines changed

packages/svelte/src/compiler/phases/3-transform/client/transform-template/to-string.js

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,29 @@ export function template_to_string(items) {
1414
* @param {Node} node
1515
*/
1616
function stringify(node) {
17-
switch (node.type) {
18-
case 'element': {
19-
let str = `<${node.name}`;
20-
21-
for (const key in node.attributes) {
22-
const value = node.attributes[key];
17+
if (node.type === 'text') {
18+
return node.nodes.map((node) => node.raw).join('');
19+
}
2320

24-
str += ` ${key}`;
25-
if (value !== undefined) str += `="${escape_html(value, true)}"`;
26-
}
21+
if (node.type === 'anchor') {
22+
return node.data ? `<!--${node.data}-->` : '<!>';
23+
}
2724

28-
str += `>`;
29-
str += node.children.map(stringify).join('');
25+
let str = `<${node.name}`;
3026

31-
if (!is_void(node.name)) {
32-
str += `</${node.name}>`;
33-
}
27+
for (const key in node.attributes) {
28+
const value = node.attributes[key];
3429

35-
return str;
36-
}
30+
str += ` ${key}`;
31+
if (value !== undefined) str += `="${escape_html(value, true)}"`;
32+
}
3733

38-
case 'text': {
39-
return node.nodes.map((node) => node.raw).join('');
40-
}
34+
str += `>`;
35+
str += node.children.map(stringify).join('');
4136

42-
case 'anchor': {
43-
return node.data ? `<!--${node.data}-->` : '<!>';
44-
}
37+
if (!is_void(node.name)) {
38+
str += `</${node.name}>`;
4539
}
40+
41+
return str;
4642
}

0 commit comments

Comments
 (0)