Skip to content

Commit 490dfef

Browse files
Merge pull request #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

Lines changed: 5 additions & 12 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 13 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 5 additions & 6 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 5 additions & 6 deletions
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

Lines changed: 5 additions & 6 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 5 additions & 6 deletions
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 {

0 commit comments

Comments
 (0)