diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index acb90c4767b..1a20940741d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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) && + (node.parent).moduleSpecifier === node)) { + return resolveExternalModuleName(node, node); } // Intentional fall-through diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index c5bb46aa962..b53c0007248 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -745,6 +745,12 @@ module ts { } var parent = name.parent; + if (parent.kind === SyntaxKind.ImportSpecifier || parent.kind === SyntaxKind.ExportSpecifier) { + if ((parent).propertyName) { + return true; + } + } + if (isDeclaration(parent) || parent.kind === SyntaxKind.FunctionExpression) { return (parent).name === name; } diff --git a/src/services/services.ts b/src/services/services.ts index e3d8923890b..79d27517369 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -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"); } diff --git a/tests/cases/fourslash/goToDefinitionExternamModuleName6.ts b/tests/cases/fourslash/goToDefinitionExternamModuleName6.ts new file mode 100644 index 00000000000..46cafbb806c --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionExternamModuleName6.ts @@ -0,0 +1,13 @@ +/// + +// @Filename: b.ts +////import * from 'e/*1*/'; + +// @Filename: a.ts +/////*2*/declare module "e" { +//// class Foo { } +////} + +goTo.marker('1'); +goTo.definition(); +verify.caretAtMarker('2'); \ No newline at end of file diff --git a/tests/cases/fourslash/goToDefinitionExternamModuleName7.ts b/tests/cases/fourslash/goToDefinitionExternamModuleName7.ts new file mode 100644 index 00000000000..dcaf4b1f021 --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionExternamModuleName7.ts @@ -0,0 +1,13 @@ +/// + +// @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'); \ No newline at end of file diff --git a/tests/cases/fourslash/goToDefinitionExternamModuleName8.ts b/tests/cases/fourslash/goToDefinitionExternamModuleName8.ts new file mode 100644 index 00000000000..03c36567dc0 --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionExternamModuleName8.ts @@ -0,0 +1,13 @@ +/// + +// @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'); \ No newline at end of file diff --git a/tests/cases/fourslash/goToDefinitionExternamModuleName9.ts b/tests/cases/fourslash/goToDefinitionExternamModuleName9.ts new file mode 100644 index 00000000000..43111c6763f --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionExternamModuleName9.ts @@ -0,0 +1,13 @@ +/// + +// @Filename: b.ts +////export * from 'e/*1*/'; + +// @Filename: a.ts +/////*2*/declare module "e" { +//// class Foo { } +////} + +goTo.marker('1'); +goTo.definition(); +verify.caretAtMarker('2'); \ No newline at end of file diff --git a/tests/cases/fourslash/goToDefinitionImportedNames.ts b/tests/cases/fourslash/goToDefinitionImportedNames.ts new file mode 100644 index 00000000000..64eb2df96bf --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionImportedNames.ts @@ -0,0 +1,21 @@ +/// + +// @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'); diff --git a/tests/cases/fourslash/goToDefinitionImportedNames2.ts b/tests/cases/fourslash/goToDefinitionImportedNames2.ts new file mode 100644 index 00000000000..8533dad62a8 --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionImportedNames2.ts @@ -0,0 +1,21 @@ +/// + +// @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'); diff --git a/tests/cases/fourslash/goToDefinitionImportedNames3.ts b/tests/cases/fourslash/goToDefinitionImportedNames3.ts new file mode 100644 index 00000000000..d55137575ef --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionImportedNames3.ts @@ -0,0 +1,38 @@ +/// + +// @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'); diff --git a/tests/cases/fourslash/goToDefinitionImportedNames4.ts b/tests/cases/fourslash/goToDefinitionImportedNames4.ts new file mode 100644 index 00000000000..cce49af874b --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionImportedNames4.ts @@ -0,0 +1,21 @@ +/// + +// @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'); diff --git a/tests/cases/fourslash/goToDefinitionImportedNames5.ts b/tests/cases/fourslash/goToDefinitionImportedNames5.ts new file mode 100644 index 00000000000..46a8c45e272 --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionImportedNames5.ts @@ -0,0 +1,21 @@ +/// + +// @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'); diff --git a/tests/cases/fourslash/goToDefinitionImportedNames6.ts b/tests/cases/fourslash/goToDefinitionImportedNames6.ts new file mode 100644 index 00000000000..27b6c55d107 --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionImportedNames6.ts @@ -0,0 +1,21 @@ +/// + +// @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'); diff --git a/tests/cases/fourslash/goToDefinitionImportedNames7.ts b/tests/cases/fourslash/goToDefinitionImportedNames7.ts new file mode 100644 index 00000000000..de77b935fcd --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionImportedNames7.ts @@ -0,0 +1,19 @@ +/// + +// @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');