Merge pull request #7591 from Microsoft/allow-merge-for-types-namespaces

Allow aliases to be merged with exported types\namespaces
This commit is contained in:
Vladimir Matveev 2016-03-21 15:16:10 -07:00
commit cc8277c4db
9 changed files with 121 additions and 2 deletions

View file

@ -15085,8 +15085,8 @@ namespace ts {
// in order to prevent collisions with declarations that were exported from the current module (they still contribute to local names).
const excludedMeanings =
(symbol.flags & (SymbolFlags.Value | SymbolFlags.ExportValue) ? SymbolFlags.Value : 0) |
(symbol.flags & (SymbolFlags.Type | SymbolFlags.ExportType) ? SymbolFlags.Type : 0) |
(symbol.flags & (SymbolFlags.Namespace | SymbolFlags.ExportNamespace) ? SymbolFlags.Namespace : 0);
(symbol.flags & SymbolFlags.Type ? SymbolFlags.Type : 0) |
(symbol.flags & SymbolFlags.Namespace ? SymbolFlags.Namespace : 0);
if (target.flags & excludedMeanings) {
const message = node.kind === SyntaxKind.ExportSpecifier ?
Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 :

View file

@ -0,0 +1,20 @@
//// [tests/cases/compiler/mergeWithImportedNamespace.ts] ////
//// [f1.ts]
export namespace N { export var x = 1; }
//// [f2.ts]
import {N} from "./f1";
// partial revert of https://github.com/Microsoft/TypeScript/pull/7583 to prevent breaking changes
export namespace N {
export interface I {x: any}
}
//// [f1.js]
"use strict";
var N;
(function (N) {
N.x = 1;
})(N = exports.N || (exports.N = {}));
//// [f2.js]
"use strict";

View file

@ -0,0 +1,17 @@
=== tests/cases/compiler/f1.ts ===
export namespace N { export var x = 1; }
>N : Symbol(N, Decl(f1.ts, 0, 0))
>x : Symbol(x, Decl(f1.ts, 0, 31))
=== tests/cases/compiler/f2.ts ===
import {N} from "./f1";
>N : Symbol(N, Decl(f2.ts, 0, 8), Decl(f2.ts, 0, 23))
// partial revert of https://github.com/Microsoft/TypeScript/pull/7583 to prevent breaking changes
export namespace N {
>N : Symbol(N, Decl(f2.ts, 0, 23))
export interface I {x: any}
>I : Symbol(I, Decl(f2.ts, 2, 20))
>x : Symbol(I.x, Decl(f2.ts, 3, 24))
}

View file

@ -0,0 +1,18 @@
=== tests/cases/compiler/f1.ts ===
export namespace N { export var x = 1; }
>N : typeof N
>x : number
>1 : number
=== tests/cases/compiler/f2.ts ===
import {N} from "./f1";
>N : typeof N
// partial revert of https://github.com/Microsoft/TypeScript/pull/7583 to prevent breaking changes
export namespace N {
>N : any
export interface I {x: any}
>I : I
>x : any
}

View file

@ -0,0 +1,18 @@
//// [tests/cases/compiler/mergeWithImportedType.ts] ////
//// [f1.ts]
export enum E {X}
//// [f2.ts]
import {E} from "./f1";
// partial revert of https://github.com/Microsoft/TypeScript/pull/7583 to prevent breaking changes
export type E = E;
//// [f1.js]
"use strict";
(function (E) {
E[E["X"] = 0] = "X";
})(exports.E || (exports.E = {}));
var E = exports.E;
//// [f2.js]
"use strict";

View file

@ -0,0 +1,14 @@
=== tests/cases/compiler/f1.ts ===
export enum E {X}
>E : Symbol(E, Decl(f1.ts, 0, 0))
>X : Symbol(E.X, Decl(f1.ts, 0, 15))
=== tests/cases/compiler/f2.ts ===
import {E} from "./f1";
>E : Symbol(E, Decl(f2.ts, 0, 8), Decl(f2.ts, 0, 23))
// partial revert of https://github.com/Microsoft/TypeScript/pull/7583 to prevent breaking changes
export type E = E;
>E : Symbol(E, Decl(f2.ts, 0, 23))
>E : Symbol(E, Decl(f2.ts, 0, 8), Decl(f2.ts, 0, 23))

View file

@ -0,0 +1,14 @@
=== tests/cases/compiler/f1.ts ===
export enum E {X}
>E : E
>X : E
=== tests/cases/compiler/f2.ts ===
import {E} from "./f1";
>E : typeof E
// partial revert of https://github.com/Microsoft/TypeScript/pull/7583 to prevent breaking changes
export type E = E;
>E : E
>E : E

View file

@ -0,0 +1,10 @@
// @module:commonjs
// @filename: f1.ts
export namespace N { export var x = 1; }
// @filename: f2.ts
import {N} from "./f1";
// partial revert of https://github.com/Microsoft/TypeScript/pull/7583 to prevent breaking changes
export namespace N {
export interface I {x: any}
}

View file

@ -0,0 +1,8 @@
// @module:commonjs
// @filename: f1.ts
export enum E {X}
// @filename: f2.ts
import {E} from "./f1";
// partial revert of https://github.com/Microsoft/TypeScript/pull/7583 to prevent breaking changes
export type E = E;