fix(44123): forbid convert to async for generator callbacks (#44147)

This commit is contained in:
Oleksandr T
2021-05-28 14:42:09 -07:00
committed by GitHub
parent e34b2adcae
commit 1f4c8708c2
2 changed files with 15 additions and 0 deletions
+5
View File
@@ -174,6 +174,11 @@ namespace ts {
switch (arg.kind) {
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.FunctionExpression:
const functionFlags = getFunctionFlags(arg as FunctionDeclaration | FunctionExpression);
if (functionFlags & FunctionFlags.Generator) {
return false;
}
// falls through
case SyntaxKind.ArrowFunction:
visitedNestedConvertibleFunctions.set(getKeyFromNode(arg as FunctionLikeDeclaration), true);
// falls through
@@ -1706,6 +1706,16 @@ class Foo {
return Promise.resolve(1).then(n => n);
}
}
`);
_testConvertToAsyncFunctionFailed("convertToAsyncFunction__NoSuggestionForGeneratorCallbacks", `
function [#|foo|](p: Promise<string[]>) {
return p.then(function* (strings) {
for (const s of strings) {
yield s.toUpperCase();
}
});
}
`);
});