-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Implicitly closing tags aren't allowed before closing block #2807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'll go ahead and be the negative nancy and say implicitly closing tags probably shouldn't be supported even if they are valid html, they would in my mind introduce complexity and make debugging harder. Just my $0.02 |
I'll go out on a limb here and would advocate the same as mrkishi. Keep it and make it work with mustaches as well. After all, less code is better https://svelte.dev/blog/write-less-code :) |
It's really hard to debug/maintain large trees where you have some unclosed tags. It often messes any closing tag highlighting help you get from IDEs as well. I'd rather have the compiler warn and throw early before it becomes a problem. |
While I understand that this feature might encourage some to write code which is difficult to debug/maintain, there are use cases where conditional opening and closing tags make sense in order to obey the DRY (Don´t Repeat Yourself) coding paradigm. Like this one:
In order to archive conditional structures like the one above, you currently need to use redundant code, which is not elegant. Imho, you should consider to add this feature despite the reasonable objections mentioned beforehand.. |
@teamore Unfortunately, that wouldn't be possible without major changes in how Svelte works, fundamentally. Svelte needs to understand the structure of the component statically, and the compiler works with the complete well-formed tree of tags. While that example would indeed generate a valid tag in all cases if we were doing raw text templating, it would be impossible for the compiler to parse a valid and unique structure for arbitrary expressions and tree shapes. |
Is it still not possible in Svelte 4? |
This is breaking my whole workflow on creating menu items dynamically. I'm going to be forced to put my logic in the <script> instead of the HTML. Sucks. |
Svelte supports implicitly closing tags like
<li>first <li>second
, but it won't allow them to be closed by a mustache closing block: https://svelte.dev/repl/733548506a2b44819e39157bd6a055d3.I don't think this is intuitive and would expect svelte to either disallow it everywhere (even though it's valid html) or relax the mustache closing block rules (what I'd personally prefer).
The text was updated successfully, but these errors were encountered: