Handle more child types when generating navigation tree items for export default (#62620)

This commit is contained in:
Mateusz Burzyński 2025-10-17 18:44:34 +02:00 committed by GitHub
parent d3be7e171b
commit d8aafb3197
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 295 additions and 4 deletions

View File

@ -59,6 +59,7 @@ import {
isBindingPattern,
isCallExpression,
isClassDeclaration,
isClassExpression,
isClassLike,
isComputedPropertyName,
isDeclaration,
@ -104,6 +105,7 @@ import {
removeFileExtension,
setTextRange,
ShorthandPropertyAssignment,
skipOuterExpressions,
SourceFile,
SpreadAssignment,
SyntaxKind,
@ -444,8 +446,8 @@ function addChildrenRecursively(node: Node | undefined): void {
break;
case SyntaxKind.ExportAssignment: {
const expression = (node as ExportAssignment).expression;
const child = isObjectLiteralExpression(expression) || isCallExpression(expression) ? expression :
const expression = skipOuterExpressions((node as ExportAssignment).expression);
const child = isObjectLiteralExpression(expression) || isCallExpression(expression) || isClassExpression(expression) ? expression :
isArrowFunction(expression) || isFunctionExpression(expression) ? expression.body : undefined;
if (child) {
startNode(node);

View File

@ -0,0 +1,131 @@
/// <reference path="fourslash.ts"/>
//// export const foo = {
//// foo: {},
//// };
////
//// export default {
//// foo: {},
//// };
////
//// export default {
//// foo: {},
//// };
////
//// type Type = typeof foo;
////
//// export default {
//// foo: {},
//// } as Type;
////
//// export default {
//// foo: {},
//// } satisfies Type;
////
//// export default (class {
//// prop = 42;
//// });
////
//// export default (class Cls {
//// prop = 42;
//// });
verify.navigationTree({
text: '"navigationItemsExportDefaultExpression2"',
kind: "module",
childItems: [
{
text: "default",
kind: "const",
kindModifiers: "export",
childItems: [
{
text: "foo",
kind: "property",
},
],
},
{
text: "default",
kind: "const",
kindModifiers: "export",
childItems: [
{
text: "foo",
kind: "property",
},
],
},
{
text: "default",
kind: "const",
kindModifiers: "export",
childItems: [
{
text: "foo",
kind: "property",
},
],
},
{
text: "default",
kind: "const",
kindModifiers: "export",
childItems: [
{
text: "foo",
kind: "property",
},
],
},
{
text: "default",
kind: "const",
kindModifiers: "export",
childItems: [
{
text: "<class>",
kind: "class",
childItems: [
{
text: "prop",
kind: "property",
},
],
},
],
},
{
text: "default",
kind: "const",
kindModifiers: "export",
childItems: [
{
text: "Cls",
kind: "class",
childItems: [
{
text: "prop",
kind: "property",
},
],
},
],
},
{
text: "foo",
kind: "const",
kindModifiers: "export",
childItems: [
{
text: "foo",
kind: "property",
},
],
},
{
text: "Type",
kind: "type",
},
],
});

View File

@ -29,6 +29,9 @@
//// d: 1
//// }
//// }
////
//// function foo(props: { x: number; y: number }) {}
//// export = foo({ x: 1, y: 1 });
verify.navigationTree({
"text": '"navigationItemsExportEqualsExpression"',
@ -85,7 +88,13 @@ verify.navigationTree({
{
"text": "export=",
"kind": "class",
"kindModifiers": "export"
"kindModifiers": "export",
"childItems": [
{
"text": "AB",
"kind": "class"
}
]
},
{
"text": "export=",
@ -112,6 +121,21 @@ verify.navigationTree({
}
]
},
{
"text": "export=",
"kind": "const",
"kindModifiers": "export",
"childItems": [
{
"text": "x",
"kind": "property"
},
{
"text": "y",
"kind": "property"
}
]
},
{
"text": "abc",
"kind": "const"
@ -120,7 +144,10 @@ verify.navigationTree({
"text": "export=",
"kind": "const",
"kindModifiers": "export"
},
{
"text": "foo",
"kind": "function"
}
]
});

View File

@ -0,0 +1,131 @@
/// <reference path="fourslash.ts"/>
//// export const foo = {
//// foo: {},
//// };
////
//// export = {
//// foo: {},
//// };
////
//// export = {
//// foo: {},
//// };
////
//// type Type = typeof foo;
////
//// export = {
//// foo: {},
//// } as Type;
////
//// export = {
//// foo: {},
//// } satisfies Type;
////
//// export = (class {
//// prop = 42;
//// });
////
//// export = (class Cls {
//// prop = 42;
//// });
verify.navigationTree({
text: '"navigationItemsExportEqualsExpression2"',
kind: "module",
childItems: [
{
text: "export=",
kind: "const",
kindModifiers: "export",
childItems: [
{
text: "foo",
kind: "property",
},
],
},
{
text: "export=",
kind: "const",
kindModifiers: "export",
childItems: [
{
text: "foo",
kind: "property",
},
],
},
{
text: "export=",
kind: "const",
kindModifiers: "export",
childItems: [
{
text: "foo",
kind: "property",
},
],
},
{
text: "export=",
kind: "const",
kindModifiers: "export",
childItems: [
{
text: "foo",
kind: "property",
},
],
},
{
text: "export=",
kind: "const",
kindModifiers: "export",
childItems: [
{
text: "<class>",
kind: "class",
childItems: [
{
text: "prop",
kind: "property",
},
],
},
],
},
{
text: "export=",
kind: "const",
kindModifiers: "export",
childItems: [
{
text: "Cls",
kind: "class",
childItems: [
{
text: "prop",
kind: "property",
},
],
},
],
},
{
text: "foo",
kind: "const",
kindModifiers: "export",
childItems: [
{
text: "foo",
kind: "property",
},
],
},
{
text: "Type",
kind: "type",
},
],
});