Skip to content

Array destructuring broken in async script #17250

@paoloricciuti

Description

@paoloricciuti

Describe the bug

Having something as simple as this

<script>
	await Promise.resolve();
	const [] = $derived([]);
</script>

throws a ReferenceError $$array is not defined

this is because this is the generated code

import 'svelte/internal/disclose-version';
import 'svelte/internal/flags/async';
import * as $ from 'svelte/internal/client';

export default function App($$anchor) {
	var $$promises = $.run([
		() => Promise.resolve(),

		() => {
			var $$d = $.derived(() => []);

			$$array = $.derived(() => $.to_array($.get($$d), 0));
		}
	]);
}

which means $$array is not a multi declaration with $$d how it should be.

Reproduction

repl

Logs

System Info

repl

Severity

annoyance

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