-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
Bug Report
π Search Terms
for await return next throw
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
Playground link with relevant code
π» Code
let pass = true
async function f() {
const y = {
[Symbol.asyncIterator]() {
let count = 0
return {
async next() {
count++
if (count === 2) throw 'error'
return { value: count }
},
async return() {
pass = false
},
}
},
}
for await (let x of y) {
}
}
f().catch(() => console.log({ pass }))π Actual behavior
The code prints { pass: false } when transformed by TypeScript with target ES2017 or lower.
π Expected behavior
The code prints { pass: true } when run natively and when transformed by Babel. I discovered this behavior difference when investigating doing a similar transform for esbuild.
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue