Skip to content

Commit 7b7d2b6

Browse files
committed
Support navigation bar for new import/export syntax
1 parent 591df20 commit 7b7d2b6

3 files changed

Lines changed: 87 additions & 1 deletion

File tree

src/services/navigationBar.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,38 @@ module ts.NavigationBar {
5050
case SyntaxKind.ArrayBindingPattern:
5151
forEach((<BindingPattern>node).elements, visit);
5252
break;
53+
54+
case SyntaxKind.ExportDeclaration:
55+
// Handle named exports case e.g.:
56+
// export {a, b as B} from "mod";
57+
if ((<ExportDeclaration>node).exportClause) {
58+
forEach((<ExportDeclaration>node).exportClause.elements, visit);
59+
}
60+
break;
61+
62+
case SyntaxKind.ImportDeclaration:
63+
var importClause = (<ImportDeclaration>node).importClause;
64+
if (importClause) {
65+
// Handle default import case e.g.:
66+
// import d from "mod";
67+
if (importClause.name) {
68+
childNodes.push(importClause);
69+
}
70+
71+
// Handle named bindings in imports e.g.:
72+
// import * as NS from "mod";
73+
// import {a, b as B} from "mod";
74+
if (importClause.namedBindings) {
75+
if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) {
76+
childNodes.push(importClause.namedBindings);
77+
}
78+
else {
79+
forEach((<NamedImports>importClause.namedBindings).elements, visit);
80+
}
81+
}
82+
}
83+
break;
84+
5385
case SyntaxKind.BindingElement:
5486
case SyntaxKind.VariableDeclaration:
5587
if (isBindingPattern((<VariableDeclaration>node).name)) {
@@ -62,7 +94,11 @@ module ts.NavigationBar {
6294
case SyntaxKind.InterfaceDeclaration:
6395
case SyntaxKind.ModuleDeclaration:
6496
case SyntaxKind.FunctionDeclaration:
97+
case SyntaxKind.ImportEqualsDeclaration:
98+
case SyntaxKind.ImportSpecifier:
99+
case SyntaxKind.ExportSpecifier:
65100
childNodes.push(node);
101+
break;
66102
}
67103
}
68104

@@ -291,9 +327,16 @@ module ts.NavigationBar {
291327
else {
292328
return createItem(node, getTextOfNode(name), ts.ScriptElementKind.variableElement);
293329
}
294-
330+
295331
case SyntaxKind.Constructor:
296332
return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement);
333+
334+
case SyntaxKind.ExportSpecifier:
335+
case SyntaxKind.ImportSpecifier:
336+
case SyntaxKind.ImportEqualsDeclaration:
337+
case SyntaxKind.ImportClause:
338+
case SyntaxKind.NamespaceImport:
339+
return createItem(node, getTextOfNode((<Declaration>node).name), ts.ScriptElementKind.alias);
297340
}
298341

299342
return undefined;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
4+
////export { {| "itemName": "a", "kind": "alias", "parentName": "" |}a } from "a";
5+
////
6+
////export { {| "itemName": "B", "kind": "alias", "parentName": "" |}b as B } from "a"
7+
////
8+
////{| "itemName": "e", "kind": "alias", "parentName": "" |} export import e = require("a");
9+
////
10+
////export * from "a"; // no bindings here
11+
12+
test.markers().forEach((marker) => {
13+
if (marker.data) {
14+
verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
15+
}
16+
});
17+
18+
verify.getScriptLexicalStructureListCount(4);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
4+
////import {| "itemName": "d1", "kind": "alias", "parentName": "" |}d1 from "a";
5+
////
6+
////import { {| "itemName": "a", "kind": "alias", "parentName": "" |}a } from "a";
7+
////
8+
////import { {| "itemName": "B", "kind": "alias", "parentName": "" |}b as B } from "a"
9+
////
10+
////import {| "itemName": "d2", "kind": "alias", "parentName": "" |}d2,
11+
//// { {| "itemName": "c", "kind": "alias", "parentName": "" |}c,
12+
//// {| "itemName": "D", "kind": "alias", "parentName": "" |} d as D } from "a"
13+
////
14+
////{| "itemName": "e", "kind": "alias", "parentName": "" |}import e = require("a");
15+
////
16+
////import {| "itemName": "ns", "kind": "alias", "parentName": "" |}* as ns from "a";
17+
18+
19+
test.markers().forEach((marker) => {
20+
if (marker.data) {
21+
verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
22+
}
23+
});
24+
25+
verify.getScriptLexicalStructureListCount(9);

0 commit comments

Comments
 (0)