Skip to content

Commit 48f2995

Browse files
committed
hasContextSensitiveYieldExpression
1 parent e22b095 commit 48f2995

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/compiler/checker.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21155,7 +21155,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2115521155
}
2115621156

2115721157
function isContextSensitiveFunctionLikeDeclaration(node: FunctionLikeDeclaration): boolean {
21158-
return hasContextSensitiveParameters(node) || hasContextSensitiveReturnExpression(node) || !!(getFunctionFlags(node) & FunctionFlags.Generator && node.body && forEachYieldExpression(node.body as Block, isContextSensitive));
21158+
return hasContextSensitiveParameters(node) || hasContextSensitiveReturnExpression(node) || hasContextSensitiveYieldExpression(node);
2115921159
}
2116021160

2116121161
function hasContextSensitiveReturnExpression(node: FunctionLikeDeclaration) {
@@ -21168,6 +21168,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2116821168
return !!forEachReturnStatement(node.body as Block, statement => !!statement.expression && isContextSensitive(statement.expression));
2116921169
}
2117021170

21171+
function hasContextSensitiveYieldExpression(node: FunctionLikeDeclaration): boolean {
21172+
// yield expressions can be context sensitive in situations like:
21173+
//
21174+
// declare function test(gen: () => Generator<(arg: number) => string, void, void>): void;
21175+
//
21176+
// test(function* () {
21177+
// yield (arg) => String(arg);
21178+
// });
21179+
return !!(getFunctionFlags(node) & FunctionFlags.Generator && node.body && forEachYieldExpression(node.body as Block, isContextSensitive));
21180+
}
21181+
2117121182
function isContextSensitiveFunctionOrObjectLiteralMethod(func: Node): func is FunctionExpression | ArrowFunction | MethodDeclaration {
2117221183
return (isFunctionExpressionOrArrowFunction(func) || isObjectLiteralMethod(func)) &&
2117321184
isContextSensitiveFunctionLikeDeclaration(func);

0 commit comments

Comments
 (0)