From c76926d1ea883e65f2a8efe1c5dfe6efbf79f730 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 12 Dec 2017 15:06:47 -0800 Subject: [PATCH 1/3] Actually get module exports and not module exports sans export stars --- src/compiler/checker.ts | 3 +- .../declarationEmitAliasExportStar.js | 44 +++++++++++++++++++ .../declarationEmitAliasExportStar.symbols | 29 ++++++++++++ .../declarationEmitAliasExportStar.types | 33 ++++++++++++++ .../declarationEmitAliasExportStar.ts | 12 +++++ 5 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/declarationEmitAliasExportStar.js create mode 100644 tests/baselines/reference/declarationEmitAliasExportStar.symbols create mode 100644 tests/baselines/reference/declarationEmitAliasExportStar.types create mode 100644 tests/cases/compiler/declarationEmitAliasExportStar.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6a1d6b52abba6..01b95ce78fab8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2216,7 +2216,8 @@ namespace ts { // Look in the exported members, if we can find accessibleSymbolChain, symbol is accessible using this chain // but only if the symbolFromSymbolTable can be qualified - const accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined; + const candidateTable = getExportsOfSymbol(resolvedImportedSymbol); + const accessibleSymbolsFromExports = candidateTable ? getAccessibleSymbolChainFromSymbolTable(candidateTable) : undefined; if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, getQualifiedLeftMeaning(meaning))) { return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports); } diff --git a/tests/baselines/reference/declarationEmitAliasExportStar.js b/tests/baselines/reference/declarationEmitAliasExportStar.js new file mode 100644 index 0000000000000..7e365e68b6624 --- /dev/null +++ b/tests/baselines/reference/declarationEmitAliasExportStar.js @@ -0,0 +1,44 @@ +//// [tests/cases/compiler/declarationEmitAliasExportStar.ts] //// + +//// [thingA.ts] +export interface ThingA { } +//// [thingB.ts] +export interface ThingB { } +//// [things.ts] +export { ThingA } from "./thingA"; +export * from "./thingB"; +//// [index.ts] +import * as things from "./things"; +export const thing1 = (param: things.ThingA) => null; +export const thing2 = (param: things.ThingB) => null; + + +//// [thingA.js] +"use strict"; +exports.__esModule = true; +//// [thingB.js] +"use strict"; +exports.__esModule = true; +//// [things.js] +"use strict"; +exports.__esModule = true; +//// [index.js] +"use strict"; +exports.__esModule = true; +exports.thing1 = function (param) { return null; }; +exports.thing2 = function (param) { return null; }; + + +//// [thingA.d.ts] +export interface ThingA { +} +//// [thingB.d.ts] +export interface ThingB { +} +//// [things.d.ts] +export { ThingA } from "./thingA"; +export * from "./thingB"; +//// [index.d.ts] +import * as things from "./things"; +export declare const thing1: (param: things.ThingA) => any; +export declare const thing2: (param: things.ThingB) => any; diff --git a/tests/baselines/reference/declarationEmitAliasExportStar.symbols b/tests/baselines/reference/declarationEmitAliasExportStar.symbols new file mode 100644 index 0000000000000..d8a5cf9e7da3f --- /dev/null +++ b/tests/baselines/reference/declarationEmitAliasExportStar.symbols @@ -0,0 +1,29 @@ +=== tests/cases/compiler/thingA.ts === +export interface ThingA { } +>ThingA : Symbol(ThingA, Decl(thingA.ts, 0, 0)) + +=== tests/cases/compiler/thingB.ts === +export interface ThingB { } +>ThingB : Symbol(ThingB, Decl(thingB.ts, 0, 0)) + +=== tests/cases/compiler/things.ts === +export { ThingA } from "./thingA"; +>ThingA : Symbol(ThingA, Decl(things.ts, 0, 8)) + +export * from "./thingB"; +=== tests/cases/compiler/index.ts === +import * as things from "./things"; +>things : Symbol(things, Decl(index.ts, 0, 6)) + +export const thing1 = (param: things.ThingA) => null; +>thing1 : Symbol(thing1, Decl(index.ts, 1, 12)) +>param : Symbol(param, Decl(index.ts, 1, 23)) +>things : Symbol(things, Decl(index.ts, 0, 6)) +>ThingA : Symbol(things.ThingA, Decl(things.ts, 0, 8)) + +export const thing2 = (param: things.ThingB) => null; +>thing2 : Symbol(thing2, Decl(index.ts, 2, 12)) +>param : Symbol(param, Decl(index.ts, 2, 23)) +>things : Symbol(things, Decl(index.ts, 0, 6)) +>ThingB : Symbol(things.ThingB, Decl(thingB.ts, 0, 0)) + diff --git a/tests/baselines/reference/declarationEmitAliasExportStar.types b/tests/baselines/reference/declarationEmitAliasExportStar.types new file mode 100644 index 0000000000000..586b1b05214cb --- /dev/null +++ b/tests/baselines/reference/declarationEmitAliasExportStar.types @@ -0,0 +1,33 @@ +=== tests/cases/compiler/thingA.ts === +export interface ThingA { } +>ThingA : ThingA + +=== tests/cases/compiler/thingB.ts === +export interface ThingB { } +>ThingB : ThingB + +=== tests/cases/compiler/things.ts === +export { ThingA } from "./thingA"; +>ThingA : any + +export * from "./thingB"; +=== tests/cases/compiler/index.ts === +import * as things from "./things"; +>things : typeof things + +export const thing1 = (param: things.ThingA) => null; +>thing1 : (param: things.ThingA) => any +>(param: things.ThingA) => null : (param: things.ThingA) => any +>param : things.ThingA +>things : any +>ThingA : things.ThingA +>null : null + +export const thing2 = (param: things.ThingB) => null; +>thing2 : (param: things.ThingB) => any +>(param: things.ThingB) => null : (param: things.ThingB) => any +>param : things.ThingB +>things : any +>ThingB : things.ThingB +>null : null + diff --git a/tests/cases/compiler/declarationEmitAliasExportStar.ts b/tests/cases/compiler/declarationEmitAliasExportStar.ts new file mode 100644 index 0000000000000..1c6711d3d893a --- /dev/null +++ b/tests/cases/compiler/declarationEmitAliasExportStar.ts @@ -0,0 +1,12 @@ +// @declaration: true +// @filename: thingA.ts +export interface ThingA { } +// @filename: thingB.ts +export interface ThingB { } +// @filename: things.ts +export { ThingA } from "./thingA"; +export * from "./thingB"; +// @filename: index.ts +import * as things from "./things"; +export const thing1 = (param: things.ThingA) => null; +export const thing2 = (param: things.ThingB) => null; From fa927e5edf18e028ae1df6521bf1fcd27795d194 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 13 Dec 2017 12:55:02 -0800 Subject: [PATCH 2/3] style update --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 01b95ce78fab8..c5dd0090c1784 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2217,7 +2217,7 @@ namespace ts { // Look in the exported members, if we can find accessibleSymbolChain, symbol is accessible using this chain // but only if the symbolFromSymbolTable can be qualified const candidateTable = getExportsOfSymbol(resolvedImportedSymbol); - const accessibleSymbolsFromExports = candidateTable ? getAccessibleSymbolChainFromSymbolTable(candidateTable) : undefined; + const accessibleSymbolsFromExports = candidateTable && getAccessibleSymbolChainFromSymbolTable(candidateTable); if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, getQualifiedLeftMeaning(meaning))) { return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports); } From 4c7ddcd7e0dbea2ed9a064e0035cbd3a6a359cd7 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 13 Dec 2017 13:04:10 -0800 Subject: [PATCH 3/3] Trim test a bit --- .../declarationEmitAliasExportStar.js | 13 ------------- .../declarationEmitAliasExportStar.symbols | 19 +++---------------- .../declarationEmitAliasExportStar.types | 17 +---------------- .../declarationEmitAliasExportStar.ts | 4 ---- 4 files changed, 4 insertions(+), 49 deletions(-) diff --git a/tests/baselines/reference/declarationEmitAliasExportStar.js b/tests/baselines/reference/declarationEmitAliasExportStar.js index 7e365e68b6624..a7f8932cbf993 100644 --- a/tests/baselines/reference/declarationEmitAliasExportStar.js +++ b/tests/baselines/reference/declarationEmitAliasExportStar.js @@ -1,21 +1,14 @@ //// [tests/cases/compiler/declarationEmitAliasExportStar.ts] //// -//// [thingA.ts] -export interface ThingA { } //// [thingB.ts] export interface ThingB { } //// [things.ts] -export { ThingA } from "./thingA"; export * from "./thingB"; //// [index.ts] import * as things from "./things"; -export const thing1 = (param: things.ThingA) => null; export const thing2 = (param: things.ThingB) => null; -//// [thingA.js] -"use strict"; -exports.__esModule = true; //// [thingB.js] "use strict"; exports.__esModule = true; @@ -25,20 +18,14 @@ exports.__esModule = true; //// [index.js] "use strict"; exports.__esModule = true; -exports.thing1 = function (param) { return null; }; exports.thing2 = function (param) { return null; }; -//// [thingA.d.ts] -export interface ThingA { -} //// [thingB.d.ts] export interface ThingB { } //// [things.d.ts] -export { ThingA } from "./thingA"; export * from "./thingB"; //// [index.d.ts] import * as things from "./things"; -export declare const thing1: (param: things.ThingA) => any; export declare const thing2: (param: things.ThingB) => any; diff --git a/tests/baselines/reference/declarationEmitAliasExportStar.symbols b/tests/baselines/reference/declarationEmitAliasExportStar.symbols index d8a5cf9e7da3f..8f86cf3dc8cdb 100644 --- a/tests/baselines/reference/declarationEmitAliasExportStar.symbols +++ b/tests/baselines/reference/declarationEmitAliasExportStar.symbols @@ -1,29 +1,16 @@ -=== tests/cases/compiler/thingA.ts === -export interface ThingA { } ->ThingA : Symbol(ThingA, Decl(thingA.ts, 0, 0)) - === tests/cases/compiler/thingB.ts === export interface ThingB { } >ThingB : Symbol(ThingB, Decl(thingB.ts, 0, 0)) === tests/cases/compiler/things.ts === -export { ThingA } from "./thingA"; ->ThingA : Symbol(ThingA, Decl(things.ts, 0, 8)) - export * from "./thingB"; -=== tests/cases/compiler/index.ts === +No type information for this code.=== tests/cases/compiler/index.ts === import * as things from "./things"; >things : Symbol(things, Decl(index.ts, 0, 6)) -export const thing1 = (param: things.ThingA) => null; ->thing1 : Symbol(thing1, Decl(index.ts, 1, 12)) ->param : Symbol(param, Decl(index.ts, 1, 23)) ->things : Symbol(things, Decl(index.ts, 0, 6)) ->ThingA : Symbol(things.ThingA, Decl(things.ts, 0, 8)) - export const thing2 = (param: things.ThingB) => null; ->thing2 : Symbol(thing2, Decl(index.ts, 2, 12)) ->param : Symbol(param, Decl(index.ts, 2, 23)) +>thing2 : Symbol(thing2, Decl(index.ts, 1, 12)) +>param : Symbol(param, Decl(index.ts, 1, 23)) >things : Symbol(things, Decl(index.ts, 0, 6)) >ThingB : Symbol(things.ThingB, Decl(thingB.ts, 0, 0)) diff --git a/tests/baselines/reference/declarationEmitAliasExportStar.types b/tests/baselines/reference/declarationEmitAliasExportStar.types index 586b1b05214cb..30be7c9ff28a1 100644 --- a/tests/baselines/reference/declarationEmitAliasExportStar.types +++ b/tests/baselines/reference/declarationEmitAliasExportStar.types @@ -1,28 +1,13 @@ -=== tests/cases/compiler/thingA.ts === -export interface ThingA { } ->ThingA : ThingA - === tests/cases/compiler/thingB.ts === export interface ThingB { } >ThingB : ThingB === tests/cases/compiler/things.ts === -export { ThingA } from "./thingA"; ->ThingA : any - export * from "./thingB"; -=== tests/cases/compiler/index.ts === +No type information for this code.=== tests/cases/compiler/index.ts === import * as things from "./things"; >things : typeof things -export const thing1 = (param: things.ThingA) => null; ->thing1 : (param: things.ThingA) => any ->(param: things.ThingA) => null : (param: things.ThingA) => any ->param : things.ThingA ->things : any ->ThingA : things.ThingA ->null : null - export const thing2 = (param: things.ThingB) => null; >thing2 : (param: things.ThingB) => any >(param: things.ThingB) => null : (param: things.ThingB) => any diff --git a/tests/cases/compiler/declarationEmitAliasExportStar.ts b/tests/cases/compiler/declarationEmitAliasExportStar.ts index 1c6711d3d893a..f556e35aa0b20 100644 --- a/tests/cases/compiler/declarationEmitAliasExportStar.ts +++ b/tests/cases/compiler/declarationEmitAliasExportStar.ts @@ -1,12 +1,8 @@ // @declaration: true -// @filename: thingA.ts -export interface ThingA { } // @filename: thingB.ts export interface ThingB { } // @filename: things.ts -export { ThingA } from "./thingA"; export * from "./thingB"; // @filename: index.ts import * as things from "./things"; -export const thing1 = (param: things.ThingA) => null; export const thing2 = (param: things.ThingB) => null;