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

Function getFunctionOrClassName

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

Source from the content-addressed store, hash-verified

141524 return ts.getNodeModifiers(node);
141525 }
141526 function getFunctionOrClassName(node) {
141527 var parent = node.parent;
141528 if (node.name && ts.getFullWidth(node.name) > 0) {
141529 return cleanText(ts.declarationNameToString(node.name));
141530 }
141531 // See if it is a var initializer. If so, use the var name.
141532 else if (ts.isVariableDeclaration(parent)) {
141533 return cleanText(ts.declarationNameToString(parent.name));
141534 }
141535 // See if it is of the form "<expr> = function(){...}". If so, use the text from the left-hand side.
141536 else if (ts.isBinaryExpression(parent) && parent.operatorToken.kind === 63 /* SyntaxKind.EqualsToken */) {
141537 return nodeText(parent.left).replace(whiteSpaceRegex, "");
141538 }
141539 // See if it is a property assignment, and if so use the property name
141540 else if (ts.isPropertyAssignment(parent)) {
141541 return nodeText(parent.name);
141542 }
141543 // Default exports are named "default"
141544 else if (ts.getSyntacticModifierFlags(node) & 512 /* ModifierFlags.Default */) {
141545 return "default";
141546 }
141547 else if (ts.isClassLike(node)) {
141548 return "<class>";
141549 }
141550 else if (ts.isCallExpression(parent)) {
141551 var name = getCalledExpressionName(parent.expression);
141552 if (name !== undefined) {
141553 name = cleanText(name);
141554 if (name.length > maxLength) {
141555 return "".concat(name, " callback");
141556 }
141557 var args = cleanText(ts.mapDefined(parent.arguments, function (a) { return ts.isStringLiteralLike(a) ? a.getText(curSourceFile) : undefined; }).join(", "));
141558 return "".concat(name, "(").concat(args, ") callback");
141559 }
141560 }
141561 return "<function>";
141562 }
141563 // See also 'tryGetPropertyAccessOrIdentifierToString'
141564 function getCalledExpressionName(expr) {
141565 if (ts.isIdentifier(expr)) {

Callers 2

tryGetNameFunction · 0.85
getItemNameFunction · 0.85

Calls 5

cleanTextFunction · 0.85
nodeTextFunction · 0.85
getCalledExpressionNameFunction · 0.85
concatMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected