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

Function checkCallExpression

test/fixtures/snapshot/typescript.js:77064–77121  ·  view source on GitHub ↗

* Syntactically and semantically checks a call or new expression. * @param node The call/new expression to be checked. * @returns On success, the expression's signature's return type. On failure, anyType.

(node, checkMode)

Source from the content-addressed store, hash-verified

77062 * @returns On success, the expression's signature's return type. On failure, anyType.
77063 */
77064 function checkCallExpression(node, checkMode) {
77065 var _a;
77066 checkGrammarTypeArguments(node, node.typeArguments);
77067 var signature = getResolvedSignature(node, /*candidatesOutArray*/ undefined, checkMode);
77068 if (signature === resolvingSignature) {
77069 // CheckMode.SkipGenericFunctions is enabled and this is a call to a generic function that
77070 // returns a function type. We defer checking and return nonInferrableType.
77071 return nonInferrableType;
77072 }
77073 checkDeprecatedSignature(signature, node);
77074 if (node.expression.kind === 106 /* SyntaxKind.SuperKeyword */) {
77075 return voidType;
77076 }
77077 if (node.kind === 209 /* SyntaxKind.NewExpression */) {
77078 var declaration = signature.declaration;
77079 if (declaration &&
77080 declaration.kind !== 171 /* SyntaxKind.Constructor */ &&
77081 declaration.kind !== 175 /* SyntaxKind.ConstructSignature */ &&
77082 declaration.kind !== 180 /* SyntaxKind.ConstructorType */ &&
77083 !ts.isJSDocConstructSignature(declaration) &&
77084 !isJSConstructor(declaration)) {
77085 // When resolved signature is a call signature (and not a construct signature) the result type is any
77086 if (noImplicitAny) {
77087 error(node, ts.Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type);
77088 }
77089 return anyType;
77090 }
77091 }
77092 // In JavaScript files, calls to any identifier 'require' are treated as external module imports
77093 if (ts.isInJSFile(node) && isCommonJsRequire(node)) {
77094 return resolveExternalModuleTypeByLiteral(node.arguments[0]);
77095 }
77096 var returnType = getReturnTypeOfSignature(signature);
77097 // Treat any call to the global 'Symbol' function that is part of a const variable or readonly property
77098 // as a fresh unique symbol literal type.
77099 if (returnType.flags & 12288 /* TypeFlags.ESSymbolLike */ && isSymbolOrSymbolForCall(node)) {
77100 return getESSymbolLikeTypeForNode(ts.walkUpParenthesizedExpressions(node.parent));
77101 }
77102 if (node.kind === 208 /* SyntaxKind.CallExpression */ && !node.questionDotToken && node.parent.kind === 238 /* SyntaxKind.ExpressionStatement */ &&
77103 returnType.flags & 16384 /* TypeFlags.Void */ && getTypePredicateOfSignature(signature)) {
77104 if (!ts.isDottedName(node.expression)) {
77105 error(node.expression, ts.Diagnostics.Assertions_require_the_call_target_to_be_an_identifier_or_qualified_name);
77106 }
77107 else if (!getEffectsSignature(node)) {
77108 var diagnostic = error(node.expression, ts.Diagnostics.Assertions_require_every_name_in_the_call_target_to_be_declared_with_an_explicit_type_annotation);
77109 getTypeOfDottedName(node.expression, diagnostic);
77110 }
77111 }
77112 if (ts.isInJSFile(node)) {
77113 var jsSymbol = getSymbolOfExpando(node, /*allowDeclaration*/ false);
77114 if ((_a = jsSymbol === null || jsSymbol === void 0 ? void 0 : jsSymbol.exports) === null || _a === void 0 ? void 0 : _a.size) {
77115 var jsAssignmentType = createAnonymousType(jsSymbol, jsSymbol.exports, ts.emptyArray, ts.emptyArray, ts.emptyArray);
77116 jsAssignmentType.objectFlags |= 4096 /* ObjectFlags.JSLiteral */;
77117 return getIntersectionType([returnType, jsAssignmentType]);
77118 }
77119 }
77120 return returnType;
77121 }

Callers 1

checkExpressionWorkerFunction · 0.85

Calls 15

getResolvedSignatureFunction · 0.85
checkDeprecatedSignatureFunction · 0.85
isJSConstructorFunction · 0.85
isCommonJsRequireFunction · 0.85
getReturnTypeOfSignatureFunction · 0.85
isSymbolOrSymbolForCallFunction · 0.85
getEffectsSignatureFunction · 0.85
getTypeOfDottedNameFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…