MCPcopy Index your code
hub / github.com/nodejs/node / checkYieldExpression

Function checkYieldExpression

test/fixtures/snapshot/typescript.js:79381–79446  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

79379 return [effectiveLeft, effectiveRight];
79380 }
79381 function checkYieldExpression(node) {
79382 addLazyDiagnostic(checkYieldExpressionGrammar);
79383 var func = ts.getContainingFunction(node);
79384 if (!func)
79385 return anyType;
79386 var functionFlags = ts.getFunctionFlags(func);
79387 if (!(functionFlags & 1 /* FunctionFlags.Generator */)) {
79388 // If the user's code is syntactically correct, the func should always have a star. After all, we are in a yield context.
79389 return anyType;
79390 }
79391 var isAsync = (functionFlags & 2 /* FunctionFlags.Async */) !== 0;
79392 if (node.asteriskToken) {
79393 // Async generator functions prior to ESNext require the __await, __asyncDelegator,
79394 // and __asyncValues helpers
79395 if (isAsync && languageVersion < 99 /* ScriptTarget.ESNext */) {
79396 checkExternalEmitHelpers(node, 26624 /* ExternalEmitHelpers.AsyncDelegatorIncludes */);
79397 }
79398 // Generator functions prior to ES2015 require the __values helper
79399 if (!isAsync && languageVersion < 2 /* ScriptTarget.ES2015 */ && compilerOptions.downlevelIteration) {
79400 checkExternalEmitHelpers(node, 256 /* ExternalEmitHelpers.Values */);
79401 }
79402 }
79403 // There is no point in doing an assignability check if the function
79404 // has no explicit return type because the return type is directly computed
79405 // from the yield expressions.
79406 var returnType = getReturnTypeFromAnnotation(func);
79407 var iterationTypes = returnType && getIterationTypesOfGeneratorFunctionReturnType(returnType, isAsync);
79408 var signatureYieldType = iterationTypes && iterationTypes.yieldType || anyType;
79409 var signatureNextType = iterationTypes && iterationTypes.nextType || anyType;
79410 var resolvedSignatureNextType = isAsync ? getAwaitedType(signatureNextType) || anyType : signatureNextType;
79411 var yieldExpressionType = node.expression ? checkExpression(node.expression) : undefinedWideningType;
79412 var yieldedType = getYieldedTypeOfYieldExpression(node, yieldExpressionType, resolvedSignatureNextType, isAsync);
79413 if (returnType && yieldedType) {
79414 checkTypeAssignableToAndOptionallyElaborate(yieldedType, signatureYieldType, node.expression || node, node.expression);
79415 }
79416 if (node.asteriskToken) {
79417 var use = isAsync ? 19 /* IterationUse.AsyncYieldStar */ : 17 /* IterationUse.YieldStar */;
79418 return getIterationTypeOfIterable(use, 1 /* IterationTypeKind.Return */, yieldExpressionType, node.expression)
79419 || anyType;
79420 }
79421 else if (returnType) {
79422 return getIterationTypeOfGeneratorFunctionReturnType(2 /* IterationTypeKind.Next */, returnType, isAsync)
79423 || anyType;
79424 }
79425 var type = getContextualIterationType(2 /* IterationTypeKind.Next */, func);
79426 if (!type) {
79427 type = anyType;
79428 addLazyDiagnostic(function () {
79429 if (noImplicitAny && !ts.expressionResultIsUnused(node)) {
79430 var contextualType = getContextualType(node);
79431 if (!contextualType || isTypeAny(contextualType)) {
79432 error(node, ts.Diagnostics.yield_expression_implicitly_results_in_an_any_type_because_its_containing_generator_lacks_a_return_type_annotation);
79433 }
79434 }
79435 });
79436 }
79437 return type;
79438 function checkYieldExpressionGrammar() {

Callers 1

checkExpressionWorkerFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…