phoenix-ru / fervid

All-in-One Vue compiler written in Rust
https://phoenix-ru.github.io/fervid/
Apache License 2.0
371 stars 9 forks source link

Self-closing `/>` is invalid syntax on non-void HTML elements #6

Closed phoenix-ru closed 8 months ago

phoenix-ru commented 11 months ago

Problem

The official Vue parser allows self-closing any HTML, but this is not valid by the spec. For example, this:

<template>
  <slot />
  <div class="bad" />
</template>

Using Nu HTML Checker by W3 results in a clear error: image

The same happens when parsing with swc_html_parser. The error is being reported and the tag is not being closed:

InvalidHtml(NonVoidHtmlElementStartTagWithTrailingSolidus) <slot />

In addition, this also messes up the DOM Tree stack, which is the actual problem here.

Possible solution

All NonVoidHtmlElementStartTagWithTrailingSolidus should be considered a hard error.

Nice-to-have

It would also be nice to do RegEx search-replace as a utility in fervid. Another option is to parse the HTML and only apply this fix to where the NonVoidHtmlElementStartTagWithTrailingSolidus problem is encountered.

phoenix-ru commented 9 months ago

Raised concerns with SWC project in hopes to get a configuration flag for it https://github.com/swc-project/swc/discussions/8424

phoenix-ru commented 8 months ago

Closed in SWC via https://github.com/swc-project/swc/pull/8460