From cb804df1510e346748638a1ae8e8d11519f55b7a Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Mon, 24 Oct 2016 17:53:03 -0700 Subject: [PATCH 1/5] remove whitespace --- src/services/navigationBar.ts | 21 +++++++++++- .../navigationBarItemsFunctionProperties.ts | 33 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/navigationBarItemsFunctionProperties.ts diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 7b4fb8cdba6..7ebefe7bdbd 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -377,6 +377,7 @@ namespace ts.NavigationBar { } function getItemName(node: Node): string { + if (node.kind === SyntaxKind.ModuleDeclaration) { return getModuleName(node); } @@ -403,7 +404,10 @@ namespace ts.NavigationBar { if (getModifierFlags(node) & ModifierFlags.Default) { return "default"; } - return getFunctionOrClassName(node); + // We ma 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).replace(whiteSpaceRegex, ""); case SyntaxKind.Constructor: return "constructor"; case SyntaxKind.ConstructSignature: @@ -620,4 +624,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|\t|\n|\r)+/g; } 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 From 82e8e4323695ff303b98687712fc0fc3392f280e Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Tue, 25 Oct 2016 10:38:41 -0700 Subject: [PATCH 2/5] only remove whitespace for expr assignment --- src/services/navigationBar.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 7ebefe7bdbd..f274810a323 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -404,10 +404,10 @@ namespace ts.NavigationBar { if (getModifierFlags(node) & ModifierFlags.Default) { return "default"; } - // We ma get a string with newlines or other whitespace in the case of an object dereference + // 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).replace(whiteSpaceRegex, ""); + return getFunctionOrClassName(node); case SyntaxKind.Constructor: return "constructor"; case SyntaxKind.ConstructSignature: @@ -606,11 +606,11 @@ 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) { - return nodeText((node.parent as PropertyAssignment).name); + return nodeText((node.parent as PropertyAssignment).name).replace(whiteSpaceRegex, "#"); } // Default exports are named "default" else if (getModifierFlags(node) & ModifierFlags.Default) { From 476b6e02c873675137094f946538207ce69a626d Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Tue, 25 Oct 2016 10:59:17 -0700 Subject: [PATCH 3/5] remove check on property assignment --- src/services/navigationBar.ts | 2 +- tests/cases/fourslash/indentationWithBaseIndent.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index f274810a323..3cdf7c38195 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -610,7 +610,7 @@ namespace ts.NavigationBar { } // 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) { - return nodeText((node.parent as PropertyAssignment).name).replace(whiteSpaceRegex, "#"); + return nodeText((node.parent as PropertyAssignment).name); } // Default exports are named "default" else if (getModifierFlags(node) & ModifierFlags.Default) { 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); }); From 77df58bdb630c85f1c928576c40d6b49dac8e777 Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Tue, 25 Oct 2016 11:03:54 -0700 Subject: [PATCH 4/5] simplify regex --- src/services/navigationBar.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 3cdf7c38195..10ed52858c7 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -638,5 +638,5 @@ namespace ts.NavigationBar { * * does not match. */ - const whiteSpaceRegex = /(\s|\t|\n|\r)+/g; + const whiteSpaceRegex = /\s+/g; } From 59cfa2eafe48346a1da4dd4673938f303b0132c4 Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Tue, 25 Oct 2016 11:06:04 -0700 Subject: [PATCH 5/5] remove whitespace --- src/services/navigationBar.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 10ed52858c7..51ce9b6001d 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -377,7 +377,6 @@ namespace ts.NavigationBar { } function getItemName(node: Node): string { - if (node.kind === SyntaxKind.ModuleDeclaration) { return getModuleName(node); }