svelte icon indicating copy to clipboard operation
svelte copied to clipboard

@const isn't available to use within a component child that uses slot="name"

Open FireMakeThunder opened this issue 3 years ago • 0 comments

Describe the bug

This code won't compile though it appears it should. It happens when using an element or svelte:fragment with slot="name".

<!-- @const being used in element with named slot won't compile -->
<Component>
	{@const id = 'create-element'}
	<p slot="actions">
		{id}
	</p>
</Component>

Here's the origin of this issue: https://discord.com/channels/457912077277855764/1004908328910065735

Reproduction

https://svelte.dev/repl/ccf594828d8b4fc8b4e474d0fcb16481?version=3.49.0

Logs

No response

System Info

N/A

Severity

annoyance

FireMakeThunder avatar Aug 05 '22 03:08 FireMakeThunder

You should define the {@const} within the `slot="actions" element

<Component>
	<p slot="actions">
             {@const id = 'create-element'}
             {id}
	</p>
</Component>

whats outside is belongs to the default slot, instead of the "actions" named slot.

tanhauhau avatar Aug 15 '22 02:08 tanhauhau