Skip to content

Commit 59f8097

Browse files
authored
fix(38785): include in NavigationBar child items from default exported functions (microsoft#38915)
1 parent 535914c commit 59f8097

File tree

3 files changed

+115
-5
lines changed

3 files changed

+115
-5
lines changed

src/services/navigationBar.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,11 @@ namespace ts.NavigationBar {
310310

311311
case SyntaxKind.ExportAssignment: {
312312
const expression = (<ExportAssignment>node).expression;
313-
if (isObjectLiteralExpression(expression)) {
313+
const child = isObjectLiteralExpression(expression) ? expression :
314+
isArrowFunction(expression) || isFunctionExpression(expression) ? expression.body : undefined;
315+
if (child) {
314316
startNode(node);
315-
addChildrenRecursively(expression);
317+
addChildrenRecursively(child);
316318
endNode();
317319
}
318320
else {

tests/cases/fourslash/navigationItemsExportDefaultExpression.ts

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
/// <reference path="fourslash.ts"/>
22

3-
//// const abc = 12;
43
//// export default function () {}
4+
//// export default function () {
5+
//// return class Foo {
6+
//// }
7+
//// }
8+
////
59
//// export default () => ""
10+
//// export default () => {
11+
//// return class Foo {
12+
//// }
13+
//// }
14+
////
15+
//// export default function f1() {}
16+
//// export default function f2() {
17+
//// return class Foo {
18+
//// }
19+
//// }
20+
////
21+
//// const abc = 12;
622
//// export default abc;
723
//// export default class AB {}
824
//// export default {
@@ -22,11 +38,33 @@ verify.navigationTree({
2238
"kind": "function",
2339
"kindModifiers": "export"
2440
},
41+
{
42+
"text": "default",
43+
"kind": "function",
44+
"kindModifiers": "export",
45+
"childItems": [
46+
{
47+
"text": "Foo",
48+
"kind": "class"
49+
}
50+
]
51+
},
2552
{
2653
"text": "default",
2754
"kind": "function",
2855
"kindModifiers": "export"
2956
},
57+
{
58+
"text": "default",
59+
"kind": "function",
60+
"kindModifiers": "export",
61+
"childItems": [
62+
{
63+
"text": "Foo",
64+
"kind": "class"
65+
}
66+
]
67+
},
3068
{
3169
"text": "default",
3270
"kind": "const",
@@ -65,6 +103,22 @@ verify.navigationTree({
65103
"text": "default",
66104
"kind": "const",
67105
"kindModifiers": "export"
106+
},
107+
{
108+
"text": "f1",
109+
"kind": "function",
110+
"kindModifiers": "export"
111+
},
112+
{
113+
"text": "f2",
114+
"kind": "function",
115+
"kindModifiers": "export",
116+
"childItems": [
117+
{
118+
"text": "Foo",
119+
"kind": "class"
120+
}
121+
]
68122
}
69123
]
70124
});

tests/cases/fourslash/navigationItemsExportEqualsExpression.ts

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
// 35477
22
/// <reference path="fourslash.ts"/>
33

4-
//// const abc = 12;
5-
//// export = abc;
64
//// export = function () {}
5+
//// export = function () {
6+
//// return class Foo {
7+
//// }
8+
//// }
9+
////
710
//// export = () => ""
11+
//// export = () => {
12+
//// return class Foo {
13+
//// }
14+
//// }
15+
////
16+
//// export = function f1() {}
17+
//// export = function f2() {
18+
//// return class Foo {
19+
//// }
20+
//// }
21+
////
22+
//// const abc = 12;
23+
//// export = abc;
824
//// export = class AB {}
925
//// export = {
1026
//// a: 1,
@@ -23,11 +39,49 @@ verify.navigationTree({
2339
"kind": "function",
2440
"kindModifiers": "export"
2541
},
42+
{
43+
"text": "export=",
44+
"kind": "function",
45+
"kindModifiers": "export",
46+
"childItems": [
47+
{
48+
"text": "Foo",
49+
"kind": "class"
50+
}
51+
]
52+
},
53+
{
54+
"text": "export=",
55+
"kind": "function",
56+
"kindModifiers": "export"
57+
},
58+
{
59+
"text": "export=",
60+
"kind": "function",
61+
"kindModifiers": "export",
62+
"childItems": [
63+
{
64+
"text": "Foo",
65+
"kind": "class"
66+
}
67+
]
68+
},
2669
{
2770
"text": "export=",
2871
"kind": "function",
2972
"kindModifiers": "export"
3073
},
74+
{
75+
"text": "export=",
76+
"kind": "function",
77+
"kindModifiers": "export",
78+
"childItems": [
79+
{
80+
"text": "Foo",
81+
"kind": "class"
82+
}
83+
]
84+
},
3185
{
3286
"text": "export=",
3387
"kind": "class",

0 commit comments

Comments
 (0)