language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

Warn the user to use {@render} instead of {} with snippets

Open RaphGL opened this issue 1 year ago • 0 comments

Description

When using a snippet to "render" it to the DOM, you have to use {@render snippetname()} but simply using {snippetname} is valid svelte code and is not rejected by the compiler, this results in a bunch of javascript text instead of what the user actually wants (render the actual content).

Proposed solution

When there's type information available, check for if an identifier is a Snippet then upon asserting that it in fact is a snippet then warn the user and ask for them to instead use {@render <snippetName>()}

If the javascript output is intended (???), some sort of directive could be used to disable the warning for that instance. Not sure if this exists in the svelte LSP.

Alternatives

No response

Additional Information, eg. Screenshots

{#snippet something()}
  <p>hello</p>
{/snippet}

 <!-- the compiler is happy to render it without caring about whether it's a snippet or not -->
<div>{something}</div>

<!-- works as intended -->
<div>{@render something()}</div> 

RaphGL avatar Oct 27 '24 13:10 RaphGL