Skip to content

Commit

Permalink
(fix) strip doctype before jsx is generated (#213)
Browse files Browse the repository at this point in the history
* fix(204): strip doctype before jsx is generated

* fix(204): add tests to validate doctype if removed

Fixes #204
  • Loading branch information
skippednote committed Jun 20, 2020
1 parent 5437e5f commit 3ef9d78
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/svelte2tsx/src/htmlxtojsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ const beforeStart = (start: number) => start - 1;

type Walker = (node: Node, parent: Node, prop: string, index: number) => void;

const stripDoctype = (str: MagicString) => {
const regex = /<!doctype(.+?)>(\n)?/i;
const result = regex.exec(str.original);
if (result) str.remove(result.index, result.index + result[0].length);
};

// eslint-disable-next-line max-len
export function convertHtmlxToJsx(
str: MagicString,
Expand All @@ -28,6 +34,7 @@ export function convertHtmlxToJsx(
onLeave: Walker = null,
) {
const htmlx = str.original;
stripDoctype(str);
str.prepend('<>');
str.append('</>');
const handleRaw = (rawBlock: Node) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<><html lang="en">
<body>
<h1>Svelte</h1>
</body>
</html></>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<html lang="en">
<body>
<h1>Svelte</h1>
</body>
</html>

0 comments on commit 3ef9d78

Please sign in to comment.