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

"Unexpected block closing tag" when using </input> #224

Closed
frafra opened this issue Dec 24, 2016 · 4 comments
Closed

"Unexpected block closing tag" when using </input> #224

frafra opened this issue Dec 24, 2016 · 4 comments

Comments

@frafra
Copy link

frafra commented Dec 24, 2016

Working code:

<table>
  {{#each rows as row}}
    <tr>
      {{#each columns as col}}
        <td>
          {{matrix.get([row, col])}}
        </td>
      {{/each}}
    </tr>
  {{/each}}
</table>

<script>
  export default {
    computed: {
      rows: matrix => [...Array(matrix.size()[0]).keys()],
      columns: matrix => [...Array(matrix.size()[1]).keys()],
    }
  }
</script>

If I replace {{matrix.get([row, col])}} with <input>{{matrix.get([row, col])}}</input> I get this error:

$ node ./node_modules/.bin/svelte compile --format iife components/Matrix.html
svelte version 1.3.0
compiling components/Matrix.html...
Unexpected block closing tag
 6:           <input>{{matrix.get([row, col])}}</input>
 7:         </td>
 8:       {{/each}}
             ^
 9:     </tr>
10:   {{/each}}
@frafra
Copy link
Author

frafra commented Dec 24, 2016

I suppose that invalid HTML closing tabs could be problematic.
If I use <input> as usual, I get no error:

<input value='{{matrix.get([row, col])}}' type='number' on:change='change(row, col, event.target.value)' />

@frafra
Copy link
Author

frafra commented Dec 24, 2016

Ok, I think that the only problem here could be the misleading position of ^

@Rich-Harris
Copy link
Member

There's a couple of things going on here – Svelte doesn't do a very good job of dealing with unexpected tags at all. It needs to figure out which elements are closed by a particular closing tag (elements plural because things like <div><ul><li>one<li>two<li>three</div> are totally valid HTML) and kick up a fuss if it sees something awry, rather than waiting to get confused over a closing block tag.

But in this particular case it's slightly simpler, because </input> is invalid – a void tag can't have children. We can detect that easily and print a more useful error. #225 implements that

Rich-Harris added a commit that referenced this issue Dec 24, 2016
provide useful feedback on encountering void element closing tag
@Rich-Harris
Copy link
Member

Svelte does a much better job now (particularly as of 1.8.1, just released) of providing useful feedback when HTML isn't formed quite right, so I'll close this issue. Thanks!

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

No branches or pull requests

2 participants