Closed
Description
TypeScript Version: Nightly
Search Terms: top-level await newline duplicate duplicated
Code
export let foo = () => {
console.log('called')
return Promise.resolve(123)
}
export let bar = await
foo()
Expected behavior:
The generated code should only call foo()
once.
Actual behavior:
The generated code calls foo()
twice:
export let foo = () => {
console.log('called');
return Promise.resolve(123);
};
export let bar = await foo();
foo();
This may lead to subtle correctness bugs. This only happens when there's a newline between the await
keyword and the awaited expression. This also only happens for top-level await. Enclosing the await in an async function makes the bug disappear.
Playground Link: link
Related Issues: