Skip to content

Commit 1f4c870

Browse files
authored
fix(44123): forbid convert to async for generator callbacks (microsoft#44147)
1 parent e34b2ad commit 1f4c870

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/services/suggestionDiagnostics.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ namespace ts {
174174
switch (arg.kind) {
175175
case SyntaxKind.FunctionDeclaration:
176176
case SyntaxKind.FunctionExpression:
177+
const functionFlags = getFunctionFlags(arg as FunctionDeclaration | FunctionExpression);
178+
if (functionFlags & FunctionFlags.Generator) {
179+
return false;
180+
}
181+
// falls through
177182
case SyntaxKind.ArrowFunction:
178183
visitedNestedConvertibleFunctions.set(getKeyFromNode(arg as FunctionLikeDeclaration), true);
179184
// falls through

src/testRunner/unittests/services/convertToAsyncFunction.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,6 +1706,16 @@ class Foo {
17061706
return Promise.resolve(1).then(n => n);
17071707
}
17081708
}
1709+
`);
1710+
1711+
_testConvertToAsyncFunctionFailed("convertToAsyncFunction__NoSuggestionForGeneratorCallbacks", `
1712+
function [#|foo|](p: Promise<string[]>) {
1713+
return p.then(function* (strings) {
1714+
for (const s of strings) {
1715+
yield s.toUpperCase();
1716+
}
1717+
});
1718+
}
17091719
`);
17101720

17111721
});

0 commit comments

Comments
 (0)