Do not consider UMD alias symbols as visible within external modules (#18049)

* Do not consider UMD alias symbols as visible within external modules in the symbol writer

* Minimal repro
This commit is contained in:
Wesley Wigham
2017-09-06 22:07:30 -07:00
committed by GitHub
parent 72884b8f27
commit c3e090695e
16 changed files with 103 additions and 13 deletions

View File

@@ -2095,6 +2095,10 @@ namespace ts {
canQualifySymbol(symbolFromSymbolTable, meaning);
}
function isUMDExportSymbol(symbol: Symbol) {
return symbol && symbol.declarations && symbol.declarations[0] && isNamespaceExportDeclaration(symbol.declarations[0]);
}
function trySymbolTable(symbols: SymbolTable) {
// If symbol is directly available by its name in the symbol table
if (isAccessible(symbols.get(symbol.escapedName))) {
@@ -2106,6 +2110,7 @@ namespace ts {
if (symbolFromSymbolTable.flags & SymbolFlags.Alias
&& symbolFromSymbolTable.escapedName !== "export="
&& !getDeclarationOfKind(symbolFromSymbolTable, SyntaxKind.ExportSpecifier)
&& !(isUMDExportSymbol(symbolFromSymbolTable) && isExternalModule(getSourceFileOfNode(enclosingDeclaration)))
// If `!useOnlyExternalAliasing`, we can use any type of alias to get the name
&& (!useOnlyExternalAliasing || some(symbolFromSymbolTable.declarations, isExternalModuleImportEqualsDeclaration))) {

View File

@@ -5,5 +5,5 @@ export var X;
>X : any
export as namespace N
>N : typeof N
>N : typeof "tests/cases/compiler/exportAsNamespace"

View File

@@ -0,0 +1,26 @@
//// [tests/cases/compiler/importShouldNotBeElidedInDeclarationEmit.ts] ////
//// [umd.d.ts]
export as namespace UMD;
export type Thing = {
a: number;
}
export declare function makeThing(): Thing;
//// [index.ts]
import { makeThing } from "umd";
export const thing = makeThing();
//// [index.js]
"use strict";
exports.__esModule = true;
var umd_1 = require("umd");
exports.thing = umd_1.makeThing();
//// [index.d.ts]
export declare const thing: {
a: number;
};

View File

@@ -0,0 +1,23 @@
=== tests/cases/compiler/node_modules/umd.d.ts ===
export as namespace UMD;
>UMD : Symbol(UMD, Decl(umd.d.ts, 0, 0))
export type Thing = {
>Thing : Symbol(Thing, Decl(umd.d.ts, 0, 24))
a: number;
>a : Symbol(a, Decl(umd.d.ts, 2, 21))
}
export declare function makeThing(): Thing;
>makeThing : Symbol(makeThing, Decl(umd.d.ts, 4, 1))
>Thing : Symbol(Thing, Decl(umd.d.ts, 0, 24))
=== tests/cases/compiler/index.ts ===
import { makeThing } from "umd";
>makeThing : Symbol(makeThing, Decl(index.ts, 0, 8))
export const thing = makeThing();
>thing : Symbol(thing, Decl(index.ts, 1, 12))
>makeThing : Symbol(makeThing, Decl(index.ts, 0, 8))

View File

@@ -0,0 +1,24 @@
=== tests/cases/compiler/node_modules/umd.d.ts ===
export as namespace UMD;
>UMD : typeof "tests/cases/compiler/node_modules/umd"
export type Thing = {
>Thing : Thing
a: number;
>a : number
}
export declare function makeThing(): Thing;
>makeThing : () => Thing
>Thing : Thing
=== tests/cases/compiler/index.ts ===
import { makeThing } from "umd";
>makeThing : () => { a: number; }
export const thing = makeThing();
>thing : { a: number; }
>makeThing() : { a: number; }
>makeThing : () => { a: number; }

View File

@@ -47,7 +47,7 @@ var t = p.x;
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
export as namespace Math2d;
>Math2d : typeof Math2d
>Math2d : typeof "tests/cases/conformance/externalModules/node_modules/math2d/index"
export interface Point {
>Point : Point

View File

@@ -45,7 +45,7 @@ var t = p.x;
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
export as namespace Math2d;
>Math2d : typeof Math2d
>Math2d : typeof "tests/cases/conformance/externalModules/node_modules/math2d/index"
export interface Point {
>Point : Point

View File

@@ -44,7 +44,7 @@ export = M2D;
>M2D : Symbol(M2D, Decl(index.d.ts, 2, 13))
declare namespace M2D {
>M2D : Symbol(Math2d, Decl(index.d.ts, 2, 13), Decl(math2d-augment.d.ts, 0, 33))
>M2D : Symbol(M2D, Decl(index.d.ts, 2, 13), Decl(math2d-augment.d.ts, 0, 33))
interface Point {
>Point : Symbol(Point, Decl(index.d.ts, 4, 23))

View File

@@ -47,13 +47,13 @@ var t = p.x;
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
export as namespace Math2d;
>Math2d : typeof Math2d
>Math2d : typeof M2D
export = M2D;
>M2D : typeof M2D
declare namespace M2D {
>M2D : typeof Math2d
>M2D : typeof M2D
interface Point {
>Point : Point

View File

@@ -42,7 +42,7 @@ export = M2D;
>M2D : Symbol(M2D, Decl(index.d.ts, 2, 13))
declare namespace M2D {
>M2D : Symbol(Math2d, Decl(index.d.ts, 2, 13), Decl(math2d-augment.d.ts, 0, 33))
>M2D : Symbol(M2D, Decl(index.d.ts, 2, 13), Decl(math2d-augment.d.ts, 0, 33))
interface Point {
>Point : Symbol(Point, Decl(index.d.ts, 4, 23))

View File

@@ -45,13 +45,13 @@ var t = p.x;
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
export as namespace Math2d;
>Math2d : typeof Math2d
>Math2d : typeof M2D
export = M2D;
>M2D : typeof M2D
declare namespace M2D {
>M2D : typeof Math2d
>M2D : typeof M2D
interface Point {
>Point : Point

View File

@@ -30,5 +30,5 @@ export interface Thing { n: typeof x }
>x : number
export as namespace Foo;
>Foo : typeof Foo
>Foo : typeof "tests/cases/conformance/externalModules/foo"

View File

@@ -32,5 +32,5 @@ export interface Thing { n: typeof x }
>x : number
export as namespace Foo;
>Foo : typeof Foo
>Foo : typeof "tests/cases/conformance/externalModules/foo"

View File

@@ -32,5 +32,5 @@ export interface Thing { n: typeof x }
>x : number
export as namespace Foo;
>Foo : typeof Foo
>Foo : typeof "tests/cases/conformance/externalModules/foo"

View File

@@ -1,6 +1,6 @@
=== tests/cases/compiler/v1/index.d.ts ===
export as namespace Alpha;
>Alpha : typeof Alpha
>Alpha : typeof "tests/cases/compiler/v1/index"
export var x: string;
>x : string

View File

@@ -0,0 +1,12 @@
// @declaration: true
// @filename: node_modules/umd.d.ts
export as namespace UMD;
export type Thing = {
a: number;
}
export declare function makeThing(): Thing;
// @filename: index.ts
import { makeThing } from "umd";
export const thing = makeThing();