fix: correctly print `!doctype` during `print` (#17341)

pull/17347/head
Manuel 2 months ago committed by GitHub
parent 01cd35211b
commit a584ff1347
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: correctly print `!doctype` during `print`

@ -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('>');

@ -0,0 +1,11 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Svelte App</title>
</head>
<body>
<div>Hello World</div>
</body>
</html>

@ -0,0 +1,12 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
/>
<title>Svelte App</title>
</head>
<body><div>Hello World</div></body>
</html>
Loading…
Cancel
Save