You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In VSCode the svelte language server breaks when exporting a snippet that:
makes use of a Svelte component that spreads the props gotten as an argument
uses an #if statement referencing an "unknown" identifier like Error (i.e it can't find it in the file scope)
Reproduction
<!-- App.svelte --><scriptlang="ts" module>importDummyfrom"./DummyComponent.svelte";importtype{HTMLAttributes}from"svelte/elements";export{errorBoundary};// ERROR HERE: cannot find name 'errorBoundary'export{WithProps};// ERROR HERE: cannot find name 'WithProps'</script>
{#snippet errorBoundary(error: unknown, reset: () => void)}
<Dummyclass="text-red">This is a boundary</Dummy>
{#if error instanceof Error}
<p>This is causing the error in the module script</p>
{/if}
<buttononclick={reset}>Reset</button>
{/snippet}
{#snippet WithProps(props: HTMLAttributes<HTMLDivElement>)}
<Dummy{...props}><h1>This is a snippet with Props</h1></Dummy>
{/snippet}
More generally it seems to happen when trying to export snippets that reference any declaration defined outside1 of the snippet.
This makes sense for declarations defined in the component's instance2. This should not happen for snippets that do not reference such declarations but reference declarations from the <script module>.
I've ran into this issue when trying to create formatter snippets, with one formatter converting from svx3 resulting in the mentioned Cannot find name 'withDependencies' TypeScript error. The error does not impact compilation and everything works as expected.
The error only occurs if a non-module1 declaration is used.
The error is more descriptive. Example: Cannot export snippets referencing variables defined outside the <script module>
Footnotes
a declaration that is not defined in the <script module>, i.e. a declaration that is neither a snippet parameter nor a @const declaration within the snippet's body. ↩↩2
i.e. imports or variables in the <script> tag, or other top-level snippets depending on non-module declarations ↩
Describe the bug
In VSCode the svelte language server breaks when exporting a snippet that:
props
gotten as an argument#if
statement referencing an "unknown" identifier likeError
(i.e it can't find it in the file scope)Reproduction
Expected behaviour
There shouldn't be an error because the compiler doesn't break as shown in this REPL
System Info
Which package is the issue about?
Svelte for VS Code extension, svelte-language-server
Additional Information, eg. Screenshots
The text was updated successfully, but these errors were encountered: