Skip to content

Svelte 5: Spread args function extraction issue #9689

@brunnerh

Description

@brunnerh

Describe the bug

The compiler extracts functions to the top level scope and adds dependencies as arguments at the end.
This does not work if the function has spread arguments.

(Found by jakub on Discord.)

Reproduction

<script>
    let count = $state(0);
    function increment(...args) {
        count += 1
    }
</script>

<button on:click={increment}>
    clicks: {count}
</button>

Comma is not permitted after the rest element (6:26)

REPL

Generated JS:

function increment(...args, count) {
	$.set(count, $.get(count) + 1);
}

Logs

No response

System Info

REPL

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions