Skip to content

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

@osban

Description

@osban

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}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions