Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5e59eec

Browse filesBrowse files
author
Orta
authored
Adds support for showing default exports in the navtree (microsoft#35477)
* Adds support for showing default exports in the navtree - Fixes microsoft#34601 * Handle the feedback in microsoft#35477 * Navigation items using default export or export = will get noted if they are a const vs function
1 parent 38eccba commit 5e59eec
Copy full SHA for 5e59eec

8 files changed

+103-11Lines changed: 103 additions & 11 deletions
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/harness/fourslashImpl.ts‎

Copy file name to clipboardExpand all lines: src/harness/fourslashImpl.ts
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -860,10 +860,10 @@ namespace FourSlash {
860860

861861
if (kind !== undefined || kindModifiers !== undefined) {
862862
if (actual.kind !== kind) {
863-
this.raiseError(`Unexpected kind for ${actual.name}: Expected ${kind}, actual ${actual.kind}`);
863+
this.raiseError(`Unexpected kind for ${actual.name}: Expected '${kind}', actual '${actual.kind}'`);
864864
}
865865
if (actual.kindModifiers !== (kindModifiers || "")) {
866-
this.raiseError(`Bad kind modifiers for ${actual.name}: Expected ${kindModifiers || ""}, actual ${actual.kindModifiers}`);
866+
this.raiseError(`Bad kindModifiers for ${actual.name}: Expected ${kindModifiers || ""}, actual ${actual.kindModifiers}`);
867867
}
868868
}
869869

@@ -2873,7 +2873,7 @@ namespace FourSlash {
28732873

28742874
private verifyNavigationTreeOrBar(json: any, tree: any, name: "Tree" | "Bar", options: { checkSpans?: boolean } | undefined) {
28752875
if (JSON.stringify(tree, replacer) !== JSON.stringify(json)) {
2876-
this.raiseError(`verifyNavigation${name} failed - expected: ${stringify(json)}, got: ${stringify(tree, replacer)}`);
2876+
this.raiseError(`verifyNavigation${name} failed - \n${showTextDiff(stringify(json), stringify(tree, replacer))}`);
28772877
}
28782878

28792879
function replacer(key: string, value: any) {
Collapse file

‎src/services/navigationBar.ts‎

Copy file name to clipboardExpand all lines: src/services/navigationBar.ts
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace ts.NavigationBar {
1717

1818
/**
1919
* Maximum amount of characters to return
20-
* The amount was choosen arbitrarily.
20+
* The amount was chosen arbitrarily.
2121
*/
2222
const maxLength = 150;
2323

@@ -307,6 +307,7 @@ namespace ts.NavigationBar {
307307
addNodeWithRecursiveChild(node, getInteriorModule(<ModuleDeclaration>node).body);
308308
break;
309309

310+
case SyntaxKind.ExportAssignment:
310311
case SyntaxKind.ExportSpecifier:
311312
case SyntaxKind.ImportEqualsDeclaration:
312313
case SyntaxKind.IndexSignature:
@@ -681,6 +682,9 @@ namespace ts.NavigationBar {
681682
return isExternalModule(sourceFile)
682683
? `"${escapeString(getBaseFileName(removeFileExtension(normalizePath(sourceFile.fileName))))}"`
683684
: "<global>";
685+
case SyntaxKind.ExportAssignment:
686+
return isExportAssignment(node) && node.isExportEquals ? InternalSymbolName.ExportEquals : InternalSymbolName.Default;
687+
684688
case SyntaxKind.ArrowFunction:
685689
case SyntaxKind.FunctionDeclaration:
686690
case SyntaxKind.FunctionExpression:
Collapse file

‎src/services/utilities.ts‎

Copy file name to clipboardExpand all lines: src/services/utilities.ts
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,10 @@ namespace ts {
438438
}
439439
case SyntaxKind.Identifier:
440440
return isImportClause(node.parent) ? ScriptElementKind.alias : ScriptElementKind.unknown;
441+
case SyntaxKind.ExportAssignment:
442+
const scriptKind = getNodeKind((node as ExportAssignment).expression);
443+
// If the expression didn't come back with something (like it does for an identifiers)
444+
return scriptKind === ScriptElementKind.unknown ? ScriptElementKind.constElement : scriptKind;
441445
default:
442446
return ScriptElementKind.unknown;
443447
}
@@ -1154,6 +1158,7 @@ namespace ts {
11541158
if (flags & ModifierFlags.Abstract) result.push(ScriptElementKindModifier.abstractModifier);
11551159
if (flags & ModifierFlags.Export) result.push(ScriptElementKindModifier.exportedModifier);
11561160
if (node.flags & NodeFlags.Ambient) result.push(ScriptElementKindModifier.ambientModifier);
1161+
if (node.kind === SyntaxKind.ExportAssignment) result.push(ScriptElementKindModifier.exportedModifier);
11571162

11581163
return result.length > 0 ? result.join(",") : ScriptElementKindModifier.none;
11591164
}
Collapse file

‎tests/cases/fourslash/completionsImport_default_anonymous.ts‎

Copy file name to clipboardExpand all lines: tests/cases/fourslash/completionsImport_default_anonymous.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ verify.completions(
3131
sourceDisplay: "./foo-bar",
3232
text: "(property) default: 0",
3333
kind: "property",
34+
kindModifiers: "export",
3435
hasAction: true,
3536
sortText: completion.SortText.AutoImportSuggestions
3637
},
Collapse file

‎tests/cases/fourslash/completionsImport_default_exportDefaultIdentifier.ts‎

Copy file name to clipboardExpand all lines: tests/cases/fourslash/completionsImport_default_exportDefaultIdentifier.ts
+9-7Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@ goTo.marker("");
1515
verify.completions({
1616
marker: "",
1717
includes: {
18-
name: "foo",
19-
source: "/a",
20-
sourceDisplay: "./a",
21-
text: "(alias) const foo: 0\nexport default foo",
22-
kind: "alias",
23-
hasAction: true,
24-
sortText: completion.SortText.AutoImportSuggestions
18+
name: "foo",
19+
source: "/a",
20+
sourceDisplay: "./a",
21+
text: "(alias) const foo: 0\nexport default foo",
22+
kind: "alias",
23+
kindModifiers: "export",
24+
hasAction: true,
25+
sortText: completion.SortText.AutoImportSuggestions
2526
},
2627
preferences: { includeCompletionsForModuleExports: true },
2728
});
29+
2830
verify.applyCodeActionFromCompletion("", {
2931
name: "foo",
3032
source: "/a",
Collapse file

‎tests/cases/fourslash/completionsImport_exportEquals_anonymous.ts‎

Copy file name to clipboardExpand all lines: tests/cases/fourslash/completionsImport_exportEquals_anonymous.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const exportEntry: FourSlashInterface.ExpectedCompletionEntryObject = {
1818
sourceDisplay: "./foo-bar",
1919
text: "(property) export=: 0",
2020
kind: "property",
21+
kindModifiers: "export",
2122
hasAction: true,
2223
sortText: completion.SortText.AutoImportSuggestions
2324
};
Collapse file
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
//// const abc = 12;
4+
//// export default function () {}
5+
//// export default () => ""
6+
//// export default abc;
7+
//// export default class AB {}
8+
9+
verify.navigationTree({
10+
"text": '"navigationItemsExportDefaultExpression"',
11+
"kind": "module",
12+
"childItems": [
13+
{
14+
"text": "default",
15+
"kind": "function",
16+
"kindModifiers": "export"
17+
},
18+
{
19+
"text": "default",
20+
"kind": "function",
21+
"kindModifiers": "export"
22+
},
23+
{
24+
"text": "AB",
25+
"kind": "class",
26+
"kindModifiers": "export"
27+
},
28+
{
29+
"text": "abc",
30+
"kind": "const"
31+
},
32+
{
33+
"text": "default",
34+
"kind": "const",
35+
"kindModifiers": "export"
36+
}
37+
]
38+
});
39+
Collapse file
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// 35477
2+
/// <reference path="fourslash.ts"/>
3+
4+
//// const abc = 12;
5+
//// export = abc;
6+
//// export = function () {}
7+
//// export = () => ""
8+
//// export = class AB {}
9+
10+
verify.navigationTree({
11+
"text": '"navigationItemsExportEqualsExpression"',
12+
"kind": "module",
13+
"childItems": [
14+
{
15+
"text": "export=",
16+
"kind": "function",
17+
"kindModifiers": "export"
18+
},
19+
{
20+
"text": "export=",
21+
"kind": "function",
22+
"kindModifiers": "export"
23+
},
24+
{
25+
"text": "export=",
26+
"kind": "class",
27+
"kindModifiers": "export"
28+
},
29+
{
30+
"text": "abc",
31+
"kind": "const"
32+
},
33+
{
34+
"text": "export=",
35+
"kind": "const",
36+
"kindModifiers": "export"
37+
}
38+
]
39+
});
40+

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.