fix(54266): Navtree doesn't return computed class members (#54271)

This commit is contained in:
Oleksandr T 2023-09-14 00:50:48 +03:00 committed by GitHub
parent 07bca994fa
commit 05fdb5f671
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 79 additions and 14 deletions

View File

@ -47,10 +47,8 @@ import {
getSyntacticModifierFlags,
getTextOfIdentifierOrLiteral,
getTextOfNode,
hasDynamicName,
hasJSDocNodes,
Identifier,
idText,
ImportClause,
InterfaceDeclaration,
InternalSymbolName,
@ -62,8 +60,10 @@ import {
isCallExpression,
isClassDeclaration,
isClassLike,
isComputedPropertyName,
isDeclaration,
isElementAccessExpression,
isEntityNameExpression,
isExportAssignment,
isExpression,
isExternalModule,
@ -73,6 +73,7 @@ import {
isJSDocTypeAlias,
isModuleBlock,
isModuleDeclaration,
isNumericLiteral,
isObjectLiteralExpression,
isParameterPropertyDeclaration,
isPrivateIdentifier,
@ -82,6 +83,7 @@ import {
isPropertyNameLiteral,
isStatic,
isStringLiteralLike,
isStringOrNumericLiteralLike,
isToken,
isVariableDeclaration,
lastOrUndefined,
@ -306,19 +308,15 @@ function addNodeWithRecursiveInitializer(node: VariableDeclaration | PropertyAss
}
}
/**
* Historically, we've elided dynamic names from the nav tree (including late bound names),
* but included certain "well known" symbol names. While we no longer distinguish those well-known
* symbols from other unique symbols, we do the below to retain those members in the nav tree.
*/
function hasNavigationBarName(node: Declaration) {
return !hasDynamicName(node) ||
(
node.kind !== SyntaxKind.BinaryExpression &&
isPropertyAccessExpression(node.name.expression) &&
isIdentifier(node.name.expression.expression) &&
idText(node.name.expression.expression) === "Symbol"
);
const name = getNameOfDeclaration(node);
if (name === undefined) return false;
if (isComputedPropertyName(name)) {
const expression = name.expression;
return isEntityNameExpression(expression) || isNumericLiteral(expression) || isStringOrNumericLiteralLike(expression);
}
return !!name;
}
/** Look for navigation bar items in node's subtree, adding them to the current `parent`. */

View File

@ -0,0 +1,67 @@
/// <reference path="fourslash.ts" />
////const enum E {
//// A = 'A',
////}
////const a = '';
////
////class C {
//// [a]() {
//// return 1;
//// }
////
//// [E.A]() {
//// return 1;
//// }
////
//// [1]() {
//// return 1;
//// },
////
//// ["foo"]() {
//// return 1;
//// },
////}
verify.navigationTree({
text: "<global>",
kind: "script",
childItems: [
{
text: "a",
kind: "const"
},
{
text: "C",
kind: "class",
childItems: [
{
text: "[a]",
kind: "method"
},
{
text: "[E.A]",
kind: "method"
},
{
text: "[1]",
kind: "method"
},
{
text: "[\"foo\"]",
kind: "method"
}
],
},
{
text: "E",
kind: "enum",
childItems: [
{
text: "A",
kind: "enum member"
},
]
}
]
});