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

Function ensureType

test/fixtures/snapshot/typescript.js:108462–108509  ·  view source on GitHub ↗
(node, type, ignorePrivate)

Source from the content-addressed store, hash-verified

108460 return undefined;
108461 }
108462 function ensureType(node, type, ignorePrivate) {
108463 if (!ignorePrivate && ts.hasEffectiveModifier(node, 8 /* ModifierFlags.Private */)) {
108464 // Private nodes emit no types (except private parameter properties, whose parameter types are actually visible)
108465 return;
108466 }
108467 if (shouldPrintWithInitializer(node)) {
108468 // Literal const declarations will have an initializer ensured rather than a type
108469 return;
108470 }
108471 var shouldUseResolverType = node.kind === 164 /* SyntaxKind.Parameter */ &&
108472 (resolver.isRequiredInitializedParameter(node) ||
108473 resolver.isOptionalUninitializedParameterProperty(node));
108474 if (type && !shouldUseResolverType) {
108475 return ts.visitNode(type, visitDeclarationSubtree);
108476 }
108477 if (!ts.getParseTreeNode(node)) {
108478 return type ? ts.visitNode(type, visitDeclarationSubtree) : factory.createKeywordTypeNode(130 /* SyntaxKind.AnyKeyword */);
108479 }
108480 if (node.kind === 173 /* SyntaxKind.SetAccessor */) {
108481 // Set accessors with no associated type node (from it's param or get accessor return) are `any` since they are never contextually typed right now
108482 // (The inferred type here will be void, but the old declaration emitter printed `any`, so this replicates that)
108483 return factory.createKeywordTypeNode(130 /* SyntaxKind.AnyKeyword */);
108484 }
108485 errorNameNode = node.name;
108486 var oldDiag;
108487 if (!suppressNewDiagnosticContexts) {
108488 oldDiag = getSymbolAccessibilityDiagnostic;
108489 getSymbolAccessibilityDiagnostic = ts.createGetSymbolAccessibilityDiagnosticForNode(node);
108490 }
108491 if (node.kind === 254 /* SyntaxKind.VariableDeclaration */ || node.kind === 203 /* SyntaxKind.BindingElement */) {
108492 return cleanup(resolver.createTypeOfDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, symbolTracker));
108493 }
108494 if (node.kind === 164 /* SyntaxKind.Parameter */
108495 || node.kind === 167 /* SyntaxKind.PropertyDeclaration */
108496 || node.kind === 166 /* SyntaxKind.PropertySignature */) {
108497 if (!node.initializer)
108498 return cleanup(resolver.createTypeOfDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, symbolTracker, shouldUseResolverType));
108499 return cleanup(resolver.createTypeOfDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, symbolTracker, shouldUseResolverType) || resolver.createTypeOfExpression(node.initializer, enclosingDeclaration, declarationEmitNodeBuilderFlags, symbolTracker));
108500 }
108501 return cleanup(resolver.createReturnTypeOfSignatureDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, symbolTracker));
108502 function cleanup(returnValue) {
108503 errorNameNode = undefined;
108504 if (!suppressNewDiagnosticContexts) {
108505 getSymbolAccessibilityDiagnostic = oldDiag;
108506 }
108507 return returnValue || factory.createKeywordTypeNode(130 /* SyntaxKind.AnyKeyword */);
108508 }
108509 }
108510 function isDeclarationAndNotVisible(node) {
108511 node = ts.getParseTreeNode(node);
108512 switch (node.kind) {

Callers 5

ensureParameterFunction · 0.85
visitDeclarationSubtreeFunction · 0.85
walkBindingPatternFunction · 0.85
recreateBindingElementFunction · 0.85

Calls 2

cleanupFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…