language-tools
language-tools copied to clipboard
False positive snippet usage before assignment errors
Describe the bug
Snippets are available anywhere in their scope. The language tools falsely surface errors if the order of definition and usage is reversed on the same level.
Reproduction
<script>
const address = null;
</script>
<div>
{@render (address ?? defaultAddress)()}
{#snippet defaultAddress()}Unknown address{/snippet}
</div>
Variable 'defaultAddress' is used before being assigned. js(2454)
Expected behaviour
No error.
System Info
- OS: Win 10
- IDE: VSCode
- Extension version: v108.5.2
Which package is the issue about?
No response
Additional Information, eg. Screenshots
No response
Top level snippets are hoisted to the top, guess we need to do that for nested snippets, too (top of their scope)
Leaving here as a record. I thought it would be easier to just transform it into a function declaration but snippets are actually block-scoped so the following won't be flagged as an error if it was transformed to a var or a function declaration but would result in a runtime error. This might also mean, at least nested one, const is more correct than the current var.
<div>
{#snippet hi()}{/snippet}
</div>
{@render hi()}