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

Function checkExpressionWithContextualType

test/fixtures/snapshot/typescript.js:79483–79510  ·  view source on GitHub ↗
(node, contextualType, inferenceContext, checkMode)

Source from the content-addressed store, hash-verified

79481 return node;
79482 }
79483 function checkExpressionWithContextualType(node, contextualType, inferenceContext, checkMode) {
79484 var context = getContextNode(node);
79485 var saveContextualType = context.contextualType;
79486 var saveInferenceContext = context.inferenceContext;
79487 try {
79488 context.contextualType = contextualType;
79489 context.inferenceContext = inferenceContext;
79490 var type = checkExpression(node, checkMode | 1 /* CheckMode.Contextual */ | (inferenceContext ? 2 /* CheckMode.Inferential */ : 0));
79491 // In CheckMode.Inferential we collect intra-expression inference sites to process before fixing any type
79492 // parameters. This information is no longer needed after the call to checkExpression.
79493 if (inferenceContext && inferenceContext.intraExpressionInferenceSites) {
79494 inferenceContext.intraExpressionInferenceSites = undefined;
79495 }
79496 // We strip literal freshness when an appropriate contextual type is present such that contextually typed
79497 // literals always preserve their literal types (otherwise they might widen during type inference). An alternative
79498 // here would be to not mark contextually typed literals as fresh in the first place.
79499 var result = maybeTypeOfKind(type, 2944 /* TypeFlags.Literal */) && isLiteralOfContextualType(type, instantiateContextualType(contextualType, node)) ?
79500 getRegularTypeOfLiteralType(type) : type;
79501 return result;
79502 }
79503 finally {
79504 // In the event our operation is canceled or some other exception occurs, reset the contextual type
79505 // so that we do not accidentally hold onto an instance of the checker, as a Type created in the services layer
79506 // may hold onto the checker that created it.
79507 context.contextualType = saveContextualType;
79508 context.inferenceContext = saveInferenceContext;
79509 }
79510 }
79511 function checkExpressionCached(node, checkMode) {
79512 if (checkMode && checkMode !== 0 /* CheckMode.Normal */) {
79513 return checkExpression(node, checkMode);

Calls 6

getContextNodeFunction · 0.85
maybeTypeOfKindFunction · 0.85
checkExpressionFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…