Skip to content

Commit a584ff1

Browse files
authored
fix: correctly print !doctype during print (#17341)
1 parent 01cd352 commit a584ff1

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

.changeset/smooth-comics-shine.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: correctly print `!doctype` during `print`

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,13 @@ function base_element(node, context) {
112112
}
113113

114114
const multiline_attributes = attributes(node.attributes, child_context);
115-
115+
const is_doctype_node = node.name.toLowerCase() === '!doctype';
116116
const is_self_closing =
117117
is_void(node.name) || (node.type === 'Component' && node.fragment.nodes.length === 0);
118118
let multiline_content = false;
119119

120-
if (is_self_closing) {
120+
if (is_doctype_node) child_context.write(`>`);
121+
else if (is_self_closing) {
121122
child_context.write(`${multiline_attributes ? '' : ' '}/>`);
122123
} else {
123124
child_context.write('>');
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Svelte App</title>
7+
</head>
8+
<body>
9+
<div>Hello World</div>
10+
</body>
11+
</html>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta
6+
name="viewport"
7+
content="width=device-width, initial-scale=1.0"
8+
/>
9+
<title>Svelte App</title>
10+
</head>
11+
<body><div>Hello World</div></body>
12+
</html>

0 commit comments

Comments
 (0)