Dont consider export specifiers visible in their local scope (#26884)

This commit is contained in:
Wesley Wigham
2018-09-04 16:00:10 -07:00
committed by GitHub
parent f1370ecd54
commit ca662419e8
22 changed files with 224 additions and 75 deletions

View File

@@ -2748,7 +2748,11 @@ namespace ts {
&& symbolFromSymbolTable.escapedName !== InternalSymbolName.Default
&& !(isUMDExportSymbol(symbolFromSymbolTable) && enclosingDeclaration && isExternalModule(getSourceFileOfNode(enclosingDeclaration)))
// If `!useOnlyExternalAliasing`, we can use any type of alias to get the name
&& (!useOnlyExternalAliasing || some(symbolFromSymbolTable.declarations, isExternalModuleImportEqualsDeclaration))) {
&& (!useOnlyExternalAliasing || some(symbolFromSymbolTable.declarations, isExternalModuleImportEqualsDeclaration))
// While exports are generally considered to be in scope, export-specifier declared symbols are _not_
// See similar comment in `resolveName` for details
&& (ignoreQualification || !getDeclarationOfKind(symbolFromSymbolTable, SyntaxKind.ExportSpecifier))
) {
const resolvedImportedSymbol = resolveAlias(symbolFromSymbolTable);
if (isAccessible(symbolFromSymbolTable, resolvedImportedSymbol, ignoreQualification)) {

View File

@@ -0,0 +1,46 @@
//// [tests/cases/compiler/declarationEmitExportAliasVisibiilityMarking.ts] ////
//// [Types.ts]
type Suit = 'Hearts' | 'Spades' | 'Clubs' | 'Diamonds';
type Rank = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 'Jack' | 'Queen' | 'King';
export { Suit, Rank };
//// [Card.ts]
import { Suit, Rank } from './Types';
export default (suit: Suit, rank: Rank) => ({suit, rank});
//// [index.ts]
export let lazyCard = () => import('./Card').then(a => a.default);
export { Suit, Rank } from './Types';
//// [Types.js]
"use strict";
exports.__esModule = true;
//// [Card.js]
"use strict";
exports.__esModule = true;
exports["default"] = (function (suit, rank) { return ({ suit: suit, rank: rank }); });
//// [index.js]
"use strict";
exports.__esModule = true;
exports.lazyCard = function () { return Promise.resolve().then(function () { return require('./Card'); }).then(function (a) { return a["default"]; }); };
//// [Types.d.ts]
declare type Suit = 'Hearts' | 'Spades' | 'Clubs' | 'Diamonds';
declare type Rank = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 'Jack' | 'Queen' | 'King';
export { Suit, Rank };
//// [Card.d.ts]
import { Suit, Rank } from './Types';
declare const _default: (suit: Suit, rank: Rank) => {
suit: Suit;
rank: Rank;
};
export default _default;
//// [index.d.ts]
export declare let lazyCard: () => Promise<(suit: import("./Types").Suit, rank: import("./Types").Rank) => {
suit: import("./Types").Suit;
rank: import("./Types").Rank;
}>;
export { Suit, Rank } from './Types';

View File

@@ -0,0 +1,39 @@
=== tests/cases/compiler/Types.ts ===
type Suit = 'Hearts' | 'Spades' | 'Clubs' | 'Diamonds';
>Suit : Symbol(Suit, Decl(Types.ts, 0, 0))
type Rank = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 'Jack' | 'Queen' | 'King';
>Rank : Symbol(Rank, Decl(Types.ts, 0, 55))
export { Suit, Rank };
>Suit : Symbol(Suit, Decl(Types.ts, 2, 8))
>Rank : Symbol(Rank, Decl(Types.ts, 2, 14))
=== tests/cases/compiler/Card.ts ===
import { Suit, Rank } from './Types';
>Suit : Symbol(Suit, Decl(Card.ts, 0, 8))
>Rank : Symbol(Rank, Decl(Card.ts, 0, 14))
export default (suit: Suit, rank: Rank) => ({suit, rank});
>suit : Symbol(suit, Decl(Card.ts, 1, 16))
>Suit : Symbol(Suit, Decl(Card.ts, 0, 8))
>rank : Symbol(rank, Decl(Card.ts, 1, 27))
>Rank : Symbol(Rank, Decl(Card.ts, 0, 14))
>suit : Symbol(suit, Decl(Card.ts, 1, 45))
>rank : Symbol(rank, Decl(Card.ts, 1, 50))
=== tests/cases/compiler/index.ts ===
export let lazyCard = () => import('./Card').then(a => a.default);
>lazyCard : Symbol(lazyCard, Decl(index.ts, 0, 10))
>import('./Card').then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
>'./Card' : Symbol("tests/cases/compiler/Card", Decl(Card.ts, 0, 0))
>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
>a : Symbol(a, Decl(index.ts, 0, 50))
>a.default : Symbol(default, Decl(Card.ts, 0, 37))
>a : Symbol(a, Decl(index.ts, 0, 50))
>default : Symbol(default, Decl(Card.ts, 0, 37))
export { Suit, Rank } from './Types';
>Suit : Symbol(Suit, Decl(index.ts, 1, 8))
>Rank : Symbol(Rank, Decl(index.ts, 1, 14))

View File

@@ -0,0 +1,44 @@
=== tests/cases/compiler/Types.ts ===
type Suit = 'Hearts' | 'Spades' | 'Clubs' | 'Diamonds';
>Suit : Suit
type Rank = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 'Jack' | 'Queen' | 'King';
>Rank : Rank
export { Suit, Rank };
>Suit : any
>Rank : any
=== tests/cases/compiler/Card.ts ===
import { Suit, Rank } from './Types';
>Suit : any
>Rank : any
export default (suit: Suit, rank: Rank) => ({suit, rank});
>(suit: Suit, rank: Rank) => ({suit, rank}) : (suit: Suit, rank: Rank) => { suit: Suit; rank: Rank; }
>suit : Suit
>rank : Rank
>({suit, rank}) : { suit: Suit; rank: Rank; }
>{suit, rank} : { suit: Suit; rank: Rank; }
>suit : Suit
>rank : Rank
=== tests/cases/compiler/index.ts ===
export let lazyCard = () => import('./Card').then(a => a.default);
>lazyCard : () => Promise<(suit: import("tests/cases/compiler/Types").Suit, rank: import("tests/cases/compiler/Types").Rank) => { suit: import("tests/cases/compiler/Types").Suit; rank: import("tests/cases/compiler/Types").Rank; }>
>() => import('./Card').then(a => a.default) : () => Promise<(suit: import("tests/cases/compiler/Types").Suit, rank: import("tests/cases/compiler/Types").Rank) => { suit: import("tests/cases/compiler/Types").Suit; rank: import("tests/cases/compiler/Types").Rank; }>
>import('./Card').then(a => a.default) : Promise<(suit: import("tests/cases/compiler/Types").Suit, rank: import("tests/cases/compiler/Types").Rank) => { suit: import("tests/cases/compiler/Types").Suit; rank: import("tests/cases/compiler/Types").Rank; }>
>import('./Card').then : <TResult1 = typeof import("tests/cases/compiler/Card"), TResult2 = never>(onfulfilled?: (value: typeof import("tests/cases/compiler/Card")) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
>import('./Card') : Promise<typeof import("tests/cases/compiler/Card")>
>'./Card' : "./Card"
>then : <TResult1 = typeof import("tests/cases/compiler/Card"), TResult2 = never>(onfulfilled?: (value: typeof import("tests/cases/compiler/Card")) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
>a => a.default : (a: typeof import("tests/cases/compiler/Card")) => (suit: import("tests/cases/compiler/Types").Suit, rank: import("tests/cases/compiler/Types").Rank) => { suit: import("tests/cases/compiler/Types").Suit; rank: import("tests/cases/compiler/Types").Rank; }
>a : typeof import("tests/cases/compiler/Card")
>a.default : (suit: import("tests/cases/compiler/Types").Suit, rank: import("tests/cases/compiler/Types").Rank) => { suit: import("tests/cases/compiler/Types").Suit; rank: import("tests/cases/compiler/Types").Rank; }
>a : typeof import("tests/cases/compiler/Card")
>default : (suit: import("tests/cases/compiler/Types").Suit, rank: import("tests/cases/compiler/Types").Rank) => { suit: import("tests/cases/compiler/Types").Suit; rank: import("tests/cases/compiler/Types").Rank; }
export { Suit, Rank } from './Types';
>Suit : any
>Rank : any

View File

@@ -20,16 +20,16 @@ export module uninstantiated {
=== tests/cases/compiler/client.ts ===
export { c } from "server";
>c : typeof c
>c : typeof import("tests/cases/compiler/server").c
export { c as c2 } from "server";
>c : typeof c
>c2 : typeof c
>c : typeof import("tests/cases/compiler/server").c
>c2 : typeof import("tests/cases/compiler/server").c
export { i, m as instantiatedModule } from "server";
>i : any
>m : typeof instantiatedModule
>instantiatedModule : typeof instantiatedModule
>m : typeof import("tests/cases/compiler/server").m
>instantiatedModule : typeof import("tests/cases/compiler/server").m
export { uninstantiated } from "server";
>uninstantiated : any

View File

@@ -20,16 +20,16 @@ export module uninstantiated {
=== tests/cases/compiler/client.ts ===
export { c } from "./server";
>c : typeof c
>c : typeof import("tests/cases/compiler/server").c
export { c as c2 } from "./server";
>c : typeof c
>c2 : typeof c
>c : typeof import("tests/cases/compiler/server").c
>c2 : typeof import("tests/cases/compiler/server").c
export { i, m as instantiatedModule } from "./server";
>i : any
>m : typeof instantiatedModule
>instantiatedModule : typeof instantiatedModule
>m : typeof import("tests/cases/compiler/server").m
>instantiatedModule : typeof import("tests/cases/compiler/server").m
export { uninstantiated } from "./server";
>uninstantiated : any

View File

@@ -1,17 +1,14 @@
tests/cases/compiler/b.ts(1,9): error TS2661: Cannot export 'X'. Only local declarations can be exported from a module.
tests/cases/compiler/b.ts(2,17): error TS4060: Return type of exported function has or is using private name 'X'.
==== tests/cases/compiler/a.d.ts (0 errors) ====
declare class X { }
==== tests/cases/compiler/b.ts (2 errors) ====
==== tests/cases/compiler/b.ts (1 errors) ====
export {X};
~
!!! error TS2661: Cannot export 'X'. Only local declarations can be exported from a module.
export function f() {
~
!!! error TS4060: Return type of exported function has or is using private name 'X'.
var x: X;
return x;
}

View File

@@ -19,3 +19,8 @@ function f() {
return x;
}
exports.f = f;
//// [b.d.ts]
export { X };
export declare function f(): X;

View File

@@ -61,11 +61,11 @@ export { v, f, C, I, E, D, M, N, T, a };
export { v, f, C, I, E, D, M, N, T, a } from "./t1";
>v : number
>f : () => void
>C : typeof C
>C : typeof import("tests/cases/conformance/es6/modules/t1").C
>I : any
>E : typeof E
>D : typeof D
>M : typeof M
>E : typeof import("tests/cases/conformance/es6/modules/t1").E
>D : typeof import("tests/cases/conformance/es6/modules/t1").D
>M : typeof import("tests/cases/conformance/es6/modules/t1").M
>N : any
>T : any
>a : any

View File

@@ -61,11 +61,11 @@ export { v, f, C, I, E, D, M, N, T, a };
export { v, f, C, I, E, D, M, N, T, a } from "./t1";
>v : number
>f : () => void
>C : typeof C
>C : typeof import("tests/cases/conformance/es6/modules/t1").C
>I : any
>E : typeof E
>D : typeof D
>M : typeof M
>E : typeof import("tests/cases/conformance/es6/modules/t1").E
>D : typeof import("tests/cases/conformance/es6/modules/t1").D
>M : typeof import("tests/cases/conformance/es6/modules/t1").M
>N : any
>T : any
>a : any

View File

@@ -61,11 +61,11 @@ export { v, f, C, I, E, D, M, N, T, a };
export { v, f, C, I, E, D, M, N, T, a } from "./t1";
>v : number
>f : () => void
>C : typeof C
>C : typeof import("tests/cases/conformance/es6/modules/t1").C
>I : any
>E : typeof E
>D : typeof D
>M : typeof M
>E : typeof import("tests/cases/conformance/es6/modules/t1").E
>D : typeof import("tests/cases/conformance/es6/modules/t1").D
>M : typeof import("tests/cases/conformance/es6/modules/t1").M
>N : any
>T : any
>a : any

View File

@@ -15,17 +15,17 @@ export enum E {
>E : Symbol(E, Decl(t1.ts, 5, 1))
A, B, C
>A : Symbol(E1.A, Decl(t1.ts, 6, 15))
>B : Symbol(E1.B, Decl(t1.ts, 7, 6))
>C : Symbol(E1.C, Decl(t1.ts, 7, 9))
>A : Symbol(E.A, Decl(t1.ts, 6, 15))
>B : Symbol(E.B, Decl(t1.ts, 7, 6))
>C : Symbol(E.C, Decl(t1.ts, 7, 9))
}
export const enum D {
>D : Symbol(D, Decl(t1.ts, 8, 1))
A, B, C
>A : Symbol(D1.A, Decl(t1.ts, 9, 21))
>B : Symbol(D1.B, Decl(t1.ts, 10, 6))
>C : Symbol(D1.C, Decl(t1.ts, 10, 9))
>A : Symbol(D.A, Decl(t1.ts, 9, 21))
>B : Symbol(D.B, Decl(t1.ts, 10, 6))
>C : Symbol(D.C, Decl(t1.ts, 10, 9))
}
export module M {
>M : Symbol(M, Decl(t1.ts, 11, 1))

View File

@@ -73,16 +73,16 @@ export { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N,
>v : number
>f1 : () => void
>f : () => void
>C1 : typeof C
>C : typeof C
>C1 : typeof import("tests/cases/conformance/es6/modules/t1").C
>C : typeof import("tests/cases/conformance/es6/modules/t1").C
>I1 : any
>I : any
>E1 : typeof E
>E : typeof E
>D1 : typeof D
>D : typeof D
>M1 : typeof M
>M : typeof M
>E1 : typeof import("tests/cases/conformance/es6/modules/t1").E
>E : typeof import("tests/cases/conformance/es6/modules/t1").E
>D1 : typeof import("tests/cases/conformance/es6/modules/t1").D
>D : typeof import("tests/cases/conformance/es6/modules/t1").D
>M1 : typeof import("tests/cases/conformance/es6/modules/t1").M
>M : typeof import("tests/cases/conformance/es6/modules/t1").M
>N1 : any
>N : any
>T1 : any

View File

@@ -15,17 +15,17 @@ export enum E {
>E : Symbol(E, Decl(t1.ts, 5, 1))
A, B, C
>A : Symbol(E1.A, Decl(t1.ts, 6, 15))
>B : Symbol(E1.B, Decl(t1.ts, 7, 6))
>C : Symbol(E1.C, Decl(t1.ts, 7, 9))
>A : Symbol(E.A, Decl(t1.ts, 6, 15))
>B : Symbol(E.B, Decl(t1.ts, 7, 6))
>C : Symbol(E.C, Decl(t1.ts, 7, 9))
}
export const enum D {
>D : Symbol(D, Decl(t1.ts, 8, 1))
A, B, C
>A : Symbol(D1.A, Decl(t1.ts, 9, 21))
>B : Symbol(D1.B, Decl(t1.ts, 10, 6))
>C : Symbol(D1.C, Decl(t1.ts, 10, 9))
>A : Symbol(D.A, Decl(t1.ts, 9, 21))
>B : Symbol(D.B, Decl(t1.ts, 10, 6))
>C : Symbol(D.C, Decl(t1.ts, 10, 9))
}
export module M {
>M : Symbol(M, Decl(t1.ts, 11, 1))

View File

@@ -73,16 +73,16 @@ export { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N,
>v : number
>f1 : () => void
>f : () => void
>C1 : typeof C
>C : typeof C
>C1 : typeof import("tests/cases/conformance/es6/modules/t1").C
>C : typeof import("tests/cases/conformance/es6/modules/t1").C
>I1 : any
>I : any
>E1 : typeof E
>E : typeof E
>D1 : typeof D
>D : typeof D
>M1 : typeof M
>M : typeof M
>E1 : typeof import("tests/cases/conformance/es6/modules/t1").E
>E : typeof import("tests/cases/conformance/es6/modules/t1").E
>D1 : typeof import("tests/cases/conformance/es6/modules/t1").D
>D : typeof import("tests/cases/conformance/es6/modules/t1").D
>M1 : typeof import("tests/cases/conformance/es6/modules/t1").M
>M : typeof import("tests/cases/conformance/es6/modules/t1").M
>N1 : any
>N : any
>T1 : any

View File

@@ -15,17 +15,17 @@ export enum E {
>E : Symbol(E, Decl(t1.ts, 5, 1))
A, B, C
>A : Symbol(E1.A, Decl(t1.ts, 6, 15))
>B : Symbol(E1.B, Decl(t1.ts, 7, 6))
>C : Symbol(E1.C, Decl(t1.ts, 7, 9))
>A : Symbol(E.A, Decl(t1.ts, 6, 15))
>B : Symbol(E.B, Decl(t1.ts, 7, 6))
>C : Symbol(E.C, Decl(t1.ts, 7, 9))
}
export const enum D {
>D : Symbol(D, Decl(t1.ts, 8, 1))
A, B, C
>A : Symbol(D1.A, Decl(t1.ts, 9, 21))
>B : Symbol(D1.B, Decl(t1.ts, 10, 6))
>C : Symbol(D1.C, Decl(t1.ts, 10, 9))
>A : Symbol(D.A, Decl(t1.ts, 9, 21))
>B : Symbol(D.B, Decl(t1.ts, 10, 6))
>C : Symbol(D.C, Decl(t1.ts, 10, 9))
}
export module M {
>M : Symbol(M, Decl(t1.ts, 11, 1))

View File

@@ -73,16 +73,16 @@ export { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N,
>v : number
>f1 : () => void
>f : () => void
>C1 : typeof C
>C : typeof C
>C1 : typeof import("tests/cases/conformance/es6/modules/t1").C
>C : typeof import("tests/cases/conformance/es6/modules/t1").C
>I1 : any
>I : any
>E1 : typeof E
>E : typeof E
>D1 : typeof D
>D : typeof D
>M1 : typeof M
>M : typeof M
>E1 : typeof import("tests/cases/conformance/es6/modules/t1").E
>E : typeof import("tests/cases/conformance/es6/modules/t1").E
>D1 : typeof import("tests/cases/conformance/es6/modules/t1").D
>D : typeof import("tests/cases/conformance/es6/modules/t1").D
>M1 : typeof import("tests/cases/conformance/es6/modules/t1").M
>M : typeof import("tests/cases/conformance/es6/modules/t1").M
>N1 : any
>N : any
>T1 : any

View File

@@ -8,7 +8,7 @@ export import T2 = require("./exportEqualsT");
// OK, has a value side
export { C } from "./exportValue";
>C : typeof C
>C : typeof import("/exportValue").C
// OK, even though the namespace it exports is only types.
import * as NS from "./exportT";

View File

@@ -4,7 +4,7 @@ No type information for this code.export * from "./c";
No type information for this code.
No type information for this code.=== tests/cases/compiler/b.ts ===
export {Animals} from "./c";
>Animals : typeof Animals
>Animals : typeof import("tests/cases/compiler/c").Animals
=== tests/cases/compiler/c.ts ===
export enum Animals {

View File

@@ -9,10 +9,10 @@ export class ThingB { }
=== tests/cases/compiler/Things.ts ===
export {ThingA} from "./ThingA";
>ThingA : typeof ThingA
>ThingA : typeof import("tests/cases/compiler/ThingA").ThingA
export {ThingB} from "./ThingB";
>ThingB : typeof ThingB
>ThingB : typeof import("tests/cases/compiler/ThingB").ThingB
=== tests/cases/compiler/Test.ts ===
import * as things from "./Things";

View File

@@ -10,10 +10,10 @@ enum AnEnum {
>AnEnum : Symbol(AnEnum, Decl(systemNamespaceAliasEmit.ts, 2, 1))
ONE,
>ONE : Symbol(BarEnum.ONE, Decl(systemNamespaceAliasEmit.ts, 4, 13))
>ONE : Symbol(AnEnum.ONE, Decl(systemNamespaceAliasEmit.ts, 4, 13))
TWO
>TWO : Symbol(BarEnum.TWO, Decl(systemNamespaceAliasEmit.ts, 5, 8))
>TWO : Symbol(AnEnum.TWO, Decl(systemNamespaceAliasEmit.ts, 5, 8))
}
export {ns, AnEnum, ns as FooBar, AnEnum as BarEnum};

View File

@@ -0,0 +1,14 @@
// @lib: es2015
// @declaration: true
// @filename: Types.ts
type Suit = 'Hearts' | 'Spades' | 'Clubs' | 'Diamonds';
type Rank = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 'Jack' | 'Queen' | 'King';
export { Suit, Rank };
// @filename: Card.ts
import { Suit, Rank } from './Types';
export default (suit: Suit, rank: Rank) => ({suit, rank});
// @filename: index.ts
export let lazyCard = () => import('./Card').then(a => a.default);
export { Suit, Rank } from './Types';