-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Closed
Labels
Description
Describe the bug
Below is some svelte 5 code and it's compiled output:
//Svelte 5 code
let user = $state(null)
const load_user = async () => {
[user] = await fetch_user()
}
//Compiler Output
const load_user = async (_, user, fetch_user) => {
(() => {
const tmp = await fetch_user(); //Cannot use keyword await outside async function
($.set(user, tmp[0]));
return tmp;
})();
};
As you can see the compiled code won't work because the wrapping function is not async. This only seems to happen you destructure the result of an await expression.
The compiler should probably add async
to the wrapping function
Reproduction
Logs
No response
System Info
System:
OS: Linux 5.15 Linux Mint 21.2 (Victoria)
CPU: (4) x64 Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz
Memory: 3.71 GB / 7.63 GB
Container: Yes
Shell: 5.1.16 - /bin/bash
Binaries:
Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
npmPackages:
svelte: ^5.0.0-next.13 => 5.0.0-next.13
Severity
annoyance