Reproduction link or steps
We got this bug report in svelte sveltejs/svelte#18454 but after investigation the issue is actually from rolldown.
Having code like this
let waitWithInitPromise = waitWithInit();
let var1 = 0;
// Simulate a network request
async function wait(): Promise<number> {
await new Promise((resolve) => setTimeout(resolve, 3000));
return 1;
}
async function waitWithInit(): Promise<void> {
const num = await wait();
var1 = num;
}
console.log(waitWithInitPromise, var1)
As you can see in this REPL rollodown compress
async function waitWithInit(): Promise<void> {
const num = await wait();
var1 = num;
}
to
async function waitWithInit() {
var1 = await wait();
}
but that's a behavioural change because before you access var1 for the first time after the await and after you access it before.
What is expected?
async function waitWithInit(): Promise<void> {
const num = await wait();
var1 = num;
}
after tersing should not change the code so that var1 is accessed before the await
What is actually happening?
async function waitWithInit(): Promise<void> {
const num = await wait();
var1 = num;
}
is compiled to
async function waitWithInit() {
var1 = await wait();
}
which make so that var1 is accessed before the await.
System Info
Any additional comments?
No response
Reproduction link or steps
We got this bug report in svelte sveltejs/svelte#18454 but after investigation the issue is actually from rolldown.
Having code like this
As you can see in this REPL rollodown compress
to
but that's a behavioural change because before you access
var1for the first time after the await and after you access it before.What is expected?
after tersing should not change the code so that var1 is accessed before the
awaitWhat is actually happening?
is compiled to
which make so that
var1is accessed before the await.System Info
Any additional comments?
No response