2014-10-29 08:17:16 +01:00
|
|
|
//// [constEnums.ts]
|
2014-10-28 07:56:07 +01:00
|
|
|
const enum Enum1 {
|
2014-10-27 00:40:02 +01:00
|
|
|
A0 = 100,
|
|
|
|
}
|
|
|
|
|
2014-10-28 07:56:07 +01:00
|
|
|
const enum Enum1 {
|
2014-10-27 00:40:02 +01:00
|
|
|
// correct cases
|
|
|
|
A,
|
|
|
|
B,
|
|
|
|
C = 10,
|
2014-10-29 08:17:16 +01:00
|
|
|
D = A | B,
|
|
|
|
E = A | 1,
|
|
|
|
F = 1 | A,
|
|
|
|
G = (1 & 1),
|
|
|
|
H = ~(A | B),
|
|
|
|
I = A >>> 1,
|
|
|
|
J = 1 & A,
|
|
|
|
K = ~(1 | 5),
|
2014-10-27 00:40:02 +01:00
|
|
|
L = ~D,
|
|
|
|
M = E << B,
|
|
|
|
N = E << 1,
|
|
|
|
O = E >> B,
|
|
|
|
P = E >> 1,
|
|
|
|
Q = -D,
|
|
|
|
R = C & 5,
|
|
|
|
S = 5 & C,
|
|
|
|
T = C | D,
|
|
|
|
U = C | 1,
|
|
|
|
V = 10 | D,
|
|
|
|
W = Enum1.V,
|
|
|
|
|
|
|
|
// correct cases: reference to the enum member from different enum declaration
|
|
|
|
W1 = A0,
|
|
|
|
W2 = Enum1.A0,
|
2014-10-27 07:42:20 +01:00
|
|
|
W3 = Enum1["A0"],
|
|
|
|
W4 = Enum1["W"],
|
2014-10-27 00:40:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-27 07:42:20 +01:00
|
|
|
module A {
|
|
|
|
export module B {
|
|
|
|
export module C {
|
2014-10-28 07:56:07 +01:00
|
|
|
export const enum E {
|
2014-10-27 07:42:20 +01:00
|
|
|
V1 = 1,
|
2014-10-29 08:17:16 +01:00
|
|
|
V2 = A.B.C.E.V1 | 100
|
2014-10-27 07:42:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module A {
|
|
|
|
export module B {
|
|
|
|
export module C {
|
2014-10-28 07:56:07 +01:00
|
|
|
export const enum E {
|
2014-10-29 08:17:16 +01:00
|
|
|
V3 = A.B.C.E["V2"] & 200,
|
2014-10-27 07:42:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-01 08:56:00 +01:00
|
|
|
module A1 {
|
|
|
|
export module B {
|
|
|
|
export module C {
|
|
|
|
export const enum E {
|
|
|
|
V1 = 10,
|
|
|
|
V2 = 110,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module A2 {
|
|
|
|
export module B {
|
|
|
|
export module C {
|
|
|
|
export const enum E {
|
|
|
|
V1 = 10,
|
|
|
|
V2 = 110,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// module C will be classified as value
|
|
|
|
export module C {
|
|
|
|
var x = 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-29 08:17:16 +01:00
|
|
|
import I = A.B.C.E;
|
2014-11-01 08:56:00 +01:00
|
|
|
import I1 = A1.B;
|
|
|
|
import I2 = A2.B;
|
2014-10-29 08:17:16 +01:00
|
|
|
|
|
|
|
function foo0(e: I): void {
|
|
|
|
if (e === I.V1) {
|
|
|
|
}
|
|
|
|
else if (e === I.V2) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-01 08:56:00 +01:00
|
|
|
function foo1(e: I1.C.E): void {
|
|
|
|
if (e === I1.C.E.V1) {
|
|
|
|
}
|
|
|
|
else if (e === I1.C.E.V2) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function foo2(e: I2.C.E): void {
|
|
|
|
if (e === I2.C.E.V1) {
|
|
|
|
}
|
|
|
|
else if (e === I2.C.E.V2) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-27 00:40:02 +01:00
|
|
|
function foo(x: Enum1) {
|
|
|
|
switch (x) {
|
|
|
|
case Enum1.A:
|
|
|
|
case Enum1.B:
|
|
|
|
case Enum1.C:
|
|
|
|
case Enum1.D:
|
|
|
|
case Enum1.E:
|
|
|
|
case Enum1.F:
|
|
|
|
case Enum1.G:
|
|
|
|
case Enum1.H:
|
|
|
|
case Enum1.I:
|
|
|
|
case Enum1.J:
|
|
|
|
case Enum1.K:
|
|
|
|
case Enum1.L:
|
|
|
|
case Enum1.M:
|
|
|
|
case Enum1.N:
|
|
|
|
case Enum1.O:
|
|
|
|
case Enum1.P:
|
|
|
|
case Enum1.Q:
|
|
|
|
case Enum1.R:
|
|
|
|
case Enum1.S:
|
2014-11-02 02:16:48 +01:00
|
|
|
case Enum1["T"]:
|
2014-10-27 00:40:02 +01:00
|
|
|
case Enum1.U:
|
|
|
|
case Enum1.V:
|
|
|
|
case Enum1.W:
|
|
|
|
case Enum1.W1:
|
|
|
|
case Enum1.W2:
|
2014-10-27 07:42:20 +01:00
|
|
|
case Enum1.W3:
|
|
|
|
case Enum1.W4:
|
2014-10-27 00:40:02 +01:00
|
|
|
break;
|
|
|
|
}
|
2014-10-27 07:42:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function bar(e: A.B.C.E): number {
|
|
|
|
switch (e) {
|
|
|
|
case A.B.C.E.V1: return 1;
|
|
|
|
case A.B.C.E.V2: return 1;
|
|
|
|
case A.B.C.E.V3: return 1;
|
|
|
|
}
|
2014-10-27 00:40:02 +01:00
|
|
|
}
|
|
|
|
|
2014-10-29 08:17:16 +01:00
|
|
|
//// [constEnums.js]
|
2014-11-01 08:56:00 +01:00
|
|
|
var A2;
|
|
|
|
(function (A2) {
|
|
|
|
var B;
|
|
|
|
(function (B) {
|
|
|
|
// module C will be classified as value
|
|
|
|
var C;
|
|
|
|
(function (C) {
|
|
|
|
var x = 1;
|
|
|
|
})(C = B.C || (B.C = {}));
|
|
|
|
})(B = A2.B || (A2.B = {}));
|
|
|
|
})(A2 || (A2 = {}));
|
|
|
|
var I2 = A2.B;
|
2014-10-29 08:17:16 +01:00
|
|
|
function foo0(e) {
|
|
|
|
if (e === 1 /* V1 */) {
|
|
|
|
}
|
|
|
|
else if (e === 101 /* V2 */) {
|
|
|
|
}
|
|
|
|
}
|
2014-11-01 08:56:00 +01:00
|
|
|
function foo1(e) {
|
|
|
|
if (e === 10 /* V1 */) {
|
|
|
|
}
|
|
|
|
else if (e === 110 /* V2 */) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function foo2(e) {
|
|
|
|
if (e === 10 /* V1 */) {
|
|
|
|
}
|
|
|
|
else if (e === 110 /* V2 */) {
|
|
|
|
}
|
|
|
|
}
|
2014-10-27 00:40:02 +01:00
|
|
|
function foo(x) {
|
|
|
|
switch (x) {
|
|
|
|
case 0 /* A */:
|
|
|
|
case 1 /* B */:
|
|
|
|
case 10 /* C */:
|
|
|
|
case 1 /* D */:
|
|
|
|
case 1 /* E */:
|
|
|
|
case 1 /* F */:
|
2014-10-29 08:17:16 +01:00
|
|
|
case 1 /* G */:
|
|
|
|
case -2 /* H */:
|
|
|
|
case 0 /* I */:
|
|
|
|
case 0 /* J */:
|
|
|
|
case -6 /* K */:
|
2014-10-27 00:40:02 +01:00
|
|
|
case -2 /* L */:
|
|
|
|
case 2 /* M */:
|
|
|
|
case 2 /* N */:
|
|
|
|
case 0 /* O */:
|
|
|
|
case 0 /* P */:
|
|
|
|
case -1 /* Q */:
|
|
|
|
case 0 /* R */:
|
|
|
|
case 0 /* S */:
|
2014-11-02 02:16:48 +01:00
|
|
|
case 11 /* "T" */:
|
2014-10-27 00:40:02 +01:00
|
|
|
case 11 /* U */:
|
|
|
|
case 11 /* V */:
|
|
|
|
case 11 /* W */:
|
|
|
|
case 100 /* W1 */:
|
|
|
|
case 100 /* W2 */:
|
2014-10-27 07:42:20 +01:00
|
|
|
case 100 /* W3 */:
|
|
|
|
case 11 /* W4 */:
|
2014-10-27 00:40:02 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-10-27 07:42:20 +01:00
|
|
|
function bar(e) {
|
|
|
|
switch (e) {
|
2014-11-04 03:42:26 +01:00
|
|
|
case 1 /* V1 */: return 1;
|
|
|
|
case 101 /* V2 */: return 1;
|
|
|
|
case 64 /* V3 */: return 1;
|
2014-10-27 07:42:20 +01:00
|
|
|
}
|
|
|
|
}
|