Skip to content

Allow @const inside #key #15376

@michelAlexis

Description

@michelAlexis

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions