mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-23 07:07:09 -05:00
addressed CR feedback, added support for indexed access
This commit is contained in:
@@ -33,16 +33,39 @@ enum Enum1 {
|
||||
// correct cases: reference to the enum member from different enum declaration
|
||||
W1 = A0,
|
||||
W2 = Enum1.A0,
|
||||
|
||||
W3 = Enum1["A0"],
|
||||
W4 = Enum1["W"],
|
||||
// illegal case
|
||||
// forward reference to the element of the same enum
|
||||
X = Y,
|
||||
// forward reference to the element of the same enum
|
||||
Y = Enum1.Z,
|
||||
Y1 = Enum1["Z"],
|
||||
Z = 100,
|
||||
}
|
||||
|
||||
|
||||
module A {
|
||||
export module B {
|
||||
export module C {
|
||||
export enum E {
|
||||
V1 = 1,
|
||||
V2 = A.B.C.E.V1 + 100
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module A {
|
||||
export module B {
|
||||
export module C {
|
||||
export enum E {
|
||||
V3 = A.B.C.E["V2"] + 200,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function foo(x: Enum1) {
|
||||
switch (x) {
|
||||
case Enum1.A:
|
||||
@@ -70,11 +93,22 @@ function foo(x: Enum1) {
|
||||
case Enum1.W:
|
||||
case Enum1.W1:
|
||||
case Enum1.W2:
|
||||
case Enum1.W3:
|
||||
case Enum1.W4:
|
||||
case Enum1.X:
|
||||
case Enum1.Y:
|
||||
case Enum1.Y1:
|
||||
case Enum1.Z:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
//// [constantsInEnumMembers.js]
|
||||
@@ -111,13 +145,43 @@ var Enum1;
|
||||
// correct cases: reference to the enum member from different enum declaration
|
||||
Enum1[Enum1["W1"] = A0] = "W1";
|
||||
Enum1[Enum1["W2"] = Enum1.A0] = "W2";
|
||||
Enum1[Enum1["W3"] = Enum1["A0"]] = "W3";
|
||||
Enum1[Enum1["W4"] = Enum1["W"]] = "W4";
|
||||
// illegal case
|
||||
// forward reference to the element of the same enum
|
||||
Enum1[Enum1["X"] = Enum1.Y] = "X";
|
||||
// forward reference to the element of the same enum
|
||||
Enum1[Enum1["Y"] = 100 /* Z */] = "Y";
|
||||
Enum1[Enum1["Y1"] = Enum1["Z"]] = "Y1";
|
||||
Enum1[Enum1["Z"] = 100] = "Z";
|
||||
})(Enum1 || (Enum1 = {}));
|
||||
var A;
|
||||
(function (A) {
|
||||
var B;
|
||||
(function (B) {
|
||||
var C;
|
||||
(function (C) {
|
||||
(function (E) {
|
||||
E[E["V1"] = 1] = "V1";
|
||||
E[E["V2"] = A.B.C.E.V1 + 100] = "V2";
|
||||
})(C.E || (C.E = {}));
|
||||
var E = C.E;
|
||||
})(C = B.C || (B.C = {}));
|
||||
})(B = A.B || (A.B = {}));
|
||||
})(A || (A = {}));
|
||||
var A;
|
||||
(function (A) {
|
||||
var B;
|
||||
(function (B) {
|
||||
var C;
|
||||
(function (C) {
|
||||
(function (E) {
|
||||
E[E["V3"] = A.B.C.E["V2"] + 200] = "V3";
|
||||
})(C.E || (C.E = {}));
|
||||
var E = C.E;
|
||||
})(C = B.C || (B.C = {}));
|
||||
})(B = A.B || (A.B = {}));
|
||||
})(A || (A = {}));
|
||||
function foo(x) {
|
||||
switch (x) {
|
||||
case 0 /* A */:
|
||||
@@ -145,9 +209,22 @@ function foo(x) {
|
||||
case 11 /* W */:
|
||||
case 100 /* W1 */:
|
||||
case 100 /* W2 */:
|
||||
case 100 /* W3 */:
|
||||
case 11 /* W4 */:
|
||||
case Enum1.X:
|
||||
case Enum1.Y:
|
||||
case Enum1.Y1:
|
||||
case 100 /* Z */:
|
||||
break;
|
||||
}
|
||||
}
|
||||
function bar(e) {
|
||||
switch (e) {
|
||||
case 1 /* V1 */:
|
||||
return 1;
|
||||
case 101 /* V2 */:
|
||||
return 1;
|
||||
case 301 /* V3 */:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,6 +135,16 @@ enum Enum1 {
|
||||
>Enum1 : typeof Enum1
|
||||
>A0 : Enum1
|
||||
|
||||
W3 = Enum1["A0"],
|
||||
>W3 : Enum1
|
||||
>Enum1["A0"] : Enum1
|
||||
>Enum1 : typeof Enum1
|
||||
|
||||
W4 = Enum1["W"],
|
||||
>W4 : Enum1
|
||||
>Enum1["W"] : Enum1
|
||||
>Enum1 : typeof Enum1
|
||||
|
||||
// illegal case
|
||||
// forward reference to the element of the same enum
|
||||
X = Y,
|
||||
@@ -148,11 +158,76 @@ enum Enum1 {
|
||||
>Enum1 : typeof Enum1
|
||||
>Z : Enum1
|
||||
|
||||
Y1 = Enum1["Z"],
|
||||
>Y1 : Enum1
|
||||
>Enum1["Z"] : Enum1
|
||||
>Enum1 : typeof Enum1
|
||||
|
||||
Z = 100,
|
||||
>Z : Enum1
|
||||
}
|
||||
|
||||
|
||||
module A {
|
||||
>A : typeof A
|
||||
|
||||
export module B {
|
||||
>B : typeof B
|
||||
|
||||
export module C {
|
||||
>C : typeof C
|
||||
|
||||
export enum E {
|
||||
>E : E
|
||||
|
||||
V1 = 1,
|
||||
>V1 : E
|
||||
|
||||
V2 = A.B.C.E.V1 + 100
|
||||
>V2 : E
|
||||
>A.B.C.E.V1 + 100 : number
|
||||
>A.B.C.E.V1 : E
|
||||
>A.B.C.E : typeof E
|
||||
>A.B.C : typeof C
|
||||
>A.B : typeof B
|
||||
>A : typeof A
|
||||
>B : typeof B
|
||||
>C : typeof C
|
||||
>E : typeof E
|
||||
>V1 : E
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module A {
|
||||
>A : typeof A
|
||||
|
||||
export module B {
|
||||
>B : typeof B
|
||||
|
||||
export module C {
|
||||
>C : typeof C
|
||||
|
||||
export enum E {
|
||||
>E : E
|
||||
|
||||
V3 = A.B.C.E["V2"] + 200,
|
||||
>V3 : E
|
||||
>A.B.C.E["V2"] + 200 : number
|
||||
>A.B.C.E["V2"] : E
|
||||
>A.B.C.E : typeof E
|
||||
>A.B.C : typeof C
|
||||
>A.B : typeof B
|
||||
>A : typeof A
|
||||
>B : typeof B
|
||||
>C : typeof C
|
||||
>E : typeof E
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function foo(x: Enum1) {
|
||||
>foo : (x: Enum1) => void
|
||||
>x : Enum1
|
||||
@@ -286,6 +361,16 @@ function foo(x: Enum1) {
|
||||
>Enum1 : typeof Enum1
|
||||
>W2 : Enum1
|
||||
|
||||
case Enum1.W3:
|
||||
>Enum1.W3 : Enum1
|
||||
>Enum1 : typeof Enum1
|
||||
>W3 : Enum1
|
||||
|
||||
case Enum1.W4:
|
||||
>Enum1.W4 : Enum1
|
||||
>Enum1 : typeof Enum1
|
||||
>W4 : Enum1
|
||||
|
||||
case Enum1.X:
|
||||
>Enum1.X : Enum1
|
||||
>Enum1 : typeof Enum1
|
||||
@@ -296,6 +381,11 @@ function foo(x: Enum1) {
|
||||
>Enum1 : typeof Enum1
|
||||
>Y : Enum1
|
||||
|
||||
case Enum1.Y1:
|
||||
>Enum1.Y1 : Enum1
|
||||
>Enum1 : typeof Enum1
|
||||
>Y1 : Enum1
|
||||
|
||||
case Enum1.Z:
|
||||
>Enum1.Z : Enum1
|
||||
>Enum1 : typeof Enum1
|
||||
@@ -304,3 +394,49 @@ function foo(x: Enum1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function bar(e: A.B.C.E): number {
|
||||
>bar : (e: A.B.C.E) => number
|
||||
>e : A.B.C.E
|
||||
>A : unknown
|
||||
>B : unknown
|
||||
>C : unknown
|
||||
>E : A.B.C.E
|
||||
|
||||
switch (e) {
|
||||
>e : A.B.C.E
|
||||
|
||||
case A.B.C.E.V1: return 1;
|
||||
>A.B.C.E.V1 : A.B.C.E
|
||||
>A.B.C.E : typeof A.B.C.E
|
||||
>A.B.C : typeof A.B.C
|
||||
>A.B : typeof A.B
|
||||
>A : typeof A
|
||||
>B : typeof A.B
|
||||
>C : typeof A.B.C
|
||||
>E : typeof A.B.C.E
|
||||
>V1 : A.B.C.E
|
||||
|
||||
case A.B.C.E.V2: return 1;
|
||||
>A.B.C.E.V2 : A.B.C.E
|
||||
>A.B.C.E : typeof A.B.C.E
|
||||
>A.B.C : typeof A.B.C
|
||||
>A.B : typeof A.B
|
||||
>A : typeof A
|
||||
>B : typeof A.B
|
||||
>C : typeof A.B.C
|
||||
>E : typeof A.B.C.E
|
||||
>V2 : A.B.C.E
|
||||
|
||||
case A.B.C.E.V3: return 1;
|
||||
>A.B.C.E.V3 : A.B.C.E
|
||||
>A.B.C.E : typeof A.B.C.E
|
||||
>A.B.C : typeof A.B.C
|
||||
>A.B : typeof A.B
|
||||
>A : typeof A
|
||||
>B : typeof A.B
|
||||
>C : typeof A.B.C
|
||||
>E : typeof A.B.C.E
|
||||
>V3 : A.B.C.E
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,16 +33,39 @@ enum Enum1 {
|
||||
// correct cases: reference to the enum member from different enum declaration
|
||||
W1 = A0,
|
||||
W2 = Enum1.A0,
|
||||
|
||||
W3 = Enum1["A0"],
|
||||
W4 = Enum1["W"],
|
||||
// illegal case
|
||||
// forward reference to the element of the same enum
|
||||
X = Y,
|
||||
// forward reference to the element of the same enum
|
||||
Y = Enum1.Z,
|
||||
Y1 = Enum1["Z"],
|
||||
Z = 100,
|
||||
}
|
||||
|
||||
|
||||
module A {
|
||||
export module B {
|
||||
export module C {
|
||||
export enum E {
|
||||
V1 = 1,
|
||||
V2 = A.B.C.E.V1 + 100
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module A {
|
||||
export module B {
|
||||
export module C {
|
||||
export enum E {
|
||||
V3 = A.B.C.E["V2"] + 200,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function foo(x: Enum1) {
|
||||
switch (x) {
|
||||
case Enum1.A:
|
||||
@@ -70,9 +93,20 @@ function foo(x: Enum1) {
|
||||
case Enum1.W:
|
||||
case Enum1.W1:
|
||||
case Enum1.W2:
|
||||
case Enum1.W3:
|
||||
case Enum1.W4:
|
||||
case Enum1.X:
|
||||
case Enum1.Y:
|
||||
case Enum1.Y1:
|
||||
case Enum1.Z:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user