Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/services/navigationBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,10 @@ module ts.NavigationBar {
}

function createFunctionItem(node: FunctionDeclaration) {
if (node.name && node.body && node.body.kind === SyntaxKind.Block) {
if ((node.name || node.flags & NodeFlags.Default) && node.body && node.body.kind === SyntaxKind.Block) {
var childItems = getItemsWorker(sortNodes((<Block>node.body).statements), createChildItem);

return getNavigationBarItem(node.name.text,
return getNavigationBarItem((node.flags & NodeFlags.Default) ? "default": node.name.text ,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stray space at the end, add a space after "default"; also I think this was a little cleaner when you just used an intermediate variable (nodeName).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the syntax is of type export default function foo() {} shouldn't you be showing foo instead of default?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

ts.ScriptElementKind.functionElement,
getNodeModifiers(node),
[getNodeSpan(node)],
Expand Down Expand Up @@ -458,11 +458,6 @@ module ts.NavigationBar {
}

function createClassItem(node: ClassDeclaration): ts.NavigationBarItem {
if (!node.name) {
// An export default class may be nameless
return undefined;
}

var childItems: NavigationBarItem[];

if (node.members) {
Expand All @@ -481,8 +476,10 @@ module ts.NavigationBar {
var childItems = getItemsWorker(sortNodes(nodes), createChildItem);
}

var nodeName = (node.flags & NodeFlags.Default) ? "default" : node.name.text;

return getNavigationBarItem(
node.name.text,
nodeName,
ts.ScriptElementKind.classElement,
getNodeModifiers(node),
[getNodeSpan(node)],
Expand Down
24 changes: 24 additions & 0 deletions tests/cases/fourslash/navbar_exportDefault.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// <reference path="fourslash.ts" />

// @Filename: a.ts
//// {| "itemName": "default", "kind": "class", "parentName": "" |}export default class { }

// @Filename: b.ts
//// {| "itemName": "default", "kind": "class", "parentName": "" |}export default class C { }

// @Filename: c.ts
//// {| "itemName": "default", "kind": "function", "parentName": "" |}export default function { }

// @Filename: d.ts
//// {| "itemName": "default", "kind": "function", "parentName": "" |}export default function Func { }

test.markers().forEach(marker => {
goTo.file(marker.fileName);
verify.getScriptLexicalStructureListContains(
marker.data.itemName,
marker.data.kind,
marker.fileName,
marker.data.parentName,
marker.data.isAdditionalRange,
marker.position);
});