mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Fix temp variable scoping in async generators (#38121)
This commit is contained in:
parent
689822c183
commit
38ff7762ec
@ -1115,7 +1115,7 @@ namespace ts {
|
||||
context.requestEmitHelper(asyncGeneratorHelper);
|
||||
|
||||
// Mark this node as originally an async function
|
||||
(generatorFunc.emitNode || (generatorFunc.emitNode = {} as EmitNode)).flags |= EmitFlags.AsyncFunctionBody;
|
||||
(generatorFunc.emitNode || (generatorFunc.emitNode = {} as EmitNode)).flags |= EmitFlags.AsyncFunctionBody | EmitFlags.ReuseTempVariableScope;
|
||||
|
||||
return createCall(
|
||||
getUnscopedHelperName("__asyncGenerator"),
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
//// [nullishCoalescingOperatorInAsyncGenerator.ts]
|
||||
// https://github.com/microsoft/TypeScript/issues/37686
|
||||
async function* f(a: { b?: number }) {
|
||||
let c = a.b ?? 10;
|
||||
while (c) {
|
||||
yield c--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [nullishCoalescingOperatorInAsyncGenerator.js]
|
||||
// https://github.com/microsoft/TypeScript/issues/37686
|
||||
function f(a) {
|
||||
var _a;
|
||||
return __asyncGenerator(this, arguments, function* f_1() {
|
||||
let c = (_a = a.b) !== null && _a !== void 0 ? _a : 10;
|
||||
while (c) {
|
||||
yield yield __await(c--);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
//// [nullishCoalescingOperatorInAsyncGenerator.ts]
|
||||
// https://github.com/microsoft/TypeScript/issues/37686
|
||||
async function* f(a: { b?: number }) {
|
||||
let c = a.b ?? 10;
|
||||
while (c) {
|
||||
yield c--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [nullishCoalescingOperatorInAsyncGenerator.js]
|
||||
// https://github.com/microsoft/TypeScript/issues/37686
|
||||
function f(a) {
|
||||
var _a;
|
||||
return __asyncGenerator(this, arguments, function f_1() {
|
||||
var c;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
c = (_a = a.b) !== null && _a !== void 0 ? _a : 10;
|
||||
_b.label = 1;
|
||||
case 1:
|
||||
if (!c) return [3 /*break*/, 4];
|
||||
return [4 /*yield*/, __await(c--)];
|
||||
case 2: return [4 /*yield*/, _b.sent()];
|
||||
case 3:
|
||||
_b.sent();
|
||||
return [3 /*break*/, 1];
|
||||
case 4: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
//// [nullishCoalescingOperatorInAsyncGenerator.ts]
|
||||
// https://github.com/microsoft/TypeScript/issues/37686
|
||||
async function* f(a: { b?: number }) {
|
||||
let c = a.b ?? 10;
|
||||
while (c) {
|
||||
yield c--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [nullishCoalescingOperatorInAsyncGenerator.js]
|
||||
// https://github.com/microsoft/TypeScript/issues/37686
|
||||
async function* f(a) {
|
||||
let c = a.b ?? 10;
|
||||
while (c) {
|
||||
yield c--;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
// @target: esnext,es2015,es5
|
||||
// @lib: esnext
|
||||
// @noEmitHelpers: true
|
||||
// @noTypesAndSymbols: true
|
||||
|
||||
// https://github.com/microsoft/TypeScript/issues/37686
|
||||
async function* f(a: { b?: number }) {
|
||||
let c = a.b ?? 10;
|
||||
while (c) {
|
||||
yield c--;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user