Skip to content

Lowered async generator return function doesn't resolve promise argumentΒ #54768

@evanw

Description

@evanw

Bug Report

πŸ”Ž Search Terms

async generator return promise

πŸ•— Version & Regression Information

  • This is the behavior in every version available in the playground

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

/// <reference lib="esnext" />
async function* fn() {
  yield* [1]
  return 3
}
async function test() {
  const it = fn()
  console.log(await it.next())
  console.log(await it.return(Promise.resolve(2)))
}
test()

πŸ™ Actual behavior

When transformed by TypeScript to ES2017, this code prints the following:

{value: 1, done: false}
{value: Promise, done: true}

πŸ™‚ Expected behavior

When run natively, this code prints the following:

{value: 1, done: false}
{value: 2, done: true}

I discovered this bug when implementing async generator transformation for esbuild. I was running relevant test262 tests through both TypeScript and esbuild's transformations and comparing the differences. There are other TypeScript-only test failures as well but they mostly involve weird uses of the API where getters throw errors, which doesn't seem like something that would come up in practice. So I'm only reporting this bug because this seems like more of an important correctness issue. Let me know if you'd like to know about the other test failures too.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions