@@ -403,6 +403,9 @@ namespace ts.NavigationBar {
403
403
if ( getModifierFlags ( node ) & ModifierFlags . Default ) {
404
404
return "default" ;
405
405
}
406
+ // We may get a string with newlines or other whitespace in the case of an object dereference
407
+ // (eg: "app\n.onactivated"), so we should remove the whitespace for readabiltiy in the
408
+ // navigation bar.
406
409
return getFunctionOrClassName ( < ArrowFunction | FunctionExpression | ClassExpression > node ) ;
407
410
case SyntaxKind . Constructor :
408
411
return "constructor" ;
@@ -602,7 +605,7 @@ namespace ts.NavigationBar {
602
605
// See if it is of the form "<expr> = function(){...}". If so, use the text from the left-hand side.
603
606
else if ( node . parent . kind === SyntaxKind . BinaryExpression &&
604
607
( node . parent as BinaryExpression ) . operatorToken . kind === SyntaxKind . EqualsToken ) {
605
- return nodeText ( ( node . parent as BinaryExpression ) . left ) ;
608
+ return nodeText ( ( node . parent as BinaryExpression ) . left ) . replace ( whiteSpaceRegex , "" ) ;
606
609
}
607
610
// See if it is a property assignment, and if so use the property name
608
611
else if ( node . parent . kind === SyntaxKind . PropertyAssignment && ( node . parent as PropertyAssignment ) . name ) {
@@ -620,4 +623,19 @@ namespace ts.NavigationBar {
620
623
function isFunctionOrClassExpression ( node : Node ) : boolean {
621
624
return node . kind === SyntaxKind . FunctionExpression || node . kind === SyntaxKind . ArrowFunction || node . kind === SyntaxKind . ClassExpression ;
622
625
}
626
+
627
+ /**
628
+ * Matches all whitespace characters in a string. Eg:
629
+ *
630
+ * "app.
631
+ *
632
+ * onactivated"
633
+ *
634
+ * matches because of the newline, whereas
635
+ *
636
+ * "app.onactivated"
637
+ *
638
+ * does not match.
639
+ */
640
+ const whiteSpaceRegex = / \s + / g;
623
641
}
0 commit comments