Skip to content
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

Misleading error message, when only open tag is in if else block #4131

Closed
btamas opened this issue Dec 19, 2019 · 5 comments · Fixed by #4136
Closed

Misleading error message, when only open tag is in if else block #4131

btamas opened this issue Dec 19, 2019 · 5 comments · Fixed by #4136

Comments

@btamas
Copy link

btamas commented Dec 19, 2019

Describe the bug
Wrong error message when the open html tag is in a condition.
Cannot have an {:else} block outside an {#if ...} or {#each ...} block (3:6)

To Reproduce
https://svelte.dev/repl/116df8158726422db28a6904f8bb49f2?version=3.16.5

Expected behavior
A message that informs me about I cannot have only open tag between conditions.

Severity
Low, but it can mislead debug

@antony
Copy link
Member

antony commented Dec 20, 2019

I think this behaviour is correct. If you look at the simplified example below:

https://svelte.dev/repl/529ae6f101a548ac8bc0c0ad2f1eac63?version=3.16.5

Although it could be considered "misleading", actually, you are opening a new block, and then opening a new logic tag. So the error is correct.

I suppose it depends on how far you want to go into Svelte becoming some sort of html validator/linter/formatter, and I think the answer is, not very far.

@btamas
Copy link
Author

btamas commented Dec 20, 2019

I understand your point and if I would be a code parser then I would see it is a new logic block and it is not the if block anymore.
I can live with this behavior, but it is still misleading for me.

@ghost
Copy link

ghost commented Dec 20, 2019

I checked all the way back to first release of 3.0 and the message hasn't changed.
I do understand where the confusion comes from, but the error message is based on how the DOM and HTML work. Replace the else with <div>... would you expect the div to somehow escape the <li> tag?

So treat all Svelte keywords as creating scope because that's what they do essentially.
Maybe you could look for a place within the docs to add some wording to make things clearer.

@Conduitry
Copy link
Member

These error messages have improved in 3.18.2 - https://svelte.dev/repl/116df8158726422db28a6904f8bb49f2?version=3.18.2

@btamas
Copy link
Author

btamas commented Feb 9, 2020

These error messages have improved in 3.18.2 - https://svelte.dev/repl/116df8158726422db28a6904f8bb49f2?version=3.18.2

Thank you, it is way more helpful now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants