mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
fix(54266): Navtree doesn't return computed class members (#54271)
This commit is contained in:
parent
07bca994fa
commit
05fdb5f671
@ -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`. */
|
||||
|
||||
67
tests/cases/fourslash/navigationBarItemsComputedNames.ts
Normal file
67
tests/cases/fourslash/navigationBarItemsComputedNames.ts
Normal 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"
|
||||
},
|
||||
]
|
||||
}
|
||||
]
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user