Adds support for showing default exports in the navtree (#35477)
* Adds support for showing default exports in the navtree - Fixes #34601 * Handle the feedback in #35477 * Navigation items using default export or export = will get noted if they are a const vs function
This commit is contained in:
parent
38eccbab2a
commit
5e59eece34
|
@ -860,10 +860,10 @@ namespace FourSlash {
|
|||
|
||||
if (kind !== undefined || kindModifiers !== undefined) {
|
||||
if (actual.kind !== kind) {
|
||||
this.raiseError(`Unexpected kind for ${actual.name}: Expected ${kind}, actual ${actual.kind}`);
|
||||
this.raiseError(`Unexpected kind for ${actual.name}: Expected '${kind}', actual '${actual.kind}'`);
|
||||
}
|
||||
if (actual.kindModifiers !== (kindModifiers || "")) {
|
||||
this.raiseError(`Bad kind modifiers for ${actual.name}: Expected ${kindModifiers || ""}, actual ${actual.kindModifiers}`);
|
||||
this.raiseError(`Bad kindModifiers for ${actual.name}: Expected ${kindModifiers || ""}, actual ${actual.kindModifiers}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2873,7 +2873,7 @@ namespace FourSlash {
|
|||
|
||||
private verifyNavigationTreeOrBar(json: any, tree: any, name: "Tree" | "Bar", options: { checkSpans?: boolean } | undefined) {
|
||||
if (JSON.stringify(tree, replacer) !== JSON.stringify(json)) {
|
||||
this.raiseError(`verifyNavigation${name} failed - expected: ${stringify(json)}, got: ${stringify(tree, replacer)}`);
|
||||
this.raiseError(`verifyNavigation${name} failed - \n${showTextDiff(stringify(json), stringify(tree, replacer))}`);
|
||||
}
|
||||
|
||||
function replacer(key: string, value: any) {
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace ts.NavigationBar {
|
|||
|
||||
/**
|
||||
* Maximum amount of characters to return
|
||||
* The amount was choosen arbitrarily.
|
||||
* The amount was chosen arbitrarily.
|
||||
*/
|
||||
const maxLength = 150;
|
||||
|
||||
|
@ -307,6 +307,7 @@ namespace ts.NavigationBar {
|
|||
addNodeWithRecursiveChild(node, getInteriorModule(<ModuleDeclaration>node).body);
|
||||
break;
|
||||
|
||||
case SyntaxKind.ExportAssignment:
|
||||
case SyntaxKind.ExportSpecifier:
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
case SyntaxKind.IndexSignature:
|
||||
|
@ -681,6 +682,9 @@ namespace ts.NavigationBar {
|
|||
return isExternalModule(sourceFile)
|
||||
? `"${escapeString(getBaseFileName(removeFileExtension(normalizePath(sourceFile.fileName))))}"`
|
||||
: "<global>";
|
||||
case SyntaxKind.ExportAssignment:
|
||||
return isExportAssignment(node) && node.isExportEquals ? InternalSymbolName.ExportEquals : InternalSymbolName.Default;
|
||||
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
|
|
|
@ -438,6 +438,10 @@ namespace ts {
|
|||
}
|
||||
case SyntaxKind.Identifier:
|
||||
return isImportClause(node.parent) ? ScriptElementKind.alias : ScriptElementKind.unknown;
|
||||
case SyntaxKind.ExportAssignment:
|
||||
const scriptKind = getNodeKind((node as ExportAssignment).expression);
|
||||
// If the expression didn't come back with something (like it does for an identifiers)
|
||||
return scriptKind === ScriptElementKind.unknown ? ScriptElementKind.constElement : scriptKind;
|
||||
default:
|
||||
return ScriptElementKind.unknown;
|
||||
}
|
||||
|
@ -1154,6 +1158,7 @@ namespace ts {
|
|||
if (flags & ModifierFlags.Abstract) result.push(ScriptElementKindModifier.abstractModifier);
|
||||
if (flags & ModifierFlags.Export) result.push(ScriptElementKindModifier.exportedModifier);
|
||||
if (node.flags & NodeFlags.Ambient) result.push(ScriptElementKindModifier.ambientModifier);
|
||||
if (node.kind === SyntaxKind.ExportAssignment) result.push(ScriptElementKindModifier.exportedModifier);
|
||||
|
||||
return result.length > 0 ? result.join(",") : ScriptElementKindModifier.none;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ verify.completions(
|
|||
sourceDisplay: "./foo-bar",
|
||||
text: "(property) default: 0",
|
||||
kind: "property",
|
||||
kindModifiers: "export",
|
||||
hasAction: true,
|
||||
sortText: completion.SortText.AutoImportSuggestions
|
||||
},
|
||||
|
|
|
@ -15,16 +15,18 @@ goTo.marker("");
|
|||
verify.completions({
|
||||
marker: "",
|
||||
includes: {
|
||||
name: "foo",
|
||||
source: "/a",
|
||||
sourceDisplay: "./a",
|
||||
text: "(alias) const foo: 0\nexport default foo",
|
||||
kind: "alias",
|
||||
hasAction: true,
|
||||
sortText: completion.SortText.AutoImportSuggestions
|
||||
name: "foo",
|
||||
source: "/a",
|
||||
sourceDisplay: "./a",
|
||||
text: "(alias) const foo: 0\nexport default foo",
|
||||
kind: "alias",
|
||||
kindModifiers: "export",
|
||||
hasAction: true,
|
||||
sortText: completion.SortText.AutoImportSuggestions
|
||||
},
|
||||
preferences: { includeCompletionsForModuleExports: true },
|
||||
});
|
||||
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "foo",
|
||||
source: "/a",
|
||||
|
|
|
@ -18,6 +18,7 @@ const exportEntry: FourSlashInterface.ExpectedCompletionEntryObject = {
|
|||
sourceDisplay: "./foo-bar",
|
||||
text: "(property) export=: 0",
|
||||
kind: "property",
|
||||
kindModifiers: "export",
|
||||
hasAction: true,
|
||||
sortText: completion.SortText.AutoImportSuggestions
|
||||
};
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// const abc = 12;
|
||||
//// export default function () {}
|
||||
//// export default () => ""
|
||||
//// export default abc;
|
||||
//// export default class AB {}
|
||||
|
||||
verify.navigationTree({
|
||||
"text": '"navigationItemsExportDefaultExpression"',
|
||||
"kind": "module",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "default",
|
||||
"kind": "function",
|
||||
"kindModifiers": "export"
|
||||
},
|
||||
{
|
||||
"text": "default",
|
||||
"kind": "function",
|
||||
"kindModifiers": "export"
|
||||
},
|
||||
{
|
||||
"text": "AB",
|
||||
"kind": "class",
|
||||
"kindModifiers": "export"
|
||||
},
|
||||
{
|
||||
"text": "abc",
|
||||
"kind": "const"
|
||||
},
|
||||
{
|
||||
"text": "default",
|
||||
"kind": "const",
|
||||
"kindModifiers": "export"
|
||||
}
|
||||
]
|
||||
});
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
// 35477
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// const abc = 12;
|
||||
//// export = abc;
|
||||
//// export = function () {}
|
||||
//// export = () => ""
|
||||
//// export = class AB {}
|
||||
|
||||
verify.navigationTree({
|
||||
"text": '"navigationItemsExportEqualsExpression"',
|
||||
"kind": "module",
|
||||
"childItems": [
|
||||
{
|
||||
"text": "export=",
|
||||
"kind": "function",
|
||||
"kindModifiers": "export"
|
||||
},
|
||||
{
|
||||
"text": "export=",
|
||||
"kind": "function",
|
||||
"kindModifiers": "export"
|
||||
},
|
||||
{
|
||||
"text": "export=",
|
||||
"kind": "class",
|
||||
"kindModifiers": "export"
|
||||
},
|
||||
{
|
||||
"text": "abc",
|
||||
"kind": "const"
|
||||
},
|
||||
{
|
||||
"text": "export=",
|
||||
"kind": "const",
|
||||
"kindModifiers": "export"
|
||||
}
|
||||
]
|
||||
});
|
||||
|
Loading…
Reference in a new issue