Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
osban opened this issue Jul 16, 2020 · 0 comments
Open

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

osban opened this issue Jul 16, 2020 · 0 comments

Comments

@osban
Copy link

osban commented Jul 16, 2020

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.

  1. code:
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}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant