sveltejs / language-tools

The Svelte Language Server, and official extensions which use it
MIT License
1.18k stars 190 forks source link

False positive snippet usage before assignment errors #2417

Open brunnerh opened 1 week ago

brunnerh commented 1 week ago

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)

screenshot of error

Expected behaviour

No error.

System Info

Which package is the issue about?

No response

Additional Information, eg. Screenshots

No response

dummdidumm commented 1 week ago

Top level snippets are hoisted to the top, guess we need to do that for nested snippets, too (top of their scope)