MCPcopy Create free account
hub / github.com/nodejs/node / addImplementationReferences

Function addImplementationReferences

test/fixtures/snapshot/typescript.js:138440–138487  ·  view source on GitHub ↗
(refNode, addReference, state)

Source from the content-addressed store, hash-verified

138438 getReferencesInContainerOrFiles(classSymbol, state, search);
138439 }
138440 function addImplementationReferences(refNode, addReference, state) {
138441 // Check if we found a function/propertyAssignment/method with an implementation or initializer
138442 if (ts.isDeclarationName(refNode) && isImplementation(refNode.parent)) {
138443 addReference(refNode);
138444 return;
138445 }
138446 if (refNode.kind !== 79 /* SyntaxKind.Identifier */) {
138447 return;
138448 }
138449 if (refNode.parent.kind === 297 /* SyntaxKind.ShorthandPropertyAssignment */) {
138450 // Go ahead and dereference the shorthand assignment by going to its definition
138451 getReferenceEntriesForShorthandPropertyAssignment(refNode, state.checker, addReference);
138452 }
138453 // Check if the node is within an extends or implements clause
138454 var containingClass = getContainingClassIfInHeritageClause(refNode);
138455 if (containingClass) {
138456 addReference(containingClass);
138457 return;
138458 }
138459 // If we got a type reference, try and see if the reference applies to any expressions that can implement an interface
138460 // Find the first node whose parent isn't a type node -- i.e., the highest type node.
138461 var typeNode = ts.findAncestor(refNode, function (a) { return !ts.isQualifiedName(a.parent) && !ts.isTypeNode(a.parent) && !ts.isTypeElement(a.parent); });
138462 var typeHavingNode = typeNode.parent;
138463 if (ts.hasType(typeHavingNode) && typeHavingNode.type === typeNode && state.markSeenContainingTypeReference(typeHavingNode)) {
138464 if (ts.hasInitializer(typeHavingNode)) {
138465 addIfImplementation(typeHavingNode.initializer);
138466 }
138467 else if (ts.isFunctionLike(typeHavingNode) && typeHavingNode.body) {
138468 var body = typeHavingNode.body;
138469 if (body.kind === 235 /* SyntaxKind.Block */) {
138470 ts.forEachReturnStatement(body, function (returnStatement) {
138471 if (returnStatement.expression)
138472 addIfImplementation(returnStatement.expression);
138473 });
138474 }
138475 else {
138476 addIfImplementation(body);
138477 }
138478 }
138479 else if (ts.isAssertionExpression(typeHavingNode)) {
138480 addIfImplementation(typeHavingNode.expression);
138481 }
138482 }
138483 function addIfImplementation(e) {
138484 if (isImplementationExpression(e))
138485 addReference(e);
138486 }
138487 }
138488 function getContainingClassIfInHeritageClause(node) {
138489 return ts.isIdentifier(node) || ts.isPropertyAccessExpression(node) ? getContainingClassIfInHeritageClause(node.parent)
138490 : ts.isExpressionWithTypeArguments(node) ? ts.tryCast(node.parent.parent, ts.isClassLike) : undefined;

Callers 1

addReferenceFunction · 0.85

Tested by

no test coverage detected