Skip to content

Commit 490dfef

Browse files
Merge pull request microsoft#2485 from Microsoft/transitiveExports
Fix completion lists for transitive exports
2 parents 8bf61c7 + 3290814 commit 490dfef

16 files changed

+208
-55
lines changed

src/compiler/checker.ts

+5-12
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ module ts {
7474
isImplementationOfOverload,
7575
getAliasedSymbol: resolveAlias,
7676
getEmitResolver,
77-
getExportsOfExternalModule,
77+
getExportsOfModule: getExportsOfModuleAsArray,
7878
};
7979

8080
let unknownSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "unknown");
@@ -898,6 +898,10 @@ module ts {
898898
return moduleSymbol.exports["export="];
899899
}
900900

901+
function getExportsOfModuleAsArray(moduleSymbol: Symbol): Symbol[] {
902+
return symbolsToArray(getExportsOfModule(moduleSymbol));
903+
}
904+
901905
function getExportsOfSymbol(symbol: Symbol): SymbolTable {
902906
return symbol.flags & SymbolFlags.Module ? getExportsOfModule(symbol) : symbol.exports || emptySymbols;
903907
}
@@ -3032,17 +3036,6 @@ module ts {
30323036
return result;
30333037
}
30343038

3035-
function getExportsOfExternalModule(node: ImportDeclaration): Symbol[] {
3036-
if (!node.moduleSpecifier) {
3037-
return emptyArray;
3038-
}
3039-
let module = resolveExternalModuleName(node, node.moduleSpecifier);
3040-
if (!module) {
3041-
return emptyArray;
3042-
}
3043-
return symbolsToArray(getExportsOfModule(module));
3044-
}
3045-
30463039
function getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature {
30473040
let links = getNodeLinks(declaration);
30483041
if (!links.resolvedSignature) {

src/compiler/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ module ts {
933933
// import "mod" => importClause = undefined, moduleSpecifier = "mod"
934934
// In rest of the cases, module specifier is string literal corresponding to module
935935
// ImportClause information is shown at its declaration below.
936-
export interface ImportDeclaration extends Statement, ModuleElement {
936+
export interface ImportDeclaration extends ModuleElement {
937937
importClause?: ImportClause;
938938
moduleSpecifier: Expression;
939939
}
@@ -1146,7 +1146,7 @@ module ts {
11461146
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
11471147
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
11481148
getAliasedSymbol(symbol: Symbol): Symbol;
1149-
getExportsOfExternalModule(node: ImportDeclaration): Symbol[];
1149+
getExportsOfModule(moduleSymbol: Symbol): Symbol[];
11501150

11511151
// Should not be called directly. Should only be accessed through the Program instance.
11521152
/* @internal */ getDiagnostics(sourceFile?: SourceFile): Diagnostic[];

src/services/services.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -2598,7 +2598,8 @@ module ts {
25982598

25992599
if (symbol && symbol.flags & SymbolFlags.HasExports) {
26002600
// Extract module or enum members
2601-
forEachValue(symbol.exports, symbol => {
2601+
let exportedSymbols = typeInfoResolver.getExportsOfModule(symbol);
2602+
forEach(exportedSymbols, symbol => {
26022603
if (typeInfoResolver.isValidPropertyAccess(<PropertyAccessExpression>(node.parent), symbol.name)) {
26032604
symbols.push(symbol);
26042605
}
@@ -2642,8 +2643,17 @@ module ts {
26422643
if (showCompletionsInImportsClause(contextToken)) {
26432644
let importDeclaration = <ImportDeclaration>getAncestor(contextToken, SyntaxKind.ImportDeclaration);
26442645
Debug.assert(importDeclaration !== undefined);
2645-
let exports = typeInfoResolver.getExportsOfExternalModule(importDeclaration);
2646-
symbols = filterModuleExports(exports, importDeclaration);
2646+
2647+
let exports: Symbol[];
2648+
if (importDeclaration.moduleSpecifier) {
2649+
let moduleSpecifierSymbol = typeInfoResolver.getSymbolAtLocation(importDeclaration.moduleSpecifier);
2650+
if (moduleSpecifierSymbol) {
2651+
exports = typeInfoResolver.getExportsOfModule(moduleSpecifierSymbol);
2652+
}
2653+
}
2654+
2655+
//let exports = typeInfoResolver.getExportsOfImportDeclaration(importDeclaration);
2656+
symbols = exports ? filterModuleExports(exports, importDeclaration) : emptyArray;
26472657
}
26482658
}
26492659
else {

tests/baselines/reference/APISample_compile.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ declare module "typescript" {
760760
interface ExternalModuleReference extends Node {
761761
expression?: Expression;
762762
}
763-
interface ImportDeclaration extends Statement, ModuleElement {
763+
interface ImportDeclaration extends ModuleElement {
764764
importClause?: ImportClause;
765765
moduleSpecifier: Expression;
766766
}
@@ -902,7 +902,7 @@ declare module "typescript" {
902902
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
903903
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
904904
getAliasedSymbol(symbol: Symbol): Symbol;
905-
getExportsOfExternalModule(node: ImportDeclaration): Symbol[];
905+
getExportsOfModule(moduleSymbol: Symbol): Symbol[];
906906
}
907907
interface SymbolDisplayBuilder {
908908
buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;

tests/baselines/reference/APISample_compile.types

+5-6
Original file line numberDiff line numberDiff line change
@@ -2307,9 +2307,8 @@ declare module "typescript" {
23072307
>expression : Expression
23082308
>Expression : Expression
23092309
}
2310-
interface ImportDeclaration extends Statement, ModuleElement {
2310+
interface ImportDeclaration extends ModuleElement {
23112311
>ImportDeclaration : ImportDeclaration
2312-
>Statement : Statement
23132312
>ModuleElement : ModuleElement
23142313

23152314
importClause?: ImportClause;
@@ -2818,10 +2817,10 @@ declare module "typescript" {
28182817
>Symbol : Symbol
28192818
>Symbol : Symbol
28202819

2821-
getExportsOfExternalModule(node: ImportDeclaration): Symbol[];
2822-
>getExportsOfExternalModule : (node: ImportDeclaration) => Symbol[]
2823-
>node : ImportDeclaration
2824-
>ImportDeclaration : ImportDeclaration
2820+
getExportsOfModule(moduleSymbol: Symbol): Symbol[];
2821+
>getExportsOfModule : (moduleSymbol: Symbol) => Symbol[]
2822+
>moduleSymbol : Symbol
2823+
>Symbol : Symbol
28252824
>Symbol : Symbol
28262825
}
28272826
interface SymbolDisplayBuilder {

tests/baselines/reference/APISample_linter.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ declare module "typescript" {
791791
interface ExternalModuleReference extends Node {
792792
expression?: Expression;
793793
}
794-
interface ImportDeclaration extends Statement, ModuleElement {
794+
interface ImportDeclaration extends ModuleElement {
795795
importClause?: ImportClause;
796796
moduleSpecifier: Expression;
797797
}
@@ -933,7 +933,7 @@ declare module "typescript" {
933933
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
934934
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
935935
getAliasedSymbol(symbol: Symbol): Symbol;
936-
getExportsOfExternalModule(node: ImportDeclaration): Symbol[];
936+
getExportsOfModule(moduleSymbol: Symbol): Symbol[];
937937
}
938938
interface SymbolDisplayBuilder {
939939
buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;

tests/baselines/reference/APISample_linter.types

+5-6
Original file line numberDiff line numberDiff line change
@@ -2453,9 +2453,8 @@ declare module "typescript" {
24532453
>expression : Expression
24542454
>Expression : Expression
24552455
}
2456-
interface ImportDeclaration extends Statement, ModuleElement {
2456+
interface ImportDeclaration extends ModuleElement {
24572457
>ImportDeclaration : ImportDeclaration
2458-
>Statement : Statement
24592458
>ModuleElement : ModuleElement
24602459

24612460
importClause?: ImportClause;
@@ -2964,10 +2963,10 @@ declare module "typescript" {
29642963
>Symbol : Symbol
29652964
>Symbol : Symbol
29662965

2967-
getExportsOfExternalModule(node: ImportDeclaration): Symbol[];
2968-
>getExportsOfExternalModule : (node: ImportDeclaration) => Symbol[]
2969-
>node : ImportDeclaration
2970-
>ImportDeclaration : ImportDeclaration
2966+
getExportsOfModule(moduleSymbol: Symbol): Symbol[];
2967+
>getExportsOfModule : (moduleSymbol: Symbol) => Symbol[]
2968+
>moduleSymbol : Symbol
2969+
>Symbol : Symbol
29712970
>Symbol : Symbol
29722971
}
29732972
interface SymbolDisplayBuilder {

tests/baselines/reference/APISample_linter.types.pull

+5-6
Original file line numberDiff line numberDiff line change
@@ -2453,9 +2453,8 @@ declare module "typescript" {
24532453
>expression : Expression
24542454
>Expression : Expression
24552455
}
2456-
interface ImportDeclaration extends Statement, ModuleElement {
2456+
interface ImportDeclaration extends ModuleElement {
24572457
>ImportDeclaration : ImportDeclaration
2458-
>Statement : Statement
24592458
>ModuleElement : ModuleElement
24602459

24612460
importClause?: ImportClause;
@@ -2964,10 +2963,10 @@ declare module "typescript" {
29642963
>Symbol : Symbol
29652964
>Symbol : Symbol
29662965

2967-
getExportsOfExternalModule(node: ImportDeclaration): Symbol[];
2968-
>getExportsOfExternalModule : (node: ImportDeclaration) => Symbol[]
2969-
>node : ImportDeclaration
2970-
>ImportDeclaration : ImportDeclaration
2966+
getExportsOfModule(moduleSymbol: Symbol): Symbol[];
2967+
>getExportsOfModule : (moduleSymbol: Symbol) => Symbol[]
2968+
>moduleSymbol : Symbol
2969+
>Symbol : Symbol
29712970
>Symbol : Symbol
29722971
}
29732972
interface SymbolDisplayBuilder {

tests/baselines/reference/APISample_transform.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ declare module "typescript" {
792792
interface ExternalModuleReference extends Node {
793793
expression?: Expression;
794794
}
795-
interface ImportDeclaration extends Statement, ModuleElement {
795+
interface ImportDeclaration extends ModuleElement {
796796
importClause?: ImportClause;
797797
moduleSpecifier: Expression;
798798
}
@@ -934,7 +934,7 @@ declare module "typescript" {
934934
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
935935
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
936936
getAliasedSymbol(symbol: Symbol): Symbol;
937-
getExportsOfExternalModule(node: ImportDeclaration): Symbol[];
937+
getExportsOfModule(moduleSymbol: Symbol): Symbol[];
938938
}
939939
interface SymbolDisplayBuilder {
940940
buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;

tests/baselines/reference/APISample_transform.types

+5-6
Original file line numberDiff line numberDiff line change
@@ -2403,9 +2403,8 @@ declare module "typescript" {
24032403
>expression : Expression
24042404
>Expression : Expression
24052405
}
2406-
interface ImportDeclaration extends Statement, ModuleElement {
2406+
interface ImportDeclaration extends ModuleElement {
24072407
>ImportDeclaration : ImportDeclaration
2408-
>Statement : Statement
24092408
>ModuleElement : ModuleElement
24102409

24112410
importClause?: ImportClause;
@@ -2914,10 +2913,10 @@ declare module "typescript" {
29142913
>Symbol : Symbol
29152914
>Symbol : Symbol
29162915

2917-
getExportsOfExternalModule(node: ImportDeclaration): Symbol[];
2918-
>getExportsOfExternalModule : (node: ImportDeclaration) => Symbol[]
2919-
>node : ImportDeclaration
2920-
>ImportDeclaration : ImportDeclaration
2916+
getExportsOfModule(moduleSymbol: Symbol): Symbol[];
2917+
>getExportsOfModule : (moduleSymbol: Symbol) => Symbol[]
2918+
>moduleSymbol : Symbol
2919+
>Symbol : Symbol
29212920
>Symbol : Symbol
29222921
}
29232922
interface SymbolDisplayBuilder {

tests/baselines/reference/APISample_watcher.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ declare module "typescript" {
829829
interface ExternalModuleReference extends Node {
830830
expression?: Expression;
831831
}
832-
interface ImportDeclaration extends Statement, ModuleElement {
832+
interface ImportDeclaration extends ModuleElement {
833833
importClause?: ImportClause;
834834
moduleSpecifier: Expression;
835835
}
@@ -971,7 +971,7 @@ declare module "typescript" {
971971
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
972972
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
973973
getAliasedSymbol(symbol: Symbol): Symbol;
974-
getExportsOfExternalModule(node: ImportDeclaration): Symbol[];
974+
getExportsOfModule(moduleSymbol: Symbol): Symbol[];
975975
}
976976
interface SymbolDisplayBuilder {
977977
buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;

tests/baselines/reference/APISample_watcher.types

+5-6
Original file line numberDiff line numberDiff line change
@@ -2576,9 +2576,8 @@ declare module "typescript" {
25762576
>expression : Expression
25772577
>Expression : Expression
25782578
}
2579-
interface ImportDeclaration extends Statement, ModuleElement {
2579+
interface ImportDeclaration extends ModuleElement {
25802580
>ImportDeclaration : ImportDeclaration
2581-
>Statement : Statement
25822581
>ModuleElement : ModuleElement
25832582

25842583
importClause?: ImportClause;
@@ -3087,10 +3086,10 @@ declare module "typescript" {
30873086
>Symbol : Symbol
30883087
>Symbol : Symbol
30893088

3090-
getExportsOfExternalModule(node: ImportDeclaration): Symbol[];
3091-
>getExportsOfExternalModule : (node: ImportDeclaration) => Symbol[]
3092-
>node : ImportDeclaration
3093-
>ImportDeclaration : ImportDeclaration
3089+
getExportsOfModule(moduleSymbol: Symbol): Symbol[];
3090+
>getExportsOfModule : (moduleSymbol: Symbol) => Symbol[]
3091+
>moduleSymbol : Symbol
3092+
>Symbol : Symbol
30943093
>Symbol : Symbol
30953094
}
30963095
interface SymbolDisplayBuilder {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
///<reference path="fourslash.ts" />
2+
3+
// @Filename: A.ts
4+
////export interface I1 { one: number }
5+
////export interface I2 { two: string }
6+
////export type I1_OR_I2 = I1 | I2;
7+
////
8+
////export class C1 {
9+
//// one: string;
10+
////}
11+
////
12+
////export module Inner {
13+
//// export interface I3 {
14+
//// three: boolean
15+
//// }
16+
////
17+
//// export var varVar = 100;
18+
//// export let letVar = 200;
19+
//// export const constVar = 300;
20+
////}
21+
22+
// @Filename: B.ts
23+
////export var bVar = "bee!";
24+
25+
// @Filename: C.ts
26+
////export var cVar = "see!";
27+
////export * from "A";
28+
////export * from "B"
29+
30+
// @Filename: D.ts
31+
////import * as c from "C";
32+
////var x = c./**/
33+
34+
goTo.marker();
35+
verify.completionListContains("C1");
36+
verify.completionListContains("Inner");
37+
verify.completionListContains("bVar");
38+
verify.completionListContains("cVar");
39+
verify.not.completionListContains("__export");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
///<reference path="fourslash.ts" />
2+
3+
4+
// @Filename: A.ts
5+
////export interface I1 { one: number }
6+
////export interface I2 { two: string }
7+
////export type I1_OR_I2 = I1 | I2;
8+
////
9+
////export class C1 {
10+
//// one: string;
11+
////}
12+
////
13+
////export module Inner {
14+
//// export interface I3 {
15+
//// three: boolean
16+
//// }
17+
////
18+
//// export var varVar = 100;
19+
//// export let letVar = 200;
20+
//// export const constVar = 300;
21+
////}
22+
23+
// @Filename: B.ts
24+
////export var bVar = "bee!";
25+
26+
// @Filename: C.ts
27+
////export var cVar = "see!";
28+
////export * from "A";
29+
////export * from "B"
30+
31+
// @Filename: D.ts
32+
////import * as c from "C";
33+
////var x = c.Inner./**/
34+
35+
goTo.marker();
36+
verify.completionListContains("varVar");
37+
verify.completionListContains("letVar");
38+
verify.completionListContains("constVar");
39+
verify.not.completionListContains("__export");

0 commit comments

Comments
 (0)