Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get resolved module exports in symbol chain and not raw exports #20661

Merged
merged 3 commits into from
Dec 13, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Good place to use && instead of ?:

if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, getQualifiedLeftMeaning(meaning))) {
return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports);
}
Expand Down
44 changes: 44 additions & 0 deletions tests/baselines/reference/declarationEmitAliasExportStar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//// [tests/cases/compiler/declarationEmitAliasExportStar.ts] ////

//// [thingA.ts]
export interface ThingA { }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can reproduce the error without ThingA:
a.ts

export interface I { }

b.ts

export * from "./a";

c.ts

import * as b from "./b";
export const f = (_: b.I) => {};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. I included ThingA in my issue report only to illustrate the difference between #19852 and #20657. No need to include it in the test.

//// [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;
29 changes: 29 additions & 0 deletions tests/baselines/reference/declarationEmitAliasExportStar.symbols
Original file line number Diff line number Diff line change
@@ -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))

33 changes: 33 additions & 0 deletions tests/baselines/reference/declarationEmitAliasExportStar.types
Original file line number Diff line number Diff line change
@@ -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

12 changes: 12 additions & 0 deletions tests/cases/compiler/declarationEmitAliasExportStar.ts
Original file line number Diff line number Diff line change
@@ -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;