Using await in a function that isn't async is illegal in JavaScript, so Prettier currently fails to format with a parser error. However, Prettier should be able to detect an await inside a function that doesn't have async and add it when formatting for convenience and to prevent confusion.
Prettier 2.1.1
Playground link
Input:
async function depenency() {}
function dependent() {
await dependency();
}
Output:
SyntaxError: Unexpected token, expected ";" (4:9)
2 |
3 | function dependent() {
> 4 | await dependency()
| ^
5 | }
Expected behavior:
async function depenency() {}
async function dependent() {
await dependency();
}
Using
awaitin a function that isn'tasyncis illegal in JavaScript, so Prettier currently fails to format with a parser error. However, Prettier should be able to detect anawaitinside a function that doesn't haveasyncand add it when formatting for convenience and to prevent confusion.Prettier 2.1.1
Playground link
Input:
Output:
Expected behavior: