Skip to content

Svelte 5: Snippet references do not prevent function from being pulled out of component scope #9460

@brunnerh

Description

@brunnerh

Describe the bug

Snippets at the top level declare a variable in the component, if the variable is referenced in a script function, the compiler should make sure it does not lose the reference by moving the function around. Currently this can happen.

Use cases include e.g. passing a snippet to a modal showing function.

Reproduction

<script>
	function log() {
		console.log(snippet)
	}
</script>
{#snippet snippet()}Hello{/snippet}
<button on:click={log}>
	log snippet
</button>

REPL

Logs

No response

System Info

REPL

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions