bublejs / bublejs/buble

async/await -> using array method yields error

Open
#262 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
874
Forks
62
PR merge metrics
No merged PRs in 30d

Description

Hello, I ran into the following issue:

1. code:
```js
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:
```js
transforms: {asyncAwait: false}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce both JavaScript snippets with Rollup 2.21.0 and @rollup/plugin-buble 0.21.3 on Windows 10, using transforms: {asyncAwait: false}. Compare the inline findIndex callback with the helper-function form; done means the first form compiles without the reported “await outside an async function” error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, rollup
Domain
build-system, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.