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

Function tryGetThisTypeAt

test/fixtures/snapshot/typescript.js:71998–72043  ·  view source on GitHub ↗
(node, includeGlobalThis, container)

Source from the content-addressed store, hash-verified

71996 return type || anyType;
71997 }
71998 function tryGetThisTypeAt(node, includeGlobalThis, container) {
71999 if (includeGlobalThis === void 0) { includeGlobalThis = true; }
72000 if (container === void 0) { container = ts.getThisContainer(node, /*includeArrowFunctions*/ false); }
72001 var isInJS = ts.isInJSFile(node);
72002 if (ts.isFunctionLike(container) &&
72003 (!isInParameterInitializerBeforeContainingFunction(node) || ts.getThisParameter(container))) {
72004 var thisType = getThisTypeOfDeclaration(container) || isInJS && getTypeForThisExpressionFromJSDoc(container);
72005 // Note: a parameter initializer should refer to class-this unless function-this is explicitly annotated.
72006 // If this is a function in a JS file, it might be a class method.
72007 if (!thisType) {
72008 var className = getClassNameFromPrototypeMethod(container);
72009 if (isInJS && className) {
72010 var classSymbol = checkExpression(className).symbol;
72011 if (classSymbol && classSymbol.members && (classSymbol.flags & 16 /* SymbolFlags.Function */)) {
72012 thisType = getDeclaredTypeOfSymbol(classSymbol).thisType;
72013 }
72014 }
72015 else if (isJSConstructor(container)) {
72016 thisType = getDeclaredTypeOfSymbol(getMergedSymbol(container.symbol)).thisType;
72017 }
72018 thisType || (thisType = getContextualThisParameterType(container));
72019 }
72020 if (thisType) {
72021 return getFlowTypeOfReference(node, thisType);
72022 }
72023 }
72024 if (ts.isClassLike(container.parent)) {
72025 var symbol = getSymbolOfNode(container.parent);
72026 var type = ts.isStatic(container) ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol).thisType;
72027 return getFlowTypeOfReference(node, type);
72028 }
72029 if (ts.isSourceFile(container)) {
72030 // look up in the source file's locals or exports
72031 if (container.commonJsModuleIndicator) {
72032 var fileSymbol = getSymbolOfNode(container);
72033 return fileSymbol && getTypeOfSymbol(fileSymbol);
72034 }
72035 else if (container.externalModuleIndicator) {
72036 // TODO: Maybe issue a better error than 'object is possibly undefined'
72037 return undefinedType;
72038 }
72039 else if (includeGlobalThis) {
72040 return getTypeOfSymbol(globalThisSymbol);
72041 }
72042 }
72043 }
72044 function getExplicitThisType(node) {
72045 var container = ts.getThisContainer(node, /*includeArrowFunctions*/ false);
72046 if (ts.isFunctionLike(container)) {

Callers 2

createTypeCheckerFunction · 0.85
checkThisExpressionFunction · 0.85

Calls 12

getThisTypeOfDeclarationFunction · 0.85
getDeclaredTypeOfSymbolFunction · 0.85
isJSConstructorFunction · 0.85
getMergedSymbolFunction · 0.85
getFlowTypeOfReferenceFunction · 0.85
getSymbolOfNodeFunction · 0.85
getTypeOfSymbolFunction · 0.85
checkExpressionFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…