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

Allow aliases to be merged with exported types\namespaces #7591

Merged
merged 1 commit into from
Mar 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down
20 changes: 20 additions & 0 deletions tests/baselines/reference/mergeWithImportedNamespace.js
Original file line number Diff line number Diff line change
@@ -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";
17 changes: 17 additions & 0 deletions tests/baselines/reference/mergeWithImportedNamespace.symbols
Original file line number Diff line number Diff line change
@@ -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))
}
18 changes: 18 additions & 0 deletions tests/baselines/reference/mergeWithImportedNamespace.types
Original file line number Diff line number Diff line change
@@ -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
}
18 changes: 18 additions & 0 deletions tests/baselines/reference/mergeWithImportedType.js
Original file line number Diff line number Diff line change
@@ -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";
14 changes: 14 additions & 0 deletions tests/baselines/reference/mergeWithImportedType.symbols
Original file line number Diff line number Diff line change
@@ -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))

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

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