Self-closing `/>` is invalid syntax on non-void HTML elements
phoenix-ru opened this issue · comments
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:
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.
Raised concerns with SWC project in hopes to get a configuration flag for it
swc-project/swc#8424
Closed in SWC via swc-project/swc#8460