Skip to content

Commit 05fdb5f

Browse files
authored
fix(54266): Navtree doesn't return computed class members (#54271)
1 parent 07bca99 commit 05fdb5f

File tree

2 files changed

+79
-14
lines changed

2 files changed

+79
-14
lines changed

src/services/navigationBar.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,8 @@ import {
4747
getSyntacticModifierFlags,
4848
getTextOfIdentifierOrLiteral,
4949
getTextOfNode,
50-
hasDynamicName,
5150
hasJSDocNodes,
5251
Identifier,
53-
idText,
5452
ImportClause,
5553
InterfaceDeclaration,
5654
InternalSymbolName,
@@ -62,8 +60,10 @@ import {
6260
isCallExpression,
6361
isClassDeclaration,
6462
isClassLike,
63+
isComputedPropertyName,
6564
isDeclaration,
6665
isElementAccessExpression,
66+
isEntityNameExpression,
6767
isExportAssignment,
6868
isExpression,
6969
isExternalModule,
@@ -73,6 +73,7 @@ import {
7373
isJSDocTypeAlias,
7474
isModuleBlock,
7575
isModuleDeclaration,
76+
isNumericLiteral,
7677
isObjectLiteralExpression,
7778
isParameterPropertyDeclaration,
7879
isPrivateIdentifier,
@@ -82,6 +83,7 @@ import {
8283
isPropertyNameLiteral,
8384
isStatic,
8485
isStringLiteralLike,
86+
isStringOrNumericLiteralLike,
8587
isToken,
8688
isVariableDeclaration,
8789
lastOrUndefined,
@@ -306,19 +308,15 @@ function addNodeWithRecursiveInitializer(node: VariableDeclaration | PropertyAss
306308
}
307309
}
308310

309-
/**
310-
* Historically, we've elided dynamic names from the nav tree (including late bound names),
311-
* but included certain "well known" symbol names. While we no longer distinguish those well-known
312-
* symbols from other unique symbols, we do the below to retain those members in the nav tree.
313-
*/
314311
function hasNavigationBarName(node: Declaration) {
315-
return !hasDynamicName(node) ||
316-
(
317-
node.kind !== SyntaxKind.BinaryExpression &&
318-
isPropertyAccessExpression(node.name.expression) &&
319-
isIdentifier(node.name.expression.expression) &&
320-
idText(node.name.expression.expression) === "Symbol"
321-
);
312+
const name = getNameOfDeclaration(node);
313+
if (name === undefined) return false;
314+
315+
if (isComputedPropertyName(name)) {
316+
const expression = name.expression;
317+
return isEntityNameExpression(expression) || isNumericLiteral(expression) || isStringOrNumericLiteralLike(expression);
318+
}
319+
return !!name;
322320
}
323321

324322
/** Look for navigation bar items in node's subtree, adding them to the current `parent`. */
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////const enum E {
4+
//// A = 'A',
5+
////}
6+
////const a = '';
7+
////
8+
////class C {
9+
//// [a]() {
10+
//// return 1;
11+
//// }
12+
////
13+
//// [E.A]() {
14+
//// return 1;
15+
//// }
16+
////
17+
//// [1]() {
18+
//// return 1;
19+
//// },
20+
////
21+
//// ["foo"]() {
22+
//// return 1;
23+
//// },
24+
////}
25+
26+
verify.navigationTree({
27+
text: "<global>",
28+
kind: "script",
29+
childItems: [
30+
{
31+
text: "a",
32+
kind: "const"
33+
},
34+
{
35+
text: "C",
36+
kind: "class",
37+
childItems: [
38+
{
39+
text: "[a]",
40+
kind: "method"
41+
},
42+
{
43+
text: "[E.A]",
44+
kind: "method"
45+
},
46+
{
47+
text: "[1]",
48+
kind: "method"
49+
},
50+
{
51+
text: "[\"foo\"]",
52+
kind: "method"
53+
}
54+
],
55+
},
56+
{
57+
text: "E",
58+
kind: "enum",
59+
childItems: [
60+
{
61+
text: "A",
62+
kind: "enum member"
63+
},
64+
]
65+
}
66+
]
67+
});

0 commit comments

Comments
 (0)