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

Allow @const inside #key #15376

Open
michelAlexis opened this issue Feb 23, 2025 · 3 comments · May be fixed by #15377
Open

Allow @const inside #key #15376

michelAlexis opened this issue Feb 23, 2025 · 3 comments · May be fixed by #15377

Comments

@michelAlexis
Copy link

Describe the problem

Hi !
After discussion on the discord, the question remains. Why isn't it possible to use @const inside #key ?

When @const is the first child of a #key, the compile gives us the "const_tag_invalid_placement". Which list every other # keywords, so why not #key ?

This is not a big deal. there are multiple workaround for that.

  • <svelte:boundary> for inside loops when a parameter is necessary
  • $derived but have to create an unused var

Small playground for reproduction and workarounds.

I don't know if this is just a missing feature/bug or if there are more implications that I am not aware of.

First time issue here, feel free to correct me I missed something, or close the issue if it's an intended behaviour.
I am not familiar enough to create a PR for this (As I don't know if editing the Visitor ConstTag is enough).

Describe the proposed solution

Allow @const inside #key as it make sense to create a template variable inside a reactive scope.

Importance

nice to have

@paoloricciuti
Copy link
Member

I think it could make sense, and if you feel adventurous and want to try a PR the fix should be, like you said, to just add an extra condition in the const tag visitor. If you decide to so please make sure to also add a test in the validator folder with a key block with a const inside and an errors.json with an empty array in it.

Otherwise I'll see if I can open the PR myself later.

@michelAlexis
Copy link
Author

Seems simple enough, I will give it a shot!
Just to be sure, this is the file you are talking about ? (A bit confused by the old and new test suite described in the readme)

@paoloricciuti
Copy link
Member

Seems simple enough, I will give it a shot! Just to be sure, this is the file you are talking about ? (A bit confused by the old and new test suite described in the readme)

That's the folder...you need to create a new folder in the samples folder above that file with an unique name and an input.svelte file in it (or main.svelte I can never remember)...you can just take inspiration from the other folders

@michelAlexis michelAlexis linked a pull request Feb 23, 2025 that will close this issue
6 tasks
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 a pull request may close this issue.

2 participants