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

Function checkSignatureDeclaration

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

Source from the content-addressed store, hash-verified

80173 }
80174 }
80175 function checkSignatureDeclaration(node) {
80176 // Grammar checking
80177 if (node.kind === 176 /* SyntaxKind.IndexSignature */) {
80178 checkGrammarIndexSignature(node);
80179 }
80180 // TODO (yuisu): Remove this check in else-if when SyntaxKind.Construct is moved and ambient context is handled
80181 else if (node.kind === 179 /* SyntaxKind.FunctionType */ || node.kind === 256 /* SyntaxKind.FunctionDeclaration */ || node.kind === 180 /* SyntaxKind.ConstructorType */ ||
80182 node.kind === 174 /* SyntaxKind.CallSignature */ || node.kind === 171 /* SyntaxKind.Constructor */ ||
80183 node.kind === 175 /* SyntaxKind.ConstructSignature */) {
80184 checkGrammarFunctionLikeDeclaration(node);
80185 }
80186 var functionFlags = ts.getFunctionFlags(node);
80187 if (!(functionFlags & 4 /* FunctionFlags.Invalid */)) {
80188 // Async generators prior to ESNext require the __await and __asyncGenerator helpers
80189 if ((functionFlags & 3 /* FunctionFlags.AsyncGenerator */) === 3 /* FunctionFlags.AsyncGenerator */ && languageVersion < 99 /* ScriptTarget.ESNext */) {
80190 checkExternalEmitHelpers(node, 6144 /* ExternalEmitHelpers.AsyncGeneratorIncludes */);
80191 }
80192 // Async functions prior to ES2017 require the __awaiter helper
80193 if ((functionFlags & 3 /* FunctionFlags.AsyncGenerator */) === 2 /* FunctionFlags.Async */ && languageVersion < 4 /* ScriptTarget.ES2017 */) {
80194 checkExternalEmitHelpers(node, 64 /* ExternalEmitHelpers.Awaiter */);
80195 }
80196 // Generator functions, Async functions, and Async Generator functions prior to
80197 // ES2015 require the __generator helper
80198 if ((functionFlags & 3 /* FunctionFlags.AsyncGenerator */) !== 0 /* FunctionFlags.Normal */ && languageVersion < 2 /* ScriptTarget.ES2015 */) {
80199 checkExternalEmitHelpers(node, 128 /* ExternalEmitHelpers.Generator */);
80200 }
80201 }
80202 checkTypeParameters(ts.getEffectiveTypeParameterDeclarations(node));
80203 checkUnmatchedJSDocParameters(node);
80204 ts.forEach(node.parameters, checkParameter);
80205 // TODO(rbuckton): Should we start checking JSDoc types?
80206 if (node.type) {
80207 checkSourceElement(node.type);
80208 }
80209 addLazyDiagnostic(checkSignatureDeclarationDiagnostics);
80210 function checkSignatureDeclarationDiagnostics() {
80211 checkCollisionWithArgumentsInGeneratedCode(node);
80212 var returnTypeNode = ts.getEffectiveReturnTypeNode(node);
80213 if (noImplicitAny && !returnTypeNode) {
80214 switch (node.kind) {
80215 case 175 /* SyntaxKind.ConstructSignature */:
80216 error(node, ts.Diagnostics.Construct_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type);
80217 break;
80218 case 174 /* SyntaxKind.CallSignature */:
80219 error(node, ts.Diagnostics.Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type);
80220 break;
80221 }
80222 }
80223 if (returnTypeNode) {
80224 var functionFlags_1 = ts.getFunctionFlags(node);
80225 if ((functionFlags_1 & (4 /* FunctionFlags.Invalid */ | 1 /* FunctionFlags.Generator */)) === 1 /* FunctionFlags.Generator */) {
80226 var returnType = getTypeFromTypeNode(returnTypeNode);
80227 if (returnType === voidType) {
80228 error(returnTypeNode, ts.Diagnostics.A_generator_cannot_have_a_void_type_annotation);
80229 }
80230 else {
80231 // Naively, one could check that Generator<any, any, any> is assignable to the return type annotation.
80232 // However, that would not catch the error in the following case.

Calls 8

checkExternalEmitHelpersFunction · 0.85
checkTypeParametersFunction · 0.85
checkSourceElementFunction · 0.85
addLazyDiagnosticFunction · 0.85
forEachMethod · 0.65

Tested by

no test coverage detected