Fix asyncDelegator reporting "done" too early (#51274)

* Fix asyncDelegator reporting done too early

* Add unit test for yields inside finally block

See #45400
This commit is contained in:
Tomasz Lenarcik
2022-11-16 00:12:26 +01:00
committed by GitHub
parent 89ce16ccfd
commit dfc1242aaf
10 changed files with 43 additions and 17 deletions

View File

@@ -30,4 +30,30 @@ describe("unittests:: evaluation:: asyncGeneratorEvaluation", () => {
{ value: 0, done: true }
]);
});
it("yields in finally block with async delegator (es2017)", async () => {
const result = evaluator.evaluateTypeScript(`
async function* g1() {
try {
yield 1;
} finally {
yield 2;
}
}
async function* g2() {
yield* g1();
}
export const output: any[] = [];
export async function main() {
const it = g2();
output.push(await it.next());
output.push(await it.return());
output.push(await it.next());
}`, { target: ts.ScriptTarget.ES2017 });
await result.main();
assert.deepEqual(result.output, [
{ done: false, value: 1 },
{ done: false, value: 2 },
{ done: true, value: undefined }
]);
});
});