Skip to content

Commit 9992395

Browse files
author
Andy
authored
Support arbitrary prototype property assignments in navigation bar (#19923)
1 parent 2f7ff67 commit 9992395

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

src/services/navigationBar.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,24 @@ namespace ts.NavigationBar {
269269
addLeafNode(node);
270270
break;
271271

272+
case SyntaxKind.BinaryExpression: {
273+
const special = getSpecialPropertyAssignmentKind(node as BinaryExpression);
274+
switch (special) {
275+
case SpecialPropertyAssignmentKind.ExportsProperty:
276+
case SpecialPropertyAssignmentKind.ModuleExports:
277+
case SpecialPropertyAssignmentKind.PrototypeProperty:
278+
addNodeWithRecursiveChild(node, (node as BinaryExpression).right);
279+
break;
280+
case SpecialPropertyAssignmentKind.ThisProperty:
281+
case SpecialPropertyAssignmentKind.Property:
282+
case SpecialPropertyAssignmentKind.None:
283+
break;
284+
default:
285+
Debug.assertNever(special);
286+
}
287+
}
288+
// falls through
289+
272290
default:
273291
if (hasJSDocNodes(node)) {
274292
forEach(node.jsDoc, jsDoc => {

src/services/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ namespace ts {
364364
const rightKind = getNodeKind(right);
365365
return rightKind === ScriptElementKind.unknown ? ScriptElementKind.constElement : rightKind;
366366
case SpecialPropertyAssignmentKind.PrototypeProperty:
367-
return ScriptElementKind.memberFunctionElement; // instance method
367+
return isFunctionExpression(right) ? ScriptElementKind.memberFunctionElement : ScriptElementKind.memberVariableElement;
368368
case SpecialPropertyAssignmentKind.ThisProperty:
369369
return ScriptElementKind.memberVariableElement; // property
370370
case SpecialPropertyAssignmentKind.Property:
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
// @Filename: foo.js
4+
////function f() {}
5+
////f.prototype.x = 0;
6+
7+
verify.navigationTree({
8+
"text": "<global>",
9+
"kind": "script",
10+
"childItems": [
11+
{
12+
"text": "f",
13+
"kind": "function"
14+
},
15+
{
16+
"text": "x",
17+
"kind": "property"
18+
}
19+
]
20+
});
21+
22+
verify.navigationBar([
23+
{
24+
"text": "<global>",
25+
"kind": "script",
26+
"childItems": [
27+
{
28+
"text": "f",
29+
"kind": "function"
30+
},
31+
{
32+
"text": "x",
33+
"kind": "property"
34+
}
35+
]
36+
},
37+
{
38+
"text": "f",
39+
"kind": "function",
40+
"indent": 1
41+
}
42+
]);

0 commit comments

Comments
 (0)