Skip to content

Commit d8aafb3

Browse files
authored
Handle more child types when generating navigation tree items for export default (#62620)
1 parent d3be7e1 commit d8aafb3

File tree

4 files changed

+295
-4
lines changed

4 files changed

+295
-4
lines changed

src/services/navigationBar.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import {
5959
isBindingPattern,
6060
isCallExpression,
6161
isClassDeclaration,
62+
isClassExpression,
6263
isClassLike,
6364
isComputedPropertyName,
6465
isDeclaration,
@@ -104,6 +105,7 @@ import {
104105
removeFileExtension,
105106
setTextRange,
106107
ShorthandPropertyAssignment,
108+
skipOuterExpressions,
107109
SourceFile,
108110
SpreadAssignment,
109111
SyntaxKind,
@@ -444,8 +446,8 @@ function addChildrenRecursively(node: Node | undefined): void {
444446
break;
445447

446448
case SyntaxKind.ExportAssignment: {
447-
const expression = (node as ExportAssignment).expression;
448-
const child = isObjectLiteralExpression(expression) || isCallExpression(expression) ? expression :
449+
const expression = skipOuterExpressions((node as ExportAssignment).expression);
450+
const child = isObjectLiteralExpression(expression) || isCallExpression(expression) || isClassExpression(expression) ? expression :
449451
isArrowFunction(expression) || isFunctionExpression(expression) ? expression.body : undefined;
450452
if (child) {
451453
startNode(node);
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
//// export const foo = {
4+
//// foo: {},
5+
//// };
6+
////
7+
//// export default {
8+
//// foo: {},
9+
//// };
10+
////
11+
//// export default {
12+
//// foo: {},
13+
//// };
14+
////
15+
//// type Type = typeof foo;
16+
////
17+
//// export default {
18+
//// foo: {},
19+
//// } as Type;
20+
////
21+
//// export default {
22+
//// foo: {},
23+
//// } satisfies Type;
24+
////
25+
//// export default (class {
26+
//// prop = 42;
27+
//// });
28+
////
29+
//// export default (class Cls {
30+
//// prop = 42;
31+
//// });
32+
33+
verify.navigationTree({
34+
text: '"navigationItemsExportDefaultExpression2"',
35+
kind: "module",
36+
childItems: [
37+
{
38+
text: "default",
39+
kind: "const",
40+
kindModifiers: "export",
41+
childItems: [
42+
{
43+
text: "foo",
44+
kind: "property",
45+
},
46+
],
47+
},
48+
{
49+
text: "default",
50+
kind: "const",
51+
kindModifiers: "export",
52+
childItems: [
53+
{
54+
text: "foo",
55+
kind: "property",
56+
},
57+
],
58+
},
59+
{
60+
text: "default",
61+
kind: "const",
62+
kindModifiers: "export",
63+
childItems: [
64+
{
65+
text: "foo",
66+
kind: "property",
67+
},
68+
],
69+
},
70+
{
71+
text: "default",
72+
kind: "const",
73+
kindModifiers: "export",
74+
childItems: [
75+
{
76+
text: "foo",
77+
kind: "property",
78+
},
79+
],
80+
},
81+
{
82+
text: "default",
83+
kind: "const",
84+
kindModifiers: "export",
85+
childItems: [
86+
{
87+
text: "<class>",
88+
kind: "class",
89+
childItems: [
90+
{
91+
text: "prop",
92+
kind: "property",
93+
},
94+
],
95+
},
96+
],
97+
},
98+
{
99+
text: "default",
100+
kind: "const",
101+
kindModifiers: "export",
102+
childItems: [
103+
{
104+
text: "Cls",
105+
kind: "class",
106+
childItems: [
107+
{
108+
text: "prop",
109+
kind: "property",
110+
},
111+
],
112+
},
113+
],
114+
},
115+
{
116+
text: "foo",
117+
kind: "const",
118+
kindModifiers: "export",
119+
childItems: [
120+
{
121+
text: "foo",
122+
kind: "property",
123+
},
124+
],
125+
},
126+
{
127+
text: "Type",
128+
kind: "type",
129+
},
130+
],
131+
});

tests/cases/fourslash/navigationItemsExportEqualsExpression.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
//// d: 1
3030
//// }
3131
//// }
32+
////
33+
//// function foo(props: { x: number; y: number }) {}
34+
//// export = foo({ x: 1, y: 1 });
3235

3336
verify.navigationTree({
3437
"text": '"navigationItemsExportEqualsExpression"',
@@ -85,7 +88,13 @@ verify.navigationTree({
8588
{
8689
"text": "export=",
8790
"kind": "class",
88-
"kindModifiers": "export"
91+
"kindModifiers": "export",
92+
"childItems": [
93+
{
94+
"text": "AB",
95+
"kind": "class"
96+
}
97+
]
8998
},
9099
{
91100
"text": "export=",
@@ -112,6 +121,21 @@ verify.navigationTree({
112121
}
113122
]
114123
},
124+
{
125+
"text": "export=",
126+
"kind": "const",
127+
"kindModifiers": "export",
128+
"childItems": [
129+
{
130+
"text": "x",
131+
"kind": "property"
132+
},
133+
{
134+
"text": "y",
135+
"kind": "property"
136+
}
137+
]
138+
},
115139
{
116140
"text": "abc",
117141
"kind": "const"
@@ -120,7 +144,10 @@ verify.navigationTree({
120144
"text": "export=",
121145
"kind": "const",
122146
"kindModifiers": "export"
147+
},
148+
{
149+
"text": "foo",
150+
"kind": "function"
123151
}
124152
]
125153
});
126-
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
//// export const foo = {
4+
//// foo: {},
5+
//// };
6+
////
7+
//// export = {
8+
//// foo: {},
9+
//// };
10+
////
11+
//// export = {
12+
//// foo: {},
13+
//// };
14+
////
15+
//// type Type = typeof foo;
16+
////
17+
//// export = {
18+
//// foo: {},
19+
//// } as Type;
20+
////
21+
//// export = {
22+
//// foo: {},
23+
//// } satisfies Type;
24+
////
25+
//// export = (class {
26+
//// prop = 42;
27+
//// });
28+
////
29+
//// export = (class Cls {
30+
//// prop = 42;
31+
//// });
32+
33+
verify.navigationTree({
34+
text: '"navigationItemsExportEqualsExpression2"',
35+
kind: "module",
36+
childItems: [
37+
{
38+
text: "export=",
39+
kind: "const",
40+
kindModifiers: "export",
41+
childItems: [
42+
{
43+
text: "foo",
44+
kind: "property",
45+
},
46+
],
47+
},
48+
{
49+
text: "export=",
50+
kind: "const",
51+
kindModifiers: "export",
52+
childItems: [
53+
{
54+
text: "foo",
55+
kind: "property",
56+
},
57+
],
58+
},
59+
{
60+
text: "export=",
61+
kind: "const",
62+
kindModifiers: "export",
63+
childItems: [
64+
{
65+
text: "foo",
66+
kind: "property",
67+
},
68+
],
69+
},
70+
{
71+
text: "export=",
72+
kind: "const",
73+
kindModifiers: "export",
74+
childItems: [
75+
{
76+
text: "foo",
77+
kind: "property",
78+
},
79+
],
80+
},
81+
{
82+
text: "export=",
83+
kind: "const",
84+
kindModifiers: "export",
85+
childItems: [
86+
{
87+
text: "<class>",
88+
kind: "class",
89+
childItems: [
90+
{
91+
text: "prop",
92+
kind: "property",
93+
},
94+
],
95+
},
96+
],
97+
},
98+
{
99+
text: "export=",
100+
kind: "const",
101+
kindModifiers: "export",
102+
childItems: [
103+
{
104+
text: "Cls",
105+
kind: "class",
106+
childItems: [
107+
{
108+
text: "prop",
109+
kind: "property",
110+
},
111+
],
112+
},
113+
],
114+
},
115+
{
116+
text: "foo",
117+
kind: "const",
118+
kindModifiers: "export",
119+
childItems: [
120+
{
121+
text: "foo",
122+
kind: "property",
123+
},
124+
],
125+
},
126+
{
127+
text: "Type",
128+
kind: "type",
129+
},
130+
],
131+
});

0 commit comments

Comments
 (0)