Skip to content

Commit 5c51e9a

Browse files
authored
(fix) handle doctype (#307)
Fixes #298
1 parent 64f67ac commit 5c51e9a

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/print/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,14 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D
190190
node.name === 'template' && !isNodeSupportedLanguage(node)
191191
);
192192
const isEmpty = node.children.every((child) => isEmptyTextNode(child));
193+
const isDoctypeTag = node.name.toUpperCase() === '!DOCTYPE';
193194

194195
const isSelfClosingTag =
195196
isEmpty &&
196197
(!options.svelteStrictMode ||
197198
node.type !== 'Element' ||
198-
selfClosingTags.indexOf(node.name) !== -1);
199+
selfClosingTags.indexOf(node.name) !== -1 ||
200+
isDoctypeTag);
199201

200202
// Order important: print attributes first
201203
const attributes = path.map((childPath) => childPath.call(print), 'attributes');
@@ -232,11 +234,11 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D
232234
groupConcat([
233235
possibleThisBinding,
234236
...attributes,
235-
bracketSameLine ? '' : dedent(line),
237+
bracketSameLine || isDoctypeTag ? '' : dedent(line),
236238
]),
237239
),
238240

239-
...[bracketSameLine ? ' ' : '', `/>`],
241+
...[bracketSameLine && !isDoctypeTag ? ' ' : '', `${isDoctypeTag ? '' : '/'}>`],
240242
]);
241243
}
242244

test/printer/samples/doctype.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!DOCTYPE html>

0 commit comments

Comments
 (0)