Skip to content

Commit 71f604a

Browse files
committed
Added accessors, imports, and default export
1 parent b3a35c5 commit 71f604a

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/services/navigationBar.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,32 @@ namespace ts.NavigationBar {
8181
return getNavBarItem(declarationNameToString(methodDecl.name),
8282
ScriptElementKind.memberFunctionElement,
8383
[getNodeSpan(node)]);
84-
// TODO: Class properties/getters/setters, export defaults, import/export identifiers
84+
case SyntaxKind.GetAccessor:
85+
case SyntaxKind.SetAccessor:
86+
const accessor = node as GetAccessorDeclaration | SetAccessorDeclaration;
87+
let accessorName: string;
88+
if (accessor.name && getFullWidth(accessor.name) > 0) {
89+
accessorName = declarationNameToString(accessor.name);
90+
}
91+
else {
92+
accessorName = "<accessor>";
93+
}
94+
return getNavBarItem(accessorName, ScriptElementKind.memberGetAccessorElement, [getNodeSpan(node)]);
95+
case SyntaxKind.ExportAssignment:
96+
return getNavBarItem("default", ScriptElementKind.variableElement, [getNodeSpan(node)]);
97+
case SyntaxKind.ImportClause: // e.g. 'def' in: import def from 'mod' (in ImportDeclaration)
98+
if (!(node as ImportClause).name) {
99+
// No default import (this node is still a parent of named & namespace imports, which are handled below)
100+
return undefined;
101+
}
102+
case SyntaxKind.ImportSpecifier: // e.g. 'id' in: import {id} from 'mod' (in NamedImports, in ImportClause)
103+
case SyntaxKind.NamespaceImport: // e.g. '* as ns' in: import * as ns from 'mod' (in ImportClause)
104+
// TODO: Should export specifiers add a navbar item?
105+
// They are often just references to items defined elsewhere in the file (unless renamed, or re-exported)
106+
// case SyntaxKind.ExportSpecifier: // e.g. 'a' or 'b' in: export {a, foo as b}
107+
const decl = node as (ImportSpecifier | ImportClause | NamespaceImport | ExportSpecifier);
108+
const declName = declarationNameToString(decl.name);
109+
return getNavBarItem(declName, ScriptElementKind.constElement, [getNodeSpan(node)]);
85110
default:
86111
return undefined;
87112
}
@@ -96,6 +121,8 @@ namespace ts.NavigationBar {
96121
case SyntaxKind.FunctionDeclaration:
97122
case SyntaxKind.FunctionExpression:
98123
case SyntaxKind.ArrowFunction:
124+
case SyntaxKind.GetAccessor:
125+
case SyntaxKind.SetAccessor:
99126
return true;
100127
default:
101128
return false;

0 commit comments

Comments
 (0)