From f2e2be5e78036c68c81c59fa06ef2b53c4c0777b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Fri, 17 Oct 2025 00:32:45 +0200 Subject: [PATCH 1/2] Handle more child types when generating navigation tree items for `export default` --- src/services/navigationBar.ts | 6 +- .../navigationBarExportAssignment1.ts | 110 ++++++++++++++++++ 2 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/navigationBarExportAssignment1.ts diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index b4c32d566b126..69b36b9ee8a36 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -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); diff --git a/tests/cases/fourslash/navigationBarExportAssignment1.ts b/tests/cases/fourslash/navigationBarExportAssignment1.ts new file mode 100644 index 0000000000000..91413434173e7 --- /dev/null +++ b/tests/cases/fourslash/navigationBarExportAssignment1.ts @@ -0,0 +1,110 @@ +/// + +//// 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; +//// }); + +verify.navigationTree({ + text: '"navigationBarExportAssignment1"', + 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: "", + kind: "class", + childItems: [ + { + text: "prop", + kind: "property", + }, + ], + }, + ], + }, + { + text: "foo", + kind: "const", + kindModifiers: "export", + childItems: [ + { + text: "foo", + kind: "property", + }, + ], + }, + { + text: "Type", + kind: "type", + }, + ], +}); From f68399b9b6ed8459e1cf8d563ef93a214d1493e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Fri, 17 Oct 2025 08:51:10 +0200 Subject: [PATCH 2/2] fixed expects and add extra tests --- ...avigationItemsExportDefaultExpression2.ts} | 23 ++- .../navigationItemsExportEqualsExpression.ts | 31 ++++- .../navigationItemsExportEqualsExpression2.ts | 131 ++++++++++++++++++ 3 files changed, 182 insertions(+), 3 deletions(-) rename tests/cases/fourslash/{navigationBarExportAssignment1.ts => navigationItemsExportDefaultExpression2.ts} (80%) create mode 100644 tests/cases/fourslash/navigationItemsExportEqualsExpression2.ts diff --git a/tests/cases/fourslash/navigationBarExportAssignment1.ts b/tests/cases/fourslash/navigationItemsExportDefaultExpression2.ts similarity index 80% rename from tests/cases/fourslash/navigationBarExportAssignment1.ts rename to tests/cases/fourslash/navigationItemsExportDefaultExpression2.ts index 91413434173e7..bb2540634977a 100644 --- a/tests/cases/fourslash/navigationBarExportAssignment1.ts +++ b/tests/cases/fourslash/navigationItemsExportDefaultExpression2.ts @@ -25,9 +25,13 @@ //// export default (class { //// prop = 42; //// }); +//// +//// export default (class Cls { +//// prop = 42; +//// }); verify.navigationTree({ - text: '"navigationBarExportAssignment1"', + text: '"navigationItemsExportDefaultExpression2"', kind: "module", childItems: [ { @@ -91,6 +95,23 @@ verify.navigationTree({ }, ], }, + { + text: "default", + kind: "const", + kindModifiers: "export", + childItems: [ + { + text: "Cls", + kind: "class", + childItems: [ + { + text: "prop", + kind: "property", + }, + ], + }, + ], + }, { text: "foo", kind: "const", diff --git a/tests/cases/fourslash/navigationItemsExportEqualsExpression.ts b/tests/cases/fourslash/navigationItemsExportEqualsExpression.ts index 68bc12716731e..29874e3984739 100644 --- a/tests/cases/fourslash/navigationItemsExportEqualsExpression.ts +++ b/tests/cases/fourslash/navigationItemsExportEqualsExpression.ts @@ -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" } ] }); - diff --git a/tests/cases/fourslash/navigationItemsExportEqualsExpression2.ts b/tests/cases/fourslash/navigationItemsExportEqualsExpression2.ts new file mode 100644 index 0000000000000..d8683dc4ffc55 --- /dev/null +++ b/tests/cases/fourslash/navigationItemsExportEqualsExpression2.ts @@ -0,0 +1,131 @@ +/// + +//// 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: "", + 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", + }, + ], +});