Skip to content

Async generator with yield* in inner loop cannot manually return as expected #9905

@Cerlancism

Description

@Cerlancism

Bug Report

Manually return an async generator with yield* in a inner loop it will remain to yield.

Input Code

async function* func1()
{
    yield await "yield 1"
    yield await "yield 2"
    yield await "yield 3"
}

async function* func2()
{
    let i = 5
    while (i--) // Inner loop here
    {
        yield* await func1()
    }
}

(async () =>
{
    const iterator = func2();
    for await (let item of iterator)
    {
        console.log(item)
        iterator.return() // manual return at first iteration
    }
})()

Expected behavior/code
logs

yield 1

Current Behavior
logs

yield 1
yield 2
yield 2
yield 2
yield 2

Babel Configuration (.babelrc, package.json, cli command)

{
  "plugins": [
    [
      "@babel/plugin-transform-runtime"
    ]
  ],
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": {
          "ie": "11"
        }
      }
    ]
  ]
}

Environment

  • Babel version(s): 7.3.4
  • Node/npm version: v10.14.1
  • OS: Windows 10
  • How you are using Babel: With ParcelJS

Metadata

Metadata

Assignees

No one assigned

    Labels

    Has PRoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions