Merge pull request #2129 from Microsoft/importNavigation
New Impor/Export syntax navigation support
This commit is contained in:
commit
07547dc83c
11 changed files with 256 additions and 2 deletions
|
@ -178,7 +178,15 @@ module ts.BreakpointResolver {
|
|||
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
// import statement without including semicolon
|
||||
return textSpan(node,(<ImportEqualsDeclaration>node).moduleReference);
|
||||
return textSpan(node, (<ImportEqualsDeclaration>node).moduleReference);
|
||||
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
// import statement without including semicolon
|
||||
return textSpan(node, (<ImportDeclaration>node).moduleSpecifier);
|
||||
|
||||
case SyntaxKind.ExportDeclaration:
|
||||
// import statement without including semicolon
|
||||
return textSpan(node, (<ExportDeclaration>node).moduleSpecifier);
|
||||
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
// span on complete module if it is instantiated
|
||||
|
|
|
@ -50,6 +50,38 @@ module ts.NavigationBar {
|
|||
case SyntaxKind.ArrayBindingPattern:
|
||||
forEach((<BindingPattern>node).elements, visit);
|
||||
break;
|
||||
|
||||
case SyntaxKind.ExportDeclaration:
|
||||
// Handle named exports case e.g.:
|
||||
// export {a, b as B} from "mod";
|
||||
if ((<ExportDeclaration>node).exportClause) {
|
||||
forEach((<ExportDeclaration>node).exportClause.elements, visit);
|
||||
}
|
||||
break;
|
||||
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
var importClause = (<ImportDeclaration>node).importClause;
|
||||
if (importClause) {
|
||||
// Handle default import case e.g.:
|
||||
// import d from "mod";
|
||||
if (importClause.name) {
|
||||
childNodes.push(importClause);
|
||||
}
|
||||
|
||||
// Handle named bindings in imports e.g.:
|
||||
// import * as NS from "mod";
|
||||
// import {a, b as B} from "mod";
|
||||
if (importClause.namedBindings) {
|
||||
if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) {
|
||||
childNodes.push(importClause.namedBindings);
|
||||
}
|
||||
else {
|
||||
forEach((<NamedImports>importClause.namedBindings).elements, visit);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SyntaxKind.BindingElement:
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
if (isBindingPattern((<VariableDeclaration>node).name)) {
|
||||
|
@ -62,7 +94,11 @@ module ts.NavigationBar {
|
|||
case SyntaxKind.InterfaceDeclaration:
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
case SyntaxKind.ImportSpecifier:
|
||||
case SyntaxKind.ExportSpecifier:
|
||||
childNodes.push(node);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -291,9 +327,16 @@ module ts.NavigationBar {
|
|||
else {
|
||||
return createItem(node, getTextOfNode(name), ts.ScriptElementKind.variableElement);
|
||||
}
|
||||
|
||||
|
||||
case SyntaxKind.Constructor:
|
||||
return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement);
|
||||
|
||||
case SyntaxKind.ExportSpecifier:
|
||||
case SyntaxKind.ImportSpecifier:
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
case SyntaxKind.ImportClause:
|
||||
case SyntaxKind.NamespaceImport:
|
||||
return createItem(node, getTextOfNode((<Declaration>node).name), ts.ScriptElementKind.alias);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
|
|
|
@ -802,6 +802,11 @@ module ts {
|
|||
case SyntaxKind.EnumDeclaration:
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
case SyntaxKind.ExportSpecifier:
|
||||
case SyntaxKind.ImportSpecifier:
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
case SyntaxKind.ImportClause:
|
||||
case SyntaxKind.NamespaceImport:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
case SyntaxKind.TypeLiteral:
|
||||
|
@ -841,6 +846,37 @@ module ts {
|
|||
case SyntaxKind.PropertySignature:
|
||||
namedDeclarations.push(<Declaration>node);
|
||||
break;
|
||||
|
||||
case SyntaxKind.ExportDeclaration:
|
||||
// Handle named exports case e.g.:
|
||||
// export {a, b as B} from "mod";
|
||||
if ((<ExportDeclaration>node).exportClause) {
|
||||
forEach((<ExportDeclaration>node).exportClause.elements, visit);
|
||||
}
|
||||
break;
|
||||
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
var importClause = (<ImportDeclaration>node).importClause;
|
||||
if (importClause) {
|
||||
// Handle default import case e.g.:
|
||||
// import d from "mod";
|
||||
if (importClause.name) {
|
||||
namedDeclarations.push(importClause);
|
||||
}
|
||||
|
||||
// Handle named bindings in imports e.g.:
|
||||
// import * as NS from "mod";
|
||||
// import {a, b as B} from "mod";
|
||||
if (importClause.namedBindings) {
|
||||
if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) {
|
||||
namedDeclarations.push(<NamespaceImport>importClause.namedBindings);
|
||||
}
|
||||
else {
|
||||
forEach((<NamedImports>importClause.namedBindings).elements, visit);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -2010,6 +2046,12 @@ module ts {
|
|||
case SyntaxKind.TypeParameter: return ScriptElementKind.typeParameterElement;
|
||||
case SyntaxKind.EnumMember: return ScriptElementKind.variableElement;
|
||||
case SyntaxKind.Parameter: return (node.flags & NodeFlags.AccessibilityModifier) ? ScriptElementKind.memberVariableElement : ScriptElementKind.parameterElement;
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
case SyntaxKind.ImportSpecifier:
|
||||
case SyntaxKind.ImportClause:
|
||||
case SyntaxKind.ExportSpecifier:
|
||||
case SyntaxKind.NamespaceImport:
|
||||
return ScriptElementKind.alias;
|
||||
}
|
||||
return ScriptElementKind.unknown;
|
||||
}
|
||||
|
|
17
tests/baselines/reference/bpSpan_exports.baseline
Normal file
17
tests/baselines/reference/bpSpan_exports.baseline
Normal file
|
@ -0,0 +1,17 @@
|
|||
|
||||
1 >export * from "a";
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~ => Pos: (0 to 18) SpanInfo: {"start":0,"length":17}
|
||||
>export * from "a"
|
||||
>:=> (line 1, col 0) to (line 1, col 17)
|
||||
--------------------------------
|
||||
2 >export {a as A} from "a";
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (19 to 44) SpanInfo: {"start":19,"length":24}
|
||||
>export {a as A} from "a"
|
||||
>:=> (line 2, col 0) to (line 2, col 24)
|
||||
--------------------------------
|
||||
3 >export import e = require("a");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (45 to 75) SpanInfo: {"start":45,"length":30}
|
||||
>export import e = require("a")
|
||||
>:=> (line 3, col 0) to (line 3, col 30)
|
35
tests/baselines/reference/bpSpan_imports.baseline
Normal file
35
tests/baselines/reference/bpSpan_imports.baseline
Normal file
|
@ -0,0 +1,35 @@
|
|||
|
||||
1 >import * as NS from "a";
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (0 to 24) SpanInfo: {"start":0,"length":23}
|
||||
>import * as NS from "a"
|
||||
>:=> (line 1, col 0) to (line 1, col 23)
|
||||
--------------------------------
|
||||
2 >import {a as A} from "a";
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (25 to 50) SpanInfo: {"start":25,"length":24}
|
||||
>import {a as A} from "a"
|
||||
>:=> (line 2, col 0) to (line 2, col 24)
|
||||
--------------------------------
|
||||
3 > import d from "a";
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~ => Pos: (51 to 70) SpanInfo: {"start":52,"length":17}
|
||||
>import d from "a"
|
||||
>:=> (line 3, col 1) to (line 3, col 18)
|
||||
--------------------------------
|
||||
4 >import d2, {c, d as D} from "a";
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (71 to 103) SpanInfo: {"start":71,"length":31}
|
||||
>import d2, {c, d as D} from "a"
|
||||
>:=> (line 4, col 0) to (line 4, col 31)
|
||||
--------------------------------
|
||||
5 >import "a";
|
||||
|
||||
~~~~~~~~~~~~ => Pos: (104 to 115) SpanInfo: {"start":104,"length":10}
|
||||
>import "a"
|
||||
>:=> (line 5, col 0) to (line 5, col 10)
|
||||
--------------------------------
|
||||
6 >import e = require("a");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (116 to 139) SpanInfo: {"start":116,"length":23}
|
||||
>import e = require("a")
|
||||
>:=> (line 6, col 0) to (line 6, col 23)
|
9
tests/cases/fourslash/breakpointValidationExports.ts
Normal file
9
tests/cases/fourslash/breakpointValidationExports.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @BaselineFile: bpSpan_exports.baseline
|
||||
// @Filename: bpSpan_exports.ts
|
||||
////export * from "a";
|
||||
////export {a as A} from "a";
|
||||
////export import e = require("a");
|
||||
|
||||
verify.baselineCurrentFileBreakpointLocations();
|
12
tests/cases/fourslash/breakpointValidationImports.ts
Normal file
12
tests/cases/fourslash/breakpointValidationImports.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @BaselineFile: bpSpan_imports.baseline
|
||||
// @Filename: bpSpan_imports.ts
|
||||
////import * as NS from "a";
|
||||
////import {a as A} from "a";
|
||||
//// import d from "a";
|
||||
////import d2, {c, d as D} from "a";
|
||||
////import "a";
|
||||
////import e = require("a");
|
||||
|
||||
verify.baselineCurrentFileBreakpointLocations();
|
20
tests/cases/fourslash/navigateItemsExports.ts
Normal file
20
tests/cases/fourslash/navigateItemsExports.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////export { {| "itemName": "a", "kind": "alias", "parentName": "" |}a } from "a";
|
||||
////
|
||||
////export { {| "itemName": "B", "kind": "alias", "parentName": "" |}b as B } from "a";
|
||||
////
|
||||
////export { {| "itemName": "c", "kind": "alias", "parentName": "" |}c,
|
||||
//// {| "itemName": "D", "kind": "alias", "parentName": "" |}d as D } from "a";
|
||||
////
|
||||
////{| "itemName": "f", "kind": "alias", "parentName": "" |}export import f = require("a");
|
||||
|
||||
test.markers().forEach(marker => {
|
||||
verify.navigationItemsListContains(
|
||||
marker.data.itemName,
|
||||
marker.data.kind,
|
||||
marker.data.itemName,
|
||||
"exact",
|
||||
marker.fileName,
|
||||
marker.data.parentName);
|
||||
});
|
25
tests/cases/fourslash/navigateItemsImports.ts
Normal file
25
tests/cases/fourslash/navigateItemsImports.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////import {| "itemName": "ns", "kind": "alias", "parentName": "" |}* as ns from "a";
|
||||
////
|
||||
////import { {| "itemName": "a", "kind": "alias", "parentName": "" |}a } from "a";
|
||||
////
|
||||
////import { {| "itemName": "B", "kind": "alias", "parentName": "" |}b as B } from "a";
|
||||
////
|
||||
////import { {| "itemName": "c", "kind": "alias", "parentName": "" |}c,
|
||||
//// {| "itemName": "D", "kind": "alias", "parentName": "" |}d as D } from "a";
|
||||
////
|
||||
////import {| "itemName": "d1", "kind": "alias", "parentName": "" |}d1, {
|
||||
//// {| "itemName": "e", "kind": "alias", "parentName": "" |}e } from "a";
|
||||
////
|
||||
////{| "itemName": "f", "kind": "alias", "parentName": "" |}import f = require("a");
|
||||
|
||||
test.markers().forEach(marker => {
|
||||
verify.navigationItemsListContains(
|
||||
marker.data.itemName,
|
||||
marker.data.kind,
|
||||
marker.data.itemName,
|
||||
"exact",
|
||||
marker.fileName,
|
||||
marker.data.parentName);
|
||||
});
|
18
tests/cases/fourslash/scriptLexicalStructureExports.ts
Normal file
18
tests/cases/fourslash/scriptLexicalStructureExports.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
|
||||
////export { {| "itemName": "a", "kind": "alias", "parentName": "" |}a } from "a";
|
||||
////
|
||||
////export { {| "itemName": "B", "kind": "alias", "parentName": "" |}b as B } from "a"
|
||||
////
|
||||
////{| "itemName": "e", "kind": "alias", "parentName": "" |} export import e = require("a");
|
||||
////
|
||||
////export * from "a"; // no bindings here
|
||||
|
||||
test.markers().forEach((marker) => {
|
||||
if (marker.data) {
|
||||
verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
|
||||
}
|
||||
});
|
||||
|
||||
verify.getScriptLexicalStructureListCount(4);
|
25
tests/cases/fourslash/scriptLexicalStructureImports.ts
Normal file
25
tests/cases/fourslash/scriptLexicalStructureImports.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
|
||||
////import {| "itemName": "d1", "kind": "alias", "parentName": "" |}d1 from "a";
|
||||
////
|
||||
////import { {| "itemName": "a", "kind": "alias", "parentName": "" |}a } from "a";
|
||||
////
|
||||
////import { {| "itemName": "B", "kind": "alias", "parentName": "" |}b as B } from "a"
|
||||
////
|
||||
////import {| "itemName": "d2", "kind": "alias", "parentName": "" |}d2,
|
||||
//// { {| "itemName": "c", "kind": "alias", "parentName": "" |}c,
|
||||
//// {| "itemName": "D", "kind": "alias", "parentName": "" |} d as D } from "a"
|
||||
////
|
||||
////{| "itemName": "e", "kind": "alias", "parentName": "" |}import e = require("a");
|
||||
////
|
||||
////import {| "itemName": "ns", "kind": "alias", "parentName": "" |}* as ns from "a";
|
||||
|
||||
|
||||
test.markers().forEach((marker) => {
|
||||
if (marker.data) {
|
||||
verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
|
||||
}
|
||||
});
|
||||
|
||||
verify.getScriptLexicalStructureListCount(9);
|
Loading…
Reference in a new issue