diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 7b4fb8cdba6..51ce9b6001d 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -403,6 +403,9 @@ namespace ts.NavigationBar { if (getModifierFlags(node) & ModifierFlags.Default) { return "default"; } + // We may get a string with newlines or other whitespace in the case of an object dereference + // (eg: "app\n.onactivated"), so we should remove the whitespace for readabiltiy in the + // navigation bar. return getFunctionOrClassName(node); case SyntaxKind.Constructor: return "constructor"; @@ -602,7 +605,7 @@ namespace ts.NavigationBar { // See if it is of the form " = function(){...}". If so, use the text from the left-hand side. else if (node.parent.kind === SyntaxKind.BinaryExpression && (node.parent as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken) { - return nodeText((node.parent as BinaryExpression).left); + return nodeText((node.parent as BinaryExpression).left).replace(whiteSpaceRegex, ""); } // See if it is a property assignment, and if so use the property name else if (node.parent.kind === SyntaxKind.PropertyAssignment && (node.parent as PropertyAssignment).name) { @@ -620,4 +623,19 @@ namespace ts.NavigationBar { function isFunctionOrClassExpression(node: Node): boolean { return node.kind === SyntaxKind.FunctionExpression || node.kind === SyntaxKind.ArrowFunction || node.kind === SyntaxKind.ClassExpression; } + + /** + * Matches all whitespace characters in a string. Eg: + * + * "app. + * + * onactivated" + * + * matches because of the newline, whereas + * + * "app.onactivated" + * + * does not match. + */ + const whiteSpaceRegex = /\s+/g; } diff --git a/tests/cases/fourslash/indentationWithBaseIndent.ts b/tests/cases/fourslash/indentationWithBaseIndent.ts index 53ee01c9a3c..112ce225d01 100644 --- a/tests/cases/fourslash/indentationWithBaseIndent.ts +++ b/tests/cases/fourslash/indentationWithBaseIndent.ts @@ -205,7 +205,6 @@ //// function unterminatedListIndentation(a, ////{| "indent": 14 , "baseIndentSize": 10 |} -debugger; test.markers().forEach(marker => { verify.indentationAtPositionIs(marker.fileName, marker.position, marker.data.indent, ts.IndentStyle.Smart, marker.data.baseIndentSize); }); diff --git a/tests/cases/fourslash/navigationBarItemsFunctionProperties.ts b/tests/cases/fourslash/navigationBarItemsFunctionProperties.ts new file mode 100644 index 00000000000..75c20736b41 --- /dev/null +++ b/tests/cases/fourslash/navigationBarItemsFunctionProperties.ts @@ -0,0 +1,33 @@ +/// + +//// (function(){ +//// var A; +//// A/*1*/ +//// .a = function() { }; +//// })(); + +function navExact(name: string, kind: string) { + return; +} + +verify.navigationTree( +{ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "", + "kind": "function", + "childItems": [ + { + "text": "A", + "kind": "var" + }, + { + "text": "A.a", + "kind": "function" + } + ] + } + ] +}); \ No newline at end of file