Bug Report
π Search Terms
async iterator, for await loop
π Version & Regression Information
- This changed after version v4.9.3
β― Playground Link
Target: ES2017 (with actual result)
Playground link with relevant code
Target: ES2018 (with expected result)
Playground link with relevant code
π» Code
tsconfig.json
{
"compilerOptions": {
"target": "ES2017",
}
}
index.ts
const asyncIterable = {
[Symbol.asyncIterator]() {
return {
next() {
console.log('next()');
return { value: '!', done: false };
},
return(value: string) {
console.log('return()');
return { value, done: true };
},
};
}
};
const main = async () => {
for await (const x of asyncIterable) {
console.log(x);
break;
}
}
main();
Thanks to @kbridge for making MCVE.
π Actual behavior
Should call return() for an abrupt completion at for await of loop (e.g. break, throw). This happens when for-await-loop code is transformed to target equal or lower than ES2017.
π Expected behavior
If target for compilation is equal or higher than ES2018, It works as expected. This is also aligned with javascript specification.
Bug Report
π Search Terms
async iterator, for await loop
π Version & Regression Information
β― Playground Link
Target: ES2017 (with actual result)
Playground link with relevant code
Target: ES2018 (with expected result)
Playground link with relevant code
π» Code
tsconfig.json
{ "compilerOptions": { "target": "ES2017", } }index.ts
Thanks to @kbridge for making MCVE.
π Actual behavior
Should call
return()for an abrupt completion at for await of loop (e.g.break,throw). This happens whenfor-await-loopcode is transformed to target equal or lower thanES2017.π Expected behavior
If target for compilation is equal or higher than
ES2018, It works as expected. This is also aligned with javascript specification.