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

fix: error for rune usage in {@const} tag initialization #15044

Closed
wants to merge 3 commits into from

Conversation

paoloricciuti
Copy link
Member

Closes #15042

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

Copy link

changeset-bot bot commented Jan 17, 2025

🦋 Changeset detected

Latest commit: 15e2e0f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Rich-Harris
Copy link
Member

preview: https://svelte-dev-git-preview-svelte-15044-svelte.vercel.app/

this is an automated message

Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@15044

for (let declaration of node.declaration.declarations) {
const rune = get_rune(declaration.init, context.state.scope);
if (rune) {
e.const_tag_invalid_rune_usage(declaration.init, rune);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we start with the more generic "rune X cannot be used here" errors that already exist? that way we don't need to invent another error code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh i knew we had an error like this...i tried to search for it and miserably failed 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh actually we don't have a generic one...we only have specific ones (i think)...i'll check better after TWIS!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah confirmed there's no generic rune X cannot be used here...should we create a generic error like this instead of the specific one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was that you check which rune it is and then throw one of the more specific "X can only be used at ..." errors - I haven't checked the error message itself though, so if you find that's not possible then yes maybe a more generic error message.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the other error messages are very specific... I'll create a rune_cannot_be_used error

@svelte-docs-bot
Copy link

@Rich-Harris
Copy link
Member

This doesn't seem right to me. It should be totally fine to do this for example:

{#snippet test()}
  {@const der = $state.snapshot(blah)}
{/snippet}

Let's just fix up the existing logic around state_invalid_placement so that variable declarations inside {@const ...} tags are excluded

@Rich-Harris
Copy link
Member

Opened #15115

@theonlypwner
Copy link

This doesn't seem right to me. It should be totally fine to do this for example:

{#snippet test()}
  {@const der = $state.snapshot(blah)}
{/snippet}

Let's just fix up the existing logic around state_invalid_placement so that variable declarations inside {@const ...} tags are excluded

@Rich-Harris this seems to be disallowed in 5.19.3

image

@Rich-Harris
Copy link
Member

no it isn't

@theonlypwner
Copy link

theonlypwner commented Jan 27, 2025

never mind, I clicked your original link and saw "running Svelte compiler version 5.19.3" in the console but forgot to look at the URL, which contained version=pr-15044

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

$derived and $derived.by in {@const} tags results in obscure error message
4 participants