All files ast-helpers.ts

72.72% Statements 8/11
90.62% Branches 29/32
100% Functions 0/0
70% Lines 7/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43      3586x                   157x   83x   4x       2x       1x                             76x    
import * as ts from 'typescript';
 
export function isFunctionLike(node: ts.Node): boolean {
  return ts.isFunctionDeclaration(node)
    || ts.isFunctionExpression(node)
    || ts.isArrowFunction(node)
    || ts.isMethodDeclaration(node)
    || ts.isConstructorDeclaration(node)
    || ts.isGetAccessor(node)
    || ts.isSetAccessor(node);
}
 
export function getFunctionName(node: ts.Node, sourceFile: ts.SourceFile): string {
  if ('name' in node && node.name && ts.isIdentifier(node.name as ts.Node)) return (node.name as ts.Identifier).getText(sourceFile);
 
  const parent = node.parent;
  if (parent && ts.isVariableDeclaration(parent) && parent.name && ts.isIdentifier(parent.name)) {
    return parent.name.getText(sourceFile);
  }
 
  if (parent && ts.isPropertyAssignment(parent) && ts.isIdentifier(parent.name)) {
    return parent.name.getText(sourceFile);
  }
 
  if (parent && ts.isPropertyDeclaration(parent) && parent.name && ts.isIdentifier(parent.name)) {
    return parent.name.getText(sourceFile);
  }
 
  if (parent && ts.isMethodDeclaration(parent) && parent.name) {
    return parent.name.getText(sourceFile);
  }
 
  if (parent && ts.isGetAccessor(parent) && parent.name) {
    return parent.name.getText(sourceFile);
  }
 
  if (parent && ts.isSetAccessor(parent) && parent.name) {
    return parent.name.getText(sourceFile);
  }
 
  return '<anonymous>';
}