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

Svelte 5: Snippets available in <script> #2201

Closed
eddiemcconkie opened this issue Nov 13, 2023 · 1 comment
Closed

Svelte 5: Snippets available in <script> #2201

eddiemcconkie opened this issue Nov 13, 2023 · 1 comment
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.

Comments

@eddiemcconkie
Copy link

eddiemcconkie commented Nov 13, 2023

Describe the bug

I just found out that if you create a {#snippet} in your component, you can reference it from the script tag:

<script>
  console.log(mySnippet) // Shows type error, but works fine
</script>

{#snippet mySnippet()}
  ...
{/snippet}

Not sure if this is a bug, or if this is actually ok behavior and the type checker just marks it as an error since the snippet function isn't declared inside the script tag. I do see this as potentially useful, though, if you wanted to pass a snippet around through a store or context (see REPL). And in that case, the fix could probably just be to make intellisense aware of snippets inside the script tag.

Reproduction

REPL

This actually looks and works fine in the REPL. If you have this same code in VS Code though, it will highlight mySnippet as an error inside setContext

Logs

No response

System Info

System:
    OS: macOS 14.0
    CPU: (10) arm64 Apple M1 Max
    Memory: 460.05 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.1 - ~/.nvm/versions/node/v18.16.1/bin/node
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.1/bin/npm
    pnpm: 8.6.3 - /opt/homebrew/bin/pnpm
  Browsers:
    Chrome: 119.0.6045.123
    Safari: 17.0
  npmPackages:
    svelte: 5.0.0-next.1 => 5.0.0-next.1

Severity

annoyance

@dummdidumm
Copy link
Member

It's not a bug, it's a feature 😉 This is intended to work. Intellisense just doesn't know about that yet, therefore transfering to language-tools.

@dummdidumm dummdidumm transferred this issue from sveltejs/svelte Nov 13, 2023
@dummdidumm dummdidumm added the bug Something isn't working label Nov 13, 2023
@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Nov 21, 2023
dummdidumm added a commit that referenced this issue Nov 21, 2023

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.
Projects
None yet
Development

No branches or pull requests

2 participants