Language-tools: <!doctype html> shows errors

Created on 18 Jun 2020  ·  3Comments  ·  Source: sveltejs/language-tools

Describe the bug

<!doctype html> shows errors. Looks related to https://github.com/sveltejs/language-tools/issues/143.

To Reproduce

CleanShot 2020-06-18 at 09 50 11@2x
CleanShot 2020-06-18 at 09 54 13@2x

<!doctype html />
<html lang="en">
  <slot name="head" />
  <body>
    <slot name="view" />
    <slot name="script" />
  </body>
</html>

Removing the doctype fixes the problem. I also tried <!doctype html>, but auto-formatting inserts <!doctype html /> anyway.

Expected behavior

No errors. Seems like it's fixed in svelte: https://github.com/sveltejs/svelte/issues/336

I wasn't able to reproduce it in the Svelte REPL (I got a different error), but I think this should work with SSR.

System (please complete the following information):

  • OS: OSX
  • IDE: VSCode
  • Plugin/Package: Svelte Beta v99.0.46
bug good first issue

Most helpful comment

@dummdidumm Based on your suggestion, I've created a pull request #213.

All 3 comments

It's a svelte2tsx problem. Output of given input is:

<></>;function render() {
<><!doctype html />
<html lang="en">
  <slot name="head" />
  <body>
    <slot name="view" />
    <slot name="script" />
  </body>
</html></>
return { props: {}, slots: {head: {}, view: {}, script: {}} }}

export default class {
    $$prop_def = __sveltets_partial(render().props)
    $$slot_def = render().slots
}

<!doctype html /> is not a valid jsx tag, so it throws these syntax errors. I think the best solution would be to check inside svelte2tsx if such a string exists at the start of the document and just remove it during conversion to jsx, using a regex that checks "is there a tag that begins with

@dummdidumm Based on your suggestion, I've created a pull request #213.

Thanks @skippednote ! Fix will be available in about 20 hours.

Was this page helpful?
0 / 5 - 0 ratings