Skip to content

Commit d86d850

Browse files
author
Andy
authored
Merge pull request #13401 from Microsoft/navbar_exported_functions
Include "export" modifier on function assigned to an export (`export const x = () => 0;`).
2 parents b43cc6b + 2ae5806 commit d86d850

File tree

3 files changed

+87
-6
lines changed

3 files changed

+87
-6
lines changed

src/services/navigationBar.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ namespace ts.NavigationBar {
514514
return {
515515
text: getItemName(n.node),
516516
kind: getNodeKind(n.node),
517-
kindModifiers: getNodeModifiers(n.node),
517+
kindModifiers: getModifiers(n.node),
518518
spans: getSpans(n),
519519
childItems: map(n.children, convertToTree)
520520
};
@@ -524,7 +524,7 @@ namespace ts.NavigationBar {
524524
return {
525525
text: getItemName(n.node),
526526
kind: getNodeKind(n.node),
527-
kindModifiers: getNodeModifiers(n.node),
527+
kindModifiers: getModifiers(n.node),
528528
spans: getSpans(n),
529529
childItems: map(n.children, convertToChildItem) || emptyChildItemArray,
530530
indent: n.indent,
@@ -594,6 +594,13 @@ namespace ts.NavigationBar {
594594
: createTextSpanFromNode(node, curSourceFile);
595595
}
596596

597+
function getModifiers(node: ts.Node): string {
598+
if (node.parent && node.parent.kind === SyntaxKind.VariableDeclaration) {
599+
node = node.parent;
600+
}
601+
return getNodeModifiers(node);
602+
}
603+
597604
function getFunctionOrClassName(node: FunctionExpression | FunctionDeclaration | ArrowFunction | ClassLikeDeclaration): string {
598605
if (node.name && getFullWidth(node.name) > 0) {
599606
return declarationNameToString(node.name);

tests/cases/fourslash/navigationBarItemsFunctionProperties.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
//// .a = function() { };
77
//// })();
88

9-
function navExact(name: string, kind: string) {
10-
return;
11-
}
12-
139
verify.navigationTree(
1410
{
1511
"text": "<global>",
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////export const value = 2;
4+
////export const func = () => 2;
5+
////export const func2 = function() { };
6+
////export function exportedFunction() { }
7+
8+
verify.navigationBar([
9+
{
10+
"text": "\"navigationBarItemsNamedArrowFunctions\"",
11+
"kind": "module",
12+
"childItems": [
13+
{
14+
"text": "exportedFunction",
15+
"kind": "function",
16+
"kindModifiers": "export"
17+
},
18+
{
19+
"text": "func",
20+
"kind": "function"
21+
},
22+
{
23+
"text": "func2",
24+
"kind": "function"
25+
},
26+
{
27+
"text": "value",
28+
"kind": "const",
29+
"kindModifiers": "export"
30+
}
31+
]
32+
},
33+
{
34+
"text": "exportedFunction",
35+
"kind": "function",
36+
"kindModifiers": "export",
37+
"indent": 1
38+
},
39+
{
40+
"text": "func",
41+
"kind": "function",
42+
"kindModifiers": "export",
43+
"indent": 1
44+
},
45+
{
46+
"text": "func2",
47+
"kind": "function",
48+
"kindModifiers": "export",
49+
"indent": 1
50+
}
51+
]);
52+
53+
verify.navigationTree({
54+
"text": "\"navigationBarItemsNamedArrowFunctions\"",
55+
"kind": "module",
56+
"childItems": [
57+
{
58+
"text": "exportedFunction",
59+
"kind": "function",
60+
"kindModifiers": "export"
61+
},
62+
{
63+
"text": "func",
64+
"kind": "function",
65+
"kindModifiers": "export"
66+
},
67+
{
68+
"text": "func2",
69+
"kind": "function",
70+
"kindModifiers": "export"
71+
},
72+
{
73+
"text": "value",
74+
"kind": "const",
75+
"kindModifiers": "export"
76+
}
77+
]
78+
});

0 commit comments

Comments
 (0)