mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Support GetDefinitionLocation on module names and aliases for new import/export syntax
This commit is contained in:
parent
a47c7abbdf
commit
ce6681cc93
@ -10278,11 +10278,12 @@ module ts {
|
||||
|
||||
case SyntaxKind.StringLiteral:
|
||||
// External module name in an import declaration
|
||||
if (isExternalModuleImportEqualsDeclaration(node.parent.parent) &&
|
||||
getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) {
|
||||
var importSymbol = getSymbolOfNode(node.parent.parent);
|
||||
var moduleType = getTypeOfSymbol(importSymbol);
|
||||
return moduleType ? moduleType.symbol : undefined;
|
||||
var moduleName: Expression;
|
||||
if ((isExternalModuleImportEqualsDeclaration(node.parent.parent) &&
|
||||
getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) ||
|
||||
((node.parent.kind === SyntaxKind.ImportDeclaration || node.parent.kind === SyntaxKind.ExportDeclaration) &&
|
||||
(<ImportDeclaration>node.parent).moduleSpecifier === node)) {
|
||||
return resolveExternalModuleName(node, <LiteralExpression>node);
|
||||
}
|
||||
|
||||
// Intentional fall-through
|
||||
|
||||
@ -745,6 +745,12 @@ module ts {
|
||||
}
|
||||
|
||||
var parent = name.parent;
|
||||
if (parent.kind === SyntaxKind.ImportSpecifier || parent.kind === SyntaxKind.ExportSpecifier) {
|
||||
if ((<ImportOrExportSpecifier>parent).propertyName) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isDeclaration(parent) || parent.kind === SyntaxKind.FunctionExpression) {
|
||||
return (<Declaration>parent).name === name;
|
||||
}
|
||||
|
||||
@ -3244,6 +3244,13 @@ module ts {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (symbol.flags & SymbolFlags.Import) {
|
||||
var declaration = symbol.declarations[0];
|
||||
if (node.kind === SyntaxKind.Identifier && node.parent === declaration) {
|
||||
symbol = typeInfoResolver.getAliasedSymbol(symbol);
|
||||
}
|
||||
}
|
||||
|
||||
var result: DefinitionInfo[] = [];
|
||||
|
||||
// Because name in short-hand property assignment has two different meanings: property name and property value,
|
||||
@ -4694,12 +4701,18 @@ module ts {
|
||||
}
|
||||
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
case SyntaxKind.ExportAssignment:
|
||||
case SyntaxKind.ExportDeclaration:
|
||||
return SemanticMeaning.Value | SemanticMeaning.Type | SemanticMeaning.Namespace;
|
||||
|
||||
// An external module can be a Value
|
||||
case SyntaxKind.SourceFile:
|
||||
return SemanticMeaning.Namespace | SemanticMeaning.Value;
|
||||
}
|
||||
|
||||
return SemanticMeaning.Value | SemanticMeaning.Type | SemanticMeaning.Namespace;
|
||||
|
||||
Debug.fail("Unknown declaration type");
|
||||
}
|
||||
|
||||
|
||||
13
tests/cases/fourslash/goToDefinitionExternamModuleName6.ts
Normal file
13
tests/cases/fourslash/goToDefinitionExternamModuleName6.ts
Normal file
@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
// @Filename: b.ts
|
||||
////import * from 'e/*1*/';
|
||||
|
||||
// @Filename: a.ts
|
||||
/////*2*/declare module "e" {
|
||||
//// class Foo { }
|
||||
////}
|
||||
|
||||
goTo.marker('1');
|
||||
goTo.definition();
|
||||
verify.caretAtMarker('2');
|
||||
13
tests/cases/fourslash/goToDefinitionExternamModuleName7.ts
Normal file
13
tests/cases/fourslash/goToDefinitionExternamModuleName7.ts
Normal file
@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
// @Filename: b.ts
|
||||
////import {Foo, Bar} from 'e/*1*/';
|
||||
|
||||
// @Filename: a.ts
|
||||
/////*2*/declare module "e" {
|
||||
//// class Foo { }
|
||||
////}
|
||||
|
||||
goTo.marker('1');
|
||||
goTo.definition();
|
||||
verify.caretAtMarker('2');
|
||||
13
tests/cases/fourslash/goToDefinitionExternamModuleName8.ts
Normal file
13
tests/cases/fourslash/goToDefinitionExternamModuleName8.ts
Normal file
@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
// @Filename: b.ts
|
||||
////export {Foo, Bar} from 'e/*1*/';
|
||||
|
||||
// @Filename: a.ts
|
||||
/////*2*/declare module "e" {
|
||||
//// class Foo { }
|
||||
////}
|
||||
|
||||
goTo.marker('1');
|
||||
goTo.definition();
|
||||
verify.caretAtMarker('2');
|
||||
13
tests/cases/fourslash/goToDefinitionExternamModuleName9.ts
Normal file
13
tests/cases/fourslash/goToDefinitionExternamModuleName9.ts
Normal file
@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
// @Filename: b.ts
|
||||
////export * from 'e/*1*/';
|
||||
|
||||
// @Filename: a.ts
|
||||
/////*2*/declare module "e" {
|
||||
//// class Foo { }
|
||||
////}
|
||||
|
||||
goTo.marker('1');
|
||||
goTo.definition();
|
||||
verify.caretAtMarker('2');
|
||||
21
tests/cases/fourslash/goToDefinitionImportedNames.ts
Normal file
21
tests/cases/fourslash/goToDefinitionImportedNames.ts
Normal file
@ -0,0 +1,21 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: b.ts
|
||||
////export {/*classAliasDefinition*/Class} from "a";
|
||||
|
||||
|
||||
// @Filename: a.ts
|
||||
////export module Module {
|
||||
////}
|
||||
/////*classDefinition*/export class Class {
|
||||
//// private f;
|
||||
////}
|
||||
////export interface Interface {
|
||||
//// x;
|
||||
////}
|
||||
|
||||
goTo.file("b.ts");
|
||||
|
||||
goTo.marker('classAliasDefinition');
|
||||
goTo.definition();
|
||||
verify.caretAtMarker('classDefinition');
|
||||
21
tests/cases/fourslash/goToDefinitionImportedNames2.ts
Normal file
21
tests/cases/fourslash/goToDefinitionImportedNames2.ts
Normal file
@ -0,0 +1,21 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: b.ts
|
||||
////import {/*classAliasDefinition*/Class} from "a";
|
||||
|
||||
|
||||
// @Filename: a.ts
|
||||
////export module Module {
|
||||
////}
|
||||
/////*classDefinition*/export class Class {
|
||||
//// private f;
|
||||
////}
|
||||
////export interface Interface {
|
||||
//// x;
|
||||
////}
|
||||
|
||||
goTo.file("b.ts");
|
||||
|
||||
goTo.marker('classAliasDefinition');
|
||||
goTo.definition();
|
||||
verify.caretAtMarker('classDefinition');
|
||||
38
tests/cases/fourslash/goToDefinitionImportedNames3.ts
Normal file
38
tests/cases/fourslash/goToDefinitionImportedNames3.ts
Normal file
@ -0,0 +1,38 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: e.ts
|
||||
//// import {M, /*classAliasDefinition*/C, I} from "d";
|
||||
//// var c = new /*classReference*/C();
|
||||
|
||||
|
||||
// @Filename: d.ts
|
||||
////export * from "c";
|
||||
|
||||
|
||||
// @Filename: c.ts
|
||||
////export {Module as M, Class as C, Interface as I} from "b";
|
||||
|
||||
|
||||
// @Filename: b.ts
|
||||
////export * from "a";
|
||||
|
||||
|
||||
// @Filename: a.ts
|
||||
////export module Module {
|
||||
////}
|
||||
/////*classDefinition*/export class Class {
|
||||
//// private f;
|
||||
////}
|
||||
////export interface Interface {
|
||||
//// x;
|
||||
////}
|
||||
|
||||
goTo.file("e.ts");
|
||||
|
||||
goTo.marker('classReference');
|
||||
goTo.definition();
|
||||
verify.caretAtMarker('classAliasDefinition');
|
||||
|
||||
goTo.marker('classAliasDefinition');
|
||||
goTo.definition();
|
||||
verify.caretAtMarker('classDefinition');
|
||||
21
tests/cases/fourslash/goToDefinitionImportedNames4.ts
Normal file
21
tests/cases/fourslash/goToDefinitionImportedNames4.ts
Normal file
@ -0,0 +1,21 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: b.ts
|
||||
////import {Class as /*classAliasDefinition*/ClassAlias} from "a";
|
||||
|
||||
|
||||
// @Filename: a.ts
|
||||
////export module Module {
|
||||
////}
|
||||
/////*classDefinition*/export class Class {
|
||||
//// private f;
|
||||
////}
|
||||
////export interface Interface {
|
||||
//// x;
|
||||
////}
|
||||
|
||||
goTo.file("b.ts");
|
||||
|
||||
goTo.marker('classAliasDefinition');
|
||||
goTo.definition();
|
||||
verify.caretAtMarker('classDefinition');
|
||||
21
tests/cases/fourslash/goToDefinitionImportedNames5.ts
Normal file
21
tests/cases/fourslash/goToDefinitionImportedNames5.ts
Normal file
@ -0,0 +1,21 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: b.ts
|
||||
////export {Class as /*classAliasDefinition*/ClassAlias} from "a";
|
||||
|
||||
|
||||
// @Filename: a.ts
|
||||
////export module Module {
|
||||
////}
|
||||
/////*classDefinition*/export class Class {
|
||||
//// private f;
|
||||
////}
|
||||
////export interface Interface {
|
||||
//// x;
|
||||
////}
|
||||
|
||||
goTo.file("b.ts");
|
||||
|
||||
goTo.marker('classAliasDefinition');
|
||||
goTo.definition();
|
||||
verify.caretAtMarker('classDefinition');
|
||||
21
tests/cases/fourslash/goToDefinitionImportedNames6.ts
Normal file
21
tests/cases/fourslash/goToDefinitionImportedNames6.ts
Normal file
@ -0,0 +1,21 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: b.ts
|
||||
////import /*moduleAliasDefinition*/alias = require("a");
|
||||
|
||||
|
||||
// @Filename: a.ts
|
||||
/////*moduleDefinition*/export module Module {
|
||||
////}
|
||||
////export class Class {
|
||||
//// private f;
|
||||
////}
|
||||
////export interface Interface {
|
||||
//// x;
|
||||
////}
|
||||
|
||||
goTo.file("b.ts");
|
||||
|
||||
goTo.marker('moduleAliasDefinition');
|
||||
goTo.definition();
|
||||
verify.caretAtMarker('moduleDefinition');
|
||||
19
tests/cases/fourslash/goToDefinitionImportedNames7.ts
Normal file
19
tests/cases/fourslash/goToDefinitionImportedNames7.ts
Normal file
@ -0,0 +1,19 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: b.ts
|
||||
////import /*classAliasDefinition*/defaultExport from "myLib";
|
||||
|
||||
|
||||
// @Filename: a.ts
|
||||
////module Module {
|
||||
////}
|
||||
/////*classDefinition*/class Class {
|
||||
//// private f;
|
||||
////}
|
||||
////export = Class;
|
||||
|
||||
goTo.file("b.ts");
|
||||
|
||||
goTo.marker('classAliasDefinition');
|
||||
goTo.definition();
|
||||
verify.caretAtMarker('classDefinition');
|
||||
Loading…
x
Reference in New Issue
Block a user