-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to use a const in the initializer of a const enum
- Loading branch information
Andy Hanson
committed
Oct 2, 2017
1 parent
7aee3a1
commit 42761b8
Showing
10 changed files
with
162 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//// [enumInitializers_const.ts] | ||
const stride = 5; | ||
const enum E { | ||
x = stride * 2, | ||
} | ||
E.x; | ||
|
||
const s = "abc"; | ||
const enum S { | ||
abc = s, | ||
} | ||
S.abc; | ||
|
||
|
||
//// [enumInitializers_const.js] | ||
var stride = 5; | ||
10 /* x */; | ||
var s = "abc"; | ||
"abc" /* abc */; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
=== tests/cases/compiler/enumInitializers_const.ts === | ||
const stride = 5; | ||
>stride : Symbol(stride, Decl(enumInitializers_const.ts, 0, 5)) | ||
|
||
const enum E { | ||
>E : Symbol(E, Decl(enumInitializers_const.ts, 0, 17)) | ||
|
||
x = stride * 2, | ||
>x : Symbol(E.x, Decl(enumInitializers_const.ts, 1, 14)) | ||
>stride : Symbol(stride, Decl(enumInitializers_const.ts, 0, 5)) | ||
} | ||
E.x; | ||
>E.x : Symbol(E.x, Decl(enumInitializers_const.ts, 1, 14)) | ||
>E : Symbol(E, Decl(enumInitializers_const.ts, 0, 17)) | ||
>x : Symbol(E.x, Decl(enumInitializers_const.ts, 1, 14)) | ||
|
||
const s = "abc"; | ||
>s : Symbol(s, Decl(enumInitializers_const.ts, 6, 5)) | ||
|
||
const enum S { | ||
>S : Symbol(S, Decl(enumInitializers_const.ts, 6, 16)) | ||
|
||
abc = s, | ||
>abc : Symbol(S.abc, Decl(enumInitializers_const.ts, 7, 14)) | ||
>s : Symbol(s, Decl(enumInitializers_const.ts, 6, 5)) | ||
} | ||
S.abc; | ||
>S.abc : Symbol(S.abc, Decl(enumInitializers_const.ts, 7, 14)) | ||
>S : Symbol(S, Decl(enumInitializers_const.ts, 6, 16)) | ||
>abc : Symbol(S.abc, Decl(enumInitializers_const.ts, 7, 14)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
=== tests/cases/compiler/enumInitializers_const.ts === | ||
const stride = 5; | ||
>stride : 5 | ||
>5 : 5 | ||
|
||
const enum E { | ||
>E : E | ||
|
||
x = stride * 2, | ||
>x : E | ||
>stride * 2 : number | ||
>stride : 5 | ||
>2 : 2 | ||
} | ||
E.x; | ||
>E.x : E | ||
>E : typeof E | ||
>x : E | ||
|
||
const s = "abc"; | ||
>s : "abc" | ||
>"abc" : "abc" | ||
|
||
const enum S { | ||
>S : S | ||
|
||
abc = s, | ||
>abc : S | ||
>s : "abc" | ||
} | ||
S.abc; | ||
>S.abc : S | ||
>S : typeof S | ||
>abc : S | ||
|
11 changes: 11 additions & 0 deletions
11
tests/baselines/reference/enumInitializers_const_circular.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
tests/cases/compiler/enumInitializers_const_circular.ts(3,9): error TS2474: In 'const' enum declarations member initializer must be constant expression. | ||
|
||
|
||
==== tests/cases/compiler/enumInitializers_const_circular.ts (1 errors) ==== | ||
const x = E.y; | ||
const enum E { | ||
y = x, | ||
~ | ||
!!! error TS2474: In 'const' enum declarations member initializer must be constant expression. | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//// [enumInitializers_const_circular.ts] | ||
const x = E.y; | ||
const enum E { | ||
y = x, | ||
} | ||
|
||
|
||
//// [enumInitializers_const_circular.js] | ||
var x = E.y; |
15 changes: 15 additions & 0 deletions
15
tests/baselines/reference/enumInitializers_const_circular.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
=== tests/cases/compiler/enumInitializers_const_circular.ts === | ||
const x = E.y; | ||
>x : Symbol(x, Decl(enumInitializers_const_circular.ts, 0, 5)) | ||
>E.y : Symbol(E.y, Decl(enumInitializers_const_circular.ts, 1, 14)) | ||
>E : Symbol(E, Decl(enumInitializers_const_circular.ts, 0, 14)) | ||
>y : Symbol(E.y, Decl(enumInitializers_const_circular.ts, 1, 14)) | ||
|
||
const enum E { | ||
>E : Symbol(E, Decl(enumInitializers_const_circular.ts, 0, 14)) | ||
|
||
y = x, | ||
>y : Symbol(E.y, Decl(enumInitializers_const_circular.ts, 1, 14)) | ||
>x : Symbol(x, Decl(enumInitializers_const_circular.ts, 0, 5)) | ||
} | ||
|
15 changes: 15 additions & 0 deletions
15
tests/baselines/reference/enumInitializers_const_circular.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
=== tests/cases/compiler/enumInitializers_const_circular.ts === | ||
const x = E.y; | ||
>x : E | ||
>E.y : E | ||
>E : typeof E | ||
>y : E | ||
|
||
const enum E { | ||
>E : E | ||
|
||
y = x, | ||
>y : E | ||
>x : E | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const stride = 5; | ||
const enum E { | ||
x = stride * 2, | ||
} | ||
E.x; | ||
|
||
const s = "abc"; | ||
const enum S { | ||
abc = s, | ||
} | ||
S.abc; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const x = E.y; | ||
const enum E { | ||
y = x, | ||
} |