From 7862e58354888d5ccf9c378ac74863d5febabc21 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Mon, 21 Oct 2019 17:41:06 -0700 Subject: [PATCH] Handle undefined from getPropertyNameForPropertyNameNode ...which can be returned when the property name is computed. Part of #34404 --- src/services/navigationBar.ts | 3 +- .../navigationBarComputedPropertyName.ts | 57 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/navigationBarComputedPropertyName.ts diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 03b9d6216c874..49310ef827f1e 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -648,7 +648,8 @@ namespace ts.NavigationBar { const declName = getNameOfDeclaration(node); if (declName && isPropertyName(declName)) { - return unescapeLeadingUnderscores(getPropertyNameForPropertyNameNode(declName)!); // TODO: GH#18217 + const propertyName = getPropertyNameForPropertyNameNode(declName); + return propertyName && unescapeLeadingUnderscores(propertyName); } switch (node.kind) { case SyntaxKind.FunctionExpression: diff --git a/tests/cases/fourslash/navigationBarComputedPropertyName.ts b/tests/cases/fourslash/navigationBarComputedPropertyName.ts new file mode 100644 index 0000000000000..fc6fb808f74fe --- /dev/null +++ b/tests/cases/fourslash/navigationBarComputedPropertyName.ts @@ -0,0 +1,57 @@ +/// + +////function F(key, value) { +//// return { +//// [key]: value, +//// "prop": true +//// } +////} + +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "F", + "kind": "function", + "childItems": [ + { + "text": "[key]", + "kind": "property" + }, + { + "text": "\"prop\"", + "kind": "property" + } + ] + } + ] +}); + +verify.navigationBar([ + { + "text": "", + "kind": "script", + "childItems": [ + { + "text": "F", + "kind": "function" + } + ] + }, + { + "text": "F", + "kind": "function", + "childItems": [ + { + "text": "[key]", + "kind": "property" + }, + { + "text": "\"prop\"", + "kind": "property" + } + ], + "indent": 1 + } +]);