oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.58k stars 2.72k forks source link

missing correct message error when using await inside a non async function #8339

Closed huilensolis closed 8 months ago

huilensolis commented 8 months ago

What version of Bun is running?

1.0.0

What platform is your computer?

Linux 6.5.5-arch1-1 x86_64

What steps can reproduce the bug?

async function test(){
   const a = await fetch('/asdfas')
   return Promise.resolve({test: a})
}

function run(){
  const { test } = await test()
}

What is the expected behavior?

a more descriptive message, something like what the linters do.

"'await' expressions are only allowed within async functions and at the top levels of modules"

What do you see instead?

error: Expected ";" but found "test"

  const {test} = await test()
                       ^
/home/huilensolis/test.js:7:24 137

error: Expected "=>" but found "}"

}
^
/home/huilensolis/test.js:8:1 144

Additional information

No response

Electroid commented 8 months ago

Duplicate of #108