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

@const declaration inside components ignored #7189

Closed
nsmaciej opened this issue Jan 26, 2022 · 2 comments · Fixed by #7434
Closed

@const declaration inside components ignored #7189

nsmaciej opened this issue Jan 26, 2022 · 2 comments · Fixed by #7434

Comments

@nsmaciej
Copy link

Describe the bug

The docs state that

{@const} is only allowed as direct child of {#each}, {:then}, {:catch}, <Component /> or <svelte:fragment />.

but currently if you use it inside a component slot the compiler fails to emit the assignment and the code throws at runtime.

<script>
	import Heading from './Heading.svelte';
</script>
<Heading>
	{@const heading = "Hello world"}
	{heading}
</Heading>

If this is not the intended usage of @const (I hope it is though) the compiler should produce an error, otherwise it should emit the assignment.

Reproduction

https://svelte.dev/repl/d01b574992e04be294ba081cddbf6859?version=3.46.2

Logs

No response

System Info

System:
    OS: macOS 12.1
    CPU: (8) arm64 Apple M1
    Memory: 108.55 MB / 8.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 17.3.0 - /opt/homebrew/bin/node
    npm: 8.3.0 - /opt/homebrew/bin/npm
  Browsers:
    Chrome: 97.0.4692.99
    Safari: 15.2
    Safari Technology Preview: 15.4
  npmPackages:
    rollup: ^2.3.4 => 2.66.1
    svelte: ^3.0.0 => 3.46.2

Severity

annoyance

@Conduitry
Copy link
Member

Looking at the tests for this aspect of this feature, I suspect it was intended only to work with let: variables from the component. If that's so, the docs should be made a bit clearer and the compiler should throw an exception rather than ignoring the {@const}.

@Conduitry
Copy link
Member

This should be fixed in 3.48.0 - https://svelte.dev/repl/d01b574992e04be294ba081cddbf6859?version=3.48.0

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