mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
align behavior of constant expressions in initializers of ambient enum members with spec
This commit is contained in:
+24
-43
@@ -12940,26 +12940,41 @@ namespace ts {
|
||||
if (!(nodeLinks.flags & NodeCheckFlags.EnumValuesComputed)) {
|
||||
let enumSymbol = getSymbolOfNode(node);
|
||||
let enumType = getDeclaredTypeOfSymbol(enumSymbol);
|
||||
let autoValue = 0;
|
||||
let autoValue = 0; // set to undefined when enum member is non-constant
|
||||
let ambient = isInAmbientContext(node);
|
||||
let enumIsConst = isConst(node);
|
||||
|
||||
forEach(node.members, member => {
|
||||
if (member.name.kind !== SyntaxKind.ComputedPropertyName && isNumericLiteralName((<Identifier>member.name).text)) {
|
||||
for (const member of node.members) {
|
||||
if (member.name.kind === SyntaxKind.ComputedPropertyName) {
|
||||
error(member.name, Diagnostics.Computed_property_names_are_not_allowed_in_enums);
|
||||
}
|
||||
else if (isNumericLiteralName((<Identifier>member.name).text)) {
|
||||
error(member.name, Diagnostics.An_enum_member_cannot_have_a_numeric_name);
|
||||
}
|
||||
|
||||
const previousEnumMemberIsNonConstant = autoValue === undefined;
|
||||
|
||||
let initializer = member.initializer;
|
||||
if (initializer) {
|
||||
autoValue = computeConstantValueForEnumMemberInitializer(initializer, enumType, enumIsConst, ambient);
|
||||
}
|
||||
else if (ambient && !enumIsConst) {
|
||||
// In ambient enum declarations that specify no const modifier, enum member declarations
|
||||
// that omit a value are considered computed members (as opposed to having auto-incremented values assigned).
|
||||
autoValue = undefined;
|
||||
}
|
||||
else if (previousEnumMemberIsNonConstant) {
|
||||
// If the member declaration specifies no value, the member is considered a constant enum member.
|
||||
// If the member is the first member in the enum declaration, it is assigned the value zero.
|
||||
// Otherwise, it is assigned the value of the immediately preceding member plus one,
|
||||
// and an error occurs if the immediately preceding member is not a constant enum member
|
||||
error(member.name, Diagnostics.Enum_member_must_have_initializer);
|
||||
}
|
||||
|
||||
if (autoValue !== undefined) {
|
||||
getNodeLinks(member).enumMemberValue = autoValue++;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
nodeLinks.flags |= NodeCheckFlags.EnumValuesComputed;
|
||||
}
|
||||
@@ -12975,11 +12990,11 @@ namespace ts {
|
||||
if (enumIsConst) {
|
||||
error(initializer, Diagnostics.In_const_enum_declarations_member_initializer_must_be_constant_expression);
|
||||
}
|
||||
else if (!ambient) {
|
||||
else if (ambient) {
|
||||
error(initializer, Diagnostics.In_ambient_enum_declarations_member_initializer_must_be_constant_expression);
|
||||
}
|
||||
else {
|
||||
// Only here do we need to check that the initializer is assignable to the enum type.
|
||||
// If it is a constant value (not undefined), it is syntactically constrained to be a number.
|
||||
// Also, we do not need to check this for ambients because there is already
|
||||
// a syntax error if it is not a constant.
|
||||
checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, /*headMessage*/ undefined);
|
||||
}
|
||||
}
|
||||
@@ -13119,7 +13134,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
// Grammar checking
|
||||
checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node);
|
||||
checkGrammarDecorators(node) || checkGrammarModifiers(node);
|
||||
|
||||
checkTypeNameIsReserved(node.name, Diagnostics.Enum_name_cannot_be_0);
|
||||
checkCollisionWithCapturedThisVariable(node, node.name);
|
||||
@@ -15619,40 +15634,6 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function checkGrammarEnumDeclaration(enumDecl: EnumDeclaration): boolean {
|
||||
let enumIsConst = (enumDecl.flags & NodeFlags.Const) !== 0;
|
||||
|
||||
let hasError = false;
|
||||
|
||||
// skip checks below for const enums - they allow arbitrary initializers as long as they can be evaluated to constant expressions.
|
||||
// since all values are known in compile time - it is not necessary to check that constant enum section precedes computed enum members.
|
||||
if (!enumIsConst) {
|
||||
let inConstantEnumMemberSection = true;
|
||||
let inAmbientContext = isInAmbientContext(enumDecl);
|
||||
for (let node of enumDecl.members) {
|
||||
// Do not use hasDynamicName here, because that returns false for well known symbols.
|
||||
// We want to perform checkComputedPropertyName for all computed properties, including
|
||||
// well known symbols.
|
||||
if (node.name.kind === SyntaxKind.ComputedPropertyName) {
|
||||
hasError = grammarErrorOnNode(node.name, Diagnostics.Computed_property_names_are_not_allowed_in_enums);
|
||||
}
|
||||
else if (inAmbientContext) {
|
||||
if (node.initializer && !isIntegerLiteral(node.initializer)) {
|
||||
hasError = grammarErrorOnNode(node.name, Diagnostics.Ambient_enum_elements_can_only_have_integer_literal_initializers) || hasError;
|
||||
}
|
||||
}
|
||||
else if (node.initializer) {
|
||||
inConstantEnumMemberSection = isIntegerLiteral(node.initializer);
|
||||
}
|
||||
else if (!inConstantEnumMemberSection) {
|
||||
hasError = grammarErrorOnNode(node.name, Diagnostics.Enum_member_must_have_initializer) || hasError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return hasError;
|
||||
}
|
||||
|
||||
function hasParseDiagnostics(sourceFile: SourceFile): boolean {
|
||||
return sourceFile.parseDiagnostics.length > 0;
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@
|
||||
"category": "Error",
|
||||
"code": 1063
|
||||
},
|
||||
"Ambient enum elements can only have integer literal initializers.": {
|
||||
"In ambient enum declarations member initializer must be constant expression.": {
|
||||
"category": "Error",
|
||||
"code": 1066
|
||||
},
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
tests/cases/compiler/ambientEnum1.ts(2,9): error TS1066: Ambient enum elements can only have integer literal initializers.
|
||||
tests/cases/compiler/ambientEnum1.ts(7,9): error TS1066: Ambient enum elements can only have integer literal initializers.
|
||||
tests/cases/compiler/ambientEnum1.ts(7,13): error TS1066: In ambient enum declarations member initializer must be constant expression.
|
||||
|
||||
|
||||
==== tests/cases/compiler/ambientEnum1.ts (2 errors) ====
|
||||
==== tests/cases/compiler/ambientEnum1.ts (1 errors) ====
|
||||
declare enum E1 {
|
||||
y = 4.23
|
||||
~
|
||||
!!! error TS1066: Ambient enum elements can only have integer literal initializers.
|
||||
}
|
||||
|
||||
// Ambient enum with computer member
|
||||
declare enum E2 {
|
||||
x = 'foo'.length
|
||||
~
|
||||
!!! error TS1066: Ambient enum elements can only have integer literal initializers.
|
||||
~~~~~~~~~~~~
|
||||
!!! error TS1066: In ambient enum declarations member initializer must be constant expression.
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
tests/cases/conformance/ambient/ambientEnumDeclaration1.ts(5,5): error TS1066: Ambient enum elements can only have integer literal initializers.
|
||||
tests/cases/conformance/ambient/ambientEnumDeclaration1.ts(6,5): error TS1066: Ambient enum elements can only have integer literal initializers.
|
||||
tests/cases/conformance/ambient/ambientEnumDeclaration1.ts(7,5): error TS1066: Ambient enum elements can only have integer literal initializers.
|
||||
tests/cases/conformance/ambient/ambientEnumDeclaration1.ts(8,5): error TS1066: Ambient enum elements can only have integer literal initializers.
|
||||
|
||||
|
||||
==== tests/cases/conformance/ambient/ambientEnumDeclaration1.ts (4 errors) ====
|
||||
// In ambient enum declarations, all values specified in enum member declarations must be classified as constant enum expressions.
|
||||
|
||||
declare enum E {
|
||||
a = 10,
|
||||
b = 10 + 1,
|
||||
~
|
||||
!!! error TS1066: Ambient enum elements can only have integer literal initializers.
|
||||
c = b,
|
||||
~
|
||||
!!! error TS1066: Ambient enum elements can only have integer literal initializers.
|
||||
d = (c) + 1,
|
||||
~
|
||||
!!! error TS1066: Ambient enum elements can only have integer literal initializers.
|
||||
e = 10 << 2 * 8,
|
||||
~
|
||||
!!! error TS1066: Ambient enum elements can only have integer literal initializers.
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
=== tests/cases/conformance/ambient/ambientEnumDeclaration1.ts ===
|
||||
// In ambient enum declarations, all values specified in enum member declarations must be classified as constant enum expressions.
|
||||
|
||||
declare enum E {
|
||||
>E : Symbol(E, Decl(ambientEnumDeclaration1.ts, 0, 0))
|
||||
|
||||
a = 10,
|
||||
>a : Symbol(E.a, Decl(ambientEnumDeclaration1.ts, 2, 16))
|
||||
|
||||
b = 10 + 1,
|
||||
>b : Symbol(E.b, Decl(ambientEnumDeclaration1.ts, 3, 11))
|
||||
|
||||
c = b,
|
||||
>c : Symbol(E.c, Decl(ambientEnumDeclaration1.ts, 4, 15))
|
||||
>b : Symbol(E.b, Decl(ambientEnumDeclaration1.ts, 3, 11))
|
||||
|
||||
d = (c) + 1,
|
||||
>d : Symbol(E.d, Decl(ambientEnumDeclaration1.ts, 5, 10))
|
||||
>c : Symbol(E.c, Decl(ambientEnumDeclaration1.ts, 4, 15))
|
||||
|
||||
e = 10 << 2 * 8,
|
||||
>e : Symbol(E.e, Decl(ambientEnumDeclaration1.ts, 6, 16))
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
=== tests/cases/conformance/ambient/ambientEnumDeclaration1.ts ===
|
||||
// In ambient enum declarations, all values specified in enum member declarations must be classified as constant enum expressions.
|
||||
|
||||
declare enum E {
|
||||
>E : E
|
||||
|
||||
a = 10,
|
||||
>a : E
|
||||
>10 : number
|
||||
|
||||
b = 10 + 1,
|
||||
>b : E
|
||||
>10 + 1 : number
|
||||
>10 : number
|
||||
>1 : number
|
||||
|
||||
c = b,
|
||||
>c : E
|
||||
>b : E
|
||||
|
||||
d = (c) + 1,
|
||||
>d : E
|
||||
>(c) + 1 : number
|
||||
>(c) : E
|
||||
>c : E
|
||||
>1 : number
|
||||
|
||||
e = 10 << 2 * 8,
|
||||
>e : E
|
||||
>10 << 2 * 8 : number
|
||||
>10 : number
|
||||
>2 * 8 : number
|
||||
>2 : number
|
||||
>8 : number
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
tests/cases/compiler/ambientEnumElementInitializer3.ts(2,2): error TS1066: Ambient enum elements can only have integer literal initializers.
|
||||
|
||||
|
||||
==== tests/cases/compiler/ambientEnumElementInitializer3.ts (1 errors) ====
|
||||
declare enum E {
|
||||
e = 3.3 // Decimal
|
||||
~
|
||||
!!! error TS1066: Ambient enum elements can only have integer literal initializers.
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
=== tests/cases/compiler/ambientEnumElementInitializer3.ts ===
|
||||
declare enum E {
|
||||
>E : Symbol(E, Decl(ambientEnumElementInitializer3.ts, 0, 0))
|
||||
|
||||
e = 3.3 // Decimal
|
||||
>e : Symbol(E.e, Decl(ambientEnumElementInitializer3.ts, 0, 16))
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
=== tests/cases/compiler/ambientEnumElementInitializer3.ts ===
|
||||
declare enum E {
|
||||
>E : E
|
||||
|
||||
e = 3.3 // Decimal
|
||||
>e : E
|
||||
>3.3 : number
|
||||
}
|
||||
@@ -2,8 +2,7 @@ tests/cases/conformance/ambient/ambientErrors.ts(2,15): error TS1039: Initialize
|
||||
tests/cases/conformance/ambient/ambientErrors.ts(6,18): error TS2382: Specialized overload signature is not assignable to any non-specialized signature.
|
||||
tests/cases/conformance/ambient/ambientErrors.ts(17,22): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
|
||||
tests/cases/conformance/ambient/ambientErrors.ts(20,24): error TS1183: An implementation cannot be declared in ambient contexts.
|
||||
tests/cases/conformance/ambient/ambientErrors.ts(24,5): error TS1066: Ambient enum elements can only have integer literal initializers.
|
||||
tests/cases/conformance/ambient/ambientErrors.ts(29,5): error TS1066: Ambient enum elements can only have integer literal initializers.
|
||||
tests/cases/conformance/ambient/ambientErrors.ts(29,9): error TS1066: In ambient enum declarations member initializer must be constant expression.
|
||||
tests/cases/conformance/ambient/ambientErrors.ts(34,11): error TS1039: Initializers are not allowed in ambient contexts.
|
||||
tests/cases/conformance/ambient/ambientErrors.ts(35,19): error TS1183: An implementation cannot be declared in ambient contexts.
|
||||
tests/cases/conformance/ambient/ambientErrors.ts(37,20): error TS1039: Initializers are not allowed in ambient contexts.
|
||||
@@ -16,7 +15,7 @@ tests/cases/conformance/ambient/ambientErrors.ts(51,16): error TS2436: Ambient m
|
||||
tests/cases/conformance/ambient/ambientErrors.ts(57,5): error TS2309: An export assignment cannot be used in a module with other exported elements.
|
||||
|
||||
|
||||
==== tests/cases/conformance/ambient/ambientErrors.ts (16 errors) ====
|
||||
==== tests/cases/conformance/ambient/ambientErrors.ts (15 errors) ====
|
||||
// Ambient variable with an initializer
|
||||
declare var x = 4;
|
||||
~
|
||||
@@ -49,15 +48,13 @@ tests/cases/conformance/ambient/ambientErrors.ts(57,5): error TS2309: An export
|
||||
// Ambient enum with non - integer literal constant member
|
||||
declare enum E1 {
|
||||
y = 4.23
|
||||
~
|
||||
!!! error TS1066: Ambient enum elements can only have integer literal initializers.
|
||||
}
|
||||
|
||||
// Ambient enum with computer member
|
||||
declare enum E2 {
|
||||
x = 'foo'.length
|
||||
~
|
||||
!!! error TS1066: Ambient enum elements can only have integer literal initializers.
|
||||
~~~~~~~~~~~~
|
||||
!!! error TS1066: In ambient enum declarations member initializer must be constant expression.
|
||||
}
|
||||
|
||||
// Ambient module with initializers for values, bodies for functions / classes
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
tests/cases/conformance/enums/enumConstantMembers.ts(12,5): error TS1061: Enum member must have initializer.
|
||||
tests/cases/conformance/enums/enumConstantMembers.ts(18,5): error TS1066: Ambient enum elements can only have integer literal initializers.
|
||||
|
||||
|
||||
==== tests/cases/conformance/enums/enumConstantMembers.ts (2 errors) ====
|
||||
// Constant members allow negatives, but not decimals. Also hex literals are allowed
|
||||
enum E1 {
|
||||
a = 1,
|
||||
b
|
||||
}
|
||||
enum E2 {
|
||||
a = - 1,
|
||||
b
|
||||
}
|
||||
enum E3 {
|
||||
a = 0.1,
|
||||
b // Error because 0.1 is not a constant
|
||||
~
|
||||
!!! error TS1061: Enum member must have initializer.
|
||||
}
|
||||
|
||||
declare enum E4 {
|
||||
a = 1,
|
||||
b = -1,
|
||||
c = 0.1 // Not a constant
|
||||
~
|
||||
!!! error TS1066: Ambient enum elements can only have integer literal initializers.
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
=== tests/cases/conformance/enums/enumConstantMembers.ts ===
|
||||
// Constant members allow negatives, but not decimals. Also hex literals are allowed
|
||||
enum E1 {
|
||||
>E1 : Symbol(E1, Decl(enumConstantMembers.ts, 0, 0))
|
||||
|
||||
a = 1,
|
||||
>a : Symbol(E1.a, Decl(enumConstantMembers.ts, 1, 9))
|
||||
|
||||
b
|
||||
>b : Symbol(E1.b, Decl(enumConstantMembers.ts, 2, 10))
|
||||
}
|
||||
enum E2 {
|
||||
>E2 : Symbol(E2, Decl(enumConstantMembers.ts, 4, 1))
|
||||
|
||||
a = - 1,
|
||||
>a : Symbol(E2.a, Decl(enumConstantMembers.ts, 5, 9))
|
||||
|
||||
b
|
||||
>b : Symbol(E2.b, Decl(enumConstantMembers.ts, 6, 12))
|
||||
}
|
||||
enum E3 {
|
||||
>E3 : Symbol(E3, Decl(enumConstantMembers.ts, 8, 1))
|
||||
|
||||
a = 0.1,
|
||||
>a : Symbol(E3.a, Decl(enumConstantMembers.ts, 9, 9))
|
||||
|
||||
b // Error because 0.1 is not a constant
|
||||
>b : Symbol(E3.b, Decl(enumConstantMembers.ts, 10, 12))
|
||||
}
|
||||
|
||||
declare enum E4 {
|
||||
>E4 : Symbol(E4, Decl(enumConstantMembers.ts, 12, 1))
|
||||
|
||||
a = 1,
|
||||
>a : Symbol(E4.a, Decl(enumConstantMembers.ts, 14, 17))
|
||||
|
||||
b = -1,
|
||||
>b : Symbol(E4.b, Decl(enumConstantMembers.ts, 15, 10))
|
||||
|
||||
c = 0.1 // Not a constant
|
||||
>c : Symbol(E4.c, Decl(enumConstantMembers.ts, 16, 11))
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
=== tests/cases/conformance/enums/enumConstantMembers.ts ===
|
||||
// Constant members allow negatives, but not decimals. Also hex literals are allowed
|
||||
enum E1 {
|
||||
>E1 : E1
|
||||
|
||||
a = 1,
|
||||
>a : E1
|
||||
>1 : number
|
||||
|
||||
b
|
||||
>b : E1
|
||||
}
|
||||
enum E2 {
|
||||
>E2 : E2
|
||||
|
||||
a = - 1,
|
||||
>a : E2
|
||||
>- 1 : number
|
||||
>1 : number
|
||||
|
||||
b
|
||||
>b : E2
|
||||
}
|
||||
enum E3 {
|
||||
>E3 : E3
|
||||
|
||||
a = 0.1,
|
||||
>a : E3
|
||||
>0.1 : number
|
||||
|
||||
b // Error because 0.1 is not a constant
|
||||
>b : E3
|
||||
}
|
||||
|
||||
declare enum E4 {
|
||||
>E4 : E4
|
||||
|
||||
a = 1,
|
||||
>a : E4
|
||||
>1 : number
|
||||
|
||||
b = -1,
|
||||
>b : E4
|
||||
>-1 : number
|
||||
>1 : number
|
||||
|
||||
c = 0.1 // Not a constant
|
||||
>c : E4
|
||||
>0.1 : number
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
tests/cases/compiler/enumInitializersWithExponents.ts(5,5): error TS1066: Ambient enum elements can only have integer literal initializers.
|
||||
tests/cases/compiler/enumInitializersWithExponents.ts(6,5): error TS1066: Ambient enum elements can only have integer literal initializers.
|
||||
|
||||
|
||||
==== tests/cases/compiler/enumInitializersWithExponents.ts (2 errors) ====
|
||||
// Must be integer literals.
|
||||
declare enum E {
|
||||
a = 1e3, // ok
|
||||
b = 1e25, // ok
|
||||
c = 1e-3, // error
|
||||
~
|
||||
!!! error TS1066: Ambient enum elements can only have integer literal initializers.
|
||||
d = 1e-9, // error
|
||||
~
|
||||
!!! error TS1066: Ambient enum elements can only have integer literal initializers.
|
||||
e = 1e0, // ok
|
||||
f = 1e+25 // ok
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
=== tests/cases/compiler/enumInitializersWithExponents.ts ===
|
||||
// Must be integer literals.
|
||||
declare enum E {
|
||||
>E : Symbol(E, Decl(enumInitializersWithExponents.ts, 0, 0))
|
||||
|
||||
a = 1e3, // ok
|
||||
>a : Symbol(E.a, Decl(enumInitializersWithExponents.ts, 1, 16))
|
||||
|
||||
b = 1e25, // ok
|
||||
>b : Symbol(E.b, Decl(enumInitializersWithExponents.ts, 2, 12))
|
||||
|
||||
c = 1e-3, // error
|
||||
>c : Symbol(E.c, Decl(enumInitializersWithExponents.ts, 3, 13))
|
||||
|
||||
d = 1e-9, // error
|
||||
>d : Symbol(E.d, Decl(enumInitializersWithExponents.ts, 4, 13))
|
||||
|
||||
e = 1e0, // ok
|
||||
>e : Symbol(E.e, Decl(enumInitializersWithExponents.ts, 5, 13))
|
||||
|
||||
f = 1e+25 // ok
|
||||
>f : Symbol(E.f, Decl(enumInitializersWithExponents.ts, 6, 12))
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
=== tests/cases/compiler/enumInitializersWithExponents.ts ===
|
||||
// Must be integer literals.
|
||||
declare enum E {
|
||||
>E : E
|
||||
|
||||
a = 1e3, // ok
|
||||
>a : E
|
||||
>1e3 : number
|
||||
|
||||
b = 1e25, // ok
|
||||
>b : E
|
||||
>1e25 : number
|
||||
|
||||
c = 1e-3, // error
|
||||
>c : E
|
||||
>1e-3 : number
|
||||
|
||||
d = 1e-9, // error
|
||||
>d : E
|
||||
>1e-9 : number
|
||||
|
||||
e = 1e0, // ok
|
||||
>e : E
|
||||
>1e0 : number
|
||||
|
||||
f = 1e+25 // ok
|
||||
>f : E
|
||||
>1e+25 : number
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
tests/cases/compiler/enumWithoutInitializerAfterComputedMember.ts(4,5): error TS1061: Enum member must have initializer.
|
||||
|
||||
|
||||
==== tests/cases/compiler/enumWithoutInitializerAfterComputedMember.ts (1 errors) ====
|
||||
enum E {
|
||||
a,
|
||||
b = a,
|
||||
c
|
||||
~
|
||||
!!! error TS1061: Enum member must have initializer.
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
=== tests/cases/compiler/enumWithoutInitializerAfterComputedMember.ts ===
|
||||
enum E {
|
||||
>E : Symbol(E, Decl(enumWithoutInitializerAfterComputedMember.ts, 0, 0))
|
||||
|
||||
a,
|
||||
>a : Symbol(E.a, Decl(enumWithoutInitializerAfterComputedMember.ts, 0, 8))
|
||||
|
||||
b = a,
|
||||
>b : Symbol(E.b, Decl(enumWithoutInitializerAfterComputedMember.ts, 1, 6))
|
||||
>a : Symbol(E.a, Decl(enumWithoutInitializerAfterComputedMember.ts, 0, 8))
|
||||
|
||||
c
|
||||
>c : Symbol(E.c, Decl(enumWithoutInitializerAfterComputedMember.ts, 2, 10))
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
=== tests/cases/compiler/enumWithoutInitializerAfterComputedMember.ts ===
|
||||
enum E {
|
||||
>E : E
|
||||
|
||||
a,
|
||||
>a : E
|
||||
|
||||
b = a,
|
||||
>b : E
|
||||
>a : E
|
||||
|
||||
c
|
||||
>c : E
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
//// [initializersInAmbientEnums.ts]
|
||||
declare enum E {
|
||||
a = 10,
|
||||
b = a,
|
||||
e = 10 << 2 * 8,
|
||||
}
|
||||
|
||||
//// [initializersInAmbientEnums.js]
|
||||
@@ -0,0 +1,14 @@
|
||||
=== tests/cases/compiler/initializersInAmbientEnums.ts ===
|
||||
declare enum E {
|
||||
>E : Symbol(E, Decl(initializersInAmbientEnums.ts, 0, 0))
|
||||
|
||||
a = 10,
|
||||
>a : Symbol(E.a, Decl(initializersInAmbientEnums.ts, 0, 16))
|
||||
|
||||
b = a,
|
||||
>b : Symbol(E.b, Decl(initializersInAmbientEnums.ts, 1, 11))
|
||||
>a : Symbol(E.a, Decl(initializersInAmbientEnums.ts, 0, 16))
|
||||
|
||||
e = 10 << 2 * 8,
|
||||
>e : Symbol(E.e, Decl(initializersInAmbientEnums.ts, 2, 10))
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
=== tests/cases/compiler/initializersInAmbientEnums.ts ===
|
||||
declare enum E {
|
||||
>E : E
|
||||
|
||||
a = 10,
|
||||
>a : E
|
||||
>10 : number
|
||||
|
||||
b = a,
|
||||
>b : E
|
||||
>a : E
|
||||
|
||||
e = 10 << 2 * 8,
|
||||
>e : E
|
||||
>10 << 2 * 8 : number
|
||||
>10 : number
|
||||
>2 * 8 : number
|
||||
>2 : number
|
||||
>8 : number
|
||||
}
|
||||
@@ -1,14 +1,20 @@
|
||||
tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName30.ts(3,5): error TS1164: Computed property names are not allowed in enums.
|
||||
tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName30.ts(3,11): error TS2304: Cannot find name 'id'.
|
||||
tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName30.ts(4,5): error TS1005: ',' expected.
|
||||
tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName30.ts(4,5): error TS1164: Computed property names are not allowed in enums.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName30.ts (2 errors) ====
|
||||
==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName30.ts (4 errors) ====
|
||||
enum E {
|
||||
// no ASI, comma expected
|
||||
[e] = id++
|
||||
~~~
|
||||
!!! error TS1164: Computed property names are not allowed in enums.
|
||||
~~
|
||||
!!! error TS2304: Cannot find name 'id'.
|
||||
[e2] = 1
|
||||
~
|
||||
!!! error TS1005: ',' expected.
|
||||
~~~~
|
||||
!!! error TS1164: Computed property names are not allowed in enums.
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnumDeclaration6.ts(5,5): error TS1061: Enum member must have initializer.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnumDeclaration6.ts (1 errors) ====
|
||||
enum E {
|
||||
A = 1,
|
||||
B,
|
||||
C = 1 << 1,
|
||||
D,
|
||||
~
|
||||
!!! error TS1061: Enum member must have initializer.
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
=== tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnumDeclaration6.ts ===
|
||||
enum E {
|
||||
>E : Symbol(E, Decl(parserEnumDeclaration6.ts, 0, 0))
|
||||
|
||||
A = 1,
|
||||
>A : Symbol(E.A, Decl(parserEnumDeclaration6.ts, 0, 8))
|
||||
|
||||
B,
|
||||
>B : Symbol(E.B, Decl(parserEnumDeclaration6.ts, 1, 10))
|
||||
|
||||
C = 1 << 1,
|
||||
>C : Symbol(E.C, Decl(parserEnumDeclaration6.ts, 2, 6))
|
||||
|
||||
D,
|
||||
>D : Symbol(E.D, Decl(parserEnumDeclaration6.ts, 3, 15))
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
=== tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnumDeclaration6.ts ===
|
||||
enum E {
|
||||
>E : E
|
||||
|
||||
A = 1,
|
||||
>A : E
|
||||
>1 : number
|
||||
|
||||
B,
|
||||
>B : E
|
||||
|
||||
C = 1 << 1,
|
||||
>C : E
|
||||
>1 << 1 : number
|
||||
>1 : number
|
||||
>1 : number
|
||||
|
||||
D,
|
||||
>D : E
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
declare enum E {
|
||||
a = 10,
|
||||
b = a,
|
||||
e = 10 << 2 * 8,
|
||||
}
|
||||
Reference in New Issue
Block a user