mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-17 21:09:09 -05:00
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:
@@ -541,7 +541,7 @@ export const asyncDelegator: UnscopedEmitHelper = {
|
||||
var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
|
||||
var i, p;
|
||||
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
||||
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
|
||||
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
|
||||
};`
|
||||
};
|
||||
|
||||
|
||||
@@ -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 }
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user