diff --git a/.changeset/smooth-comics-shine.md b/.changeset/smooth-comics-shine.md new file mode 100644 index 000000000000..4bf26ed9f1b7 --- /dev/null +++ b/.changeset/smooth-comics-shine.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: correctly print `!doctype` during `print` diff --git a/packages/svelte/src/compiler/print/index.js b/packages/svelte/src/compiler/print/index.js index 8b39bdd739cc..4aed743dbad3 100644 --- a/packages/svelte/src/compiler/print/index.js +++ b/packages/svelte/src/compiler/print/index.js @@ -112,12 +112,13 @@ function base_element(node, context) { } const multiline_attributes = attributes(node.attributes, child_context); - + const is_doctype_node = node.name.toLowerCase() === '!doctype'; const is_self_closing = is_void(node.name) || (node.type === 'Component' && node.fragment.nodes.length === 0); let multiline_content = false; - if (is_self_closing) { + if (is_doctype_node) child_context.write(`>`); + else if (is_self_closing) { child_context.write(`${multiline_attributes ? '' : ' '}/>`); } else { child_context.write('>'); diff --git a/packages/svelte/tests/print/samples/html-document/input.svelte b/packages/svelte/tests/print/samples/html-document/input.svelte new file mode 100644 index 000000000000..8f1b4accabb9 --- /dev/null +++ b/packages/svelte/tests/print/samples/html-document/input.svelte @@ -0,0 +1,11 @@ + + + + + + Svelte App + + +
Hello World
+ + diff --git a/packages/svelte/tests/print/samples/html-document/output.svelte b/packages/svelte/tests/print/samples/html-document/output.svelte new file mode 100644 index 000000000000..765f9ca84b62 --- /dev/null +++ b/packages/svelte/tests/print/samples/html-document/output.svelte @@ -0,0 +1,12 @@ + + + + + + Svelte App + +
Hello World
+