bublejs / buble

https://buble.surge.sh
MIT License
871 stars 64 forks source link

async/await -> using array method yields error #262

Open osban opened 4 years ago

osban commented 4 years ago

Hello, I ran into the following issue:

  1. code:
    
    const testarray = [
    {id: 1, name: 'foo'},
    {id: 2, name: 'bar'}
    ]
    const doarray = [2]

const test = async () => { for (let i=0; i < doarray.length; i++) { const a = testarray.findIndex(x => x.id === doarray[i]) await Promise.resolve(console.log(a)) } } test()

result: Error: Cannot use keyword 'await' outside an async function.

2. code:
```js
const testarray = [
  {id: 1, name: 'foo'},
  {id: 2, name: 'bar'}
]
const doarray = [2]

const test = async () => {
  const geta = i => testarray.findIndex(x => x.id === doarray[i])

  for (let i=0; i < doarray.length; i++) {
    const a = geta(i)
    await Promise.resolve(console.log(a))
  }
}
test()

result: compiles fine.

This was encountered using Rollup 2.21.0 and @rollup/plugin-buble 0.21.3 (Windows 10), with:

transforms: {asyncAwait: false}