@@ -631,28 +631,50 @@ namespace ts.NavigationBar {
631
631
}
632
632
633
633
function getFunctionOrClassName ( node : FunctionExpression | FunctionDeclaration | ArrowFunction | ClassLikeDeclaration ) : string {
634
+ const { parent } = node ;
634
635
if ( node . name && getFullWidth ( node . name ) > 0 ) {
635
636
return declarationNameToString ( node . name ) ;
636
637
}
637
638
// See if it is a var initializer. If so, use the var name.
638
- else if ( node . parent . kind === SyntaxKind . VariableDeclaration ) {
639
- return declarationNameToString ( ( node . parent as VariableDeclaration ) . name ) ;
639
+ else if ( isVariableDeclaration ( parent ) ) {
640
+ return declarationNameToString ( parent . name ) ;
640
641
}
641
642
// See if it is of the form "<expr> = function(){...}". If so, use the text from the left-hand side.
642
- else if ( node . parent . kind === SyntaxKind . BinaryExpression &&
643
- ( node . parent as BinaryExpression ) . operatorToken . kind === SyntaxKind . EqualsToken ) {
644
- return nodeText ( ( node . parent as BinaryExpression ) . left ) . replace ( whiteSpaceRegex , "" ) ;
643
+ else if ( isBinaryExpression ( parent ) && parent . operatorToken . kind === SyntaxKind . EqualsToken ) {
644
+ return nodeText ( parent . left ) . replace ( whiteSpaceRegex , "" ) ;
645
645
}
646
646
// See if it is a property assignment, and if so use the property name
647
- else if ( node . parent . kind === SyntaxKind . PropertyAssignment && ( node . parent as PropertyAssignment ) . name ) {
648
- return nodeText ( ( node . parent as PropertyAssignment ) . name ) ;
647
+ else if ( isPropertyAssignment ( parent ) ) {
648
+ return nodeText ( parent . name ) ;
649
649
}
650
650
// Default exports are named "default"
651
651
else if ( getModifierFlags ( node ) & ModifierFlags . Default ) {
652
652
return "default" ;
653
653
}
654
+ else if ( isClassLike ( node ) ) {
655
+ return "<class>" ;
656
+ }
657
+ else if ( isCallExpression ( parent ) ) {
658
+ const name = getCalledExpressionName ( parent . expression ) ;
659
+ if ( name !== undefined ) {
660
+ const args = mapDefined ( parent . arguments , a => isStringLiteral ( a ) ? a . getText ( curSourceFile ) : undefined ) . join ( ", " ) ;
661
+ return `${ name } (${ args } ) callback` ;
662
+ }
663
+ }
664
+ return "<function>" ;
665
+ }
666
+
667
+ function getCalledExpressionName ( expr : Expression ) : string | undefined {
668
+ if ( isIdentifier ( expr ) ) {
669
+ return expr . text ;
670
+ }
671
+ else if ( isPropertyAccessExpression ( expr ) ) {
672
+ const left = getCalledExpressionName ( expr . expression ) ;
673
+ const right = expr . name . text ;
674
+ return left === undefined ? right : `${ left } .${ right } ` ;
675
+ }
654
676
else {
655
- return isClassLike ( node ) ? "<class>" : "<function>" ;
677
+ return undefined ;
656
678
}
657
679
}
658
680
0 commit comments