Introduce literal freshness for literal enum member types (#26556)

* Introduce literal freshness for literal enum members, allow enum references in ambient const initializers

* Merge statements

* Add enum literal readonly property test case

* Accept better baselines post-merge
This commit is contained in:
Wesley Wigham authored and GitHub committed 2018-09-07 12:09:07 -07:00
1 parent cf2f339a5c
commit f8b6a8fc8d
161 files changed
+583 -266

No files matched your search

+17 -9
View File
@@ -5907,9 +5907,9 @@ namespace ts {
for (const declaration of symbol.declarations) {
if (declaration.kind === SyntaxKind.EnumDeclaration) {
for (const member of (<EnumDeclaration>declaration).members) {
const memberType = getLiteralType(getEnumMemberValue(member)!, enumCount, getSymbolOfNode(member)); // TODO: GH#18217
const memberType = getFreshTypeOfLiteralType(getLiteralType(getEnumMemberValue(member)!, enumCount, getSymbolOfNode(member))); // TODO: GH#18217
getSymbolLinks(getSymbolOfNode(member)).declaredType = memberType;
memberTypeList.push(memberType);
memberTypeList.push(getRegularTypeOfLiteralType(memberType));
}
}
}
@@ -8242,7 +8242,7 @@ namespace ts {
const res = tryGetDeclaredTypeOfSymbol(symbol);
if (res) {
return checkNoTypeArguments(node, symbol) ?
res.flags & TypeFlags.TypeParameter ? getConstrainedTypeVariable(<TypeParameter>res, node) : res :
res.flags & TypeFlags.TypeParameter ? getConstrainedTypeVariable(<TypeParameter>res, node) : getRegularTypeOfLiteralType(res) :
errorType;
}
@@ -12736,7 +12736,7 @@ namespace ts {
}
function getWidenedLiteralType(type: Type): Type {
return type.flags & TypeFlags.EnumLiteral ? getBaseTypeOfEnumLiteralType(<LiteralType>type) :
return type.flags & TypeFlags.EnumLiteral && type.flags & TypeFlags.FreshLiteral ? getBaseTypeOfEnumLiteralType(<LiteralType>type) :
type.flags & TypeFlags.StringLiteral && type.flags & TypeFlags.FreshLiteral ? stringType :
type.flags & TypeFlags.NumberLiteral && type.flags & TypeFlags.FreshLiteral ? numberType :
type.flags & TypeFlags.BooleanLiteral ? booleanType :
@@ -28274,13 +28274,14 @@ namespace ts {
return false;
}
function literalTypeToNode(type: LiteralType): Expression {
return createLiteral(type.value);
function literalTypeToNode(type: LiteralType, enclosing: Node): Expression {
const enumResult = type.flags & TypeFlags.EnumLiteral && nodeBuilder.symbolToExpression(type.symbol, SymbolFlags.Value, enclosing);
return enumResult || createLiteral(type.value);
}
function createLiteralConstValue(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration) {
const type = getTypeOfSymbol(getSymbolOfNode(node));
return literalTypeToNode(<LiteralType>type);
return literalTypeToNode(<LiteralType>type, node);
}
function createResolver(): EmitResolver {
@@ -29643,13 +29644,20 @@ namespace ts {
(<PrefixUnaryExpression>expr).operand.kind === SyntaxKind.NumericLiteral;
}
function isSimpleLiteralEnumReference(expr: Expression) {
if (
(isPropertyAccessExpression(expr) || (isElementAccessExpression(expr) && isStringOrNumberLiteralExpression(expr.argumentExpression))) &&
isEntityNameExpression(expr.expression)
) return !!(checkExpressionCached(expr).flags & TypeFlags.EnumLiteral);
}
function checkAmbientInitializer(node: VariableDeclaration | PropertyDeclaration | PropertySignature) {
if (node.initializer) {
const isInvalidInitializer = !isStringOrNumberLiteralExpression(node.initializer);
const isInvalidInitializer = !(isStringOrNumberLiteralExpression(node.initializer) || isSimpleLiteralEnumReference(node.initializer));
const isConstOrReadonly = isDeclarationReadonly(node) || isVariableDeclaration(node) && isVarConst(node);
if (isConstOrReadonly && !node.type) {
if (isInvalidInitializer) {
return grammarErrorOnNode(node.initializer!, Diagnostics.A_const_initializer_in_an_ambient_context_must_be_a_string_or_numeric_literal);
return grammarErrorOnNode(node.initializer!, Diagnostics.A_const_initializer_in_an_ambient_context_must_be_a_string_or_numeric_literal_or_literal_enum_reference);
}
}
else {
+1 -1
View File
@@ -835,7 +835,7 @@
"category": "Error",
"code": 1253
},
"A 'const' initializer in an ambient context must be a string or numeric literal.": {
"A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.": {
"category": "Error",
"code": 1254
},
@@ -3,7 +3,7 @@ function f<T>(x: T): T {
return x;
}
enum E { A, B, C }
enum E { A, B, C, "non identifier" }
const c1 = "abc";
const c2 = 123;
@@ -13,6 +13,7 @@ const c5 = f(123);
const c6 = f(-123);
const c7 = true;
const c8 = E.A;
const c8b = E["non identifier"];
const c9 = { x: "abc" };
const c10 = [123];
const c11 = "abc" + "def";
@@ -29,6 +30,7 @@ var E;
E[E["A"] = 0] = "A";
E[E["B"] = 1] = "B";
E[E["C"] = 2] = "C";
E[E["non identifier"] = 3] = "non identifier";
})(E || (E = {}));
var c1 = "abc";
var c2 = 123;
@@ -38,6 +40,7 @@ var c5 = f(123);
var c6 = f(-123);
var c7 = true;
var c8 = E.A;
var c8b = E["non identifier"];
var c9 = { x: "abc" };
var c10 = [123];
var c11 = "abc" + "def";
@@ -51,7 +54,8 @@ declare function f<T>(x: T): T;
declare enum E {
A = 0,
B = 1,
C = 2
C = 2,
"non identifier" = 3
}
declare const c1 = "abc";
declare const c2 = 123;
@@ -60,7 +64,8 @@ declare const c4 = 123;
declare const c5 = 123;
declare const c6 = -123;
declare const c7: boolean;
declare const c8: E;
declare const c8 = E.A;
declare const c8b = E["non identifier"];
declare const c9: {
x: string;
};
@@ -10,11 +10,12 @@ function f<T>(x: T): T {
>x : Symbol(x, Decl(ambientConstLiterals.ts, 0, 14))
}
enum E { A, B, C }
enum E { A, B, C, "non identifier" }
>E : Symbol(E, Decl(ambientConstLiterals.ts, 2, 1))
>A : Symbol(E.A, Decl(ambientConstLiterals.ts, 4, 8))
>B : Symbol(E.B, Decl(ambientConstLiterals.ts, 4, 11))
>C : Symbol(E.C, Decl(ambientConstLiterals.ts, 4, 14))
>"non identifier" : Symbol(E["non identifier"], Decl(ambientConstLiterals.ts, 4, 17))
const c1 = "abc";
>c1 : Symbol(c1, Decl(ambientConstLiterals.ts, 6, 5))
@@ -47,27 +48,32 @@ const c8 = E.A;
>E : Symbol(E, Decl(ambientConstLiterals.ts, 2, 1))
>A : Symbol(E.A, Decl(ambientConstLiterals.ts, 4, 8))
const c8b = E["non identifier"];
>c8b : Symbol(c8b, Decl(ambientConstLiterals.ts, 14, 5))
>E : Symbol(E, Decl(ambientConstLiterals.ts, 2, 1))
>"non identifier" : Symbol(E["non identifier"], Decl(ambientConstLiterals.ts, 4, 17))
const c9 = { x: "abc" };
>c9 : Symbol(c9, Decl(ambientConstLiterals.ts, 14, 5))
>x : Symbol(x, Decl(ambientConstLiterals.ts, 14, 12))
>c9 : Symbol(c9, Decl(ambientConstLiterals.ts, 15, 5))
>x : Symbol(x, Decl(ambientConstLiterals.ts, 15, 12))
const c10 = [123];
>c10 : Symbol(c10, Decl(ambientConstLiterals.ts, 15, 5))
>c10 : Symbol(c10, Decl(ambientConstLiterals.ts, 16, 5))
const c11 = "abc" + "def";
>c11 : Symbol(c11, Decl(ambientConstLiterals.ts, 16, 5))
>c11 : Symbol(c11, Decl(ambientConstLiterals.ts, 17, 5))
const c12 = 123 + 456;
>c12 : Symbol(c12, Decl(ambientConstLiterals.ts, 17, 5))
>c12 : Symbol(c12, Decl(ambientConstLiterals.ts, 18, 5))
const c13 = Math.random() > 0.5 ? "abc" : "def";
>c13 : Symbol(c13, Decl(ambientConstLiterals.ts, 18, 5))
>c13 : Symbol(c13, Decl(ambientConstLiterals.ts, 19, 5))
>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --))
>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --))
const c14 = Math.random() > 0.5 ? 123 : 456;
>c14 : Symbol(c14, Decl(ambientConstLiterals.ts, 19, 5))
>c14 : Symbol(c14, Decl(ambientConstLiterals.ts, 20, 5))
>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --))
>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --))
@@ -7,11 +7,12 @@ function f<T>(x: T): T {
>x : T
}
enum E { A, B, C }
enum E { A, B, C, "non identifier" }
>E : E
>A : E.A
>B : E.B
>C : E.C
>"non identifier" : E.non identifier
const c1 = "abc";
>c1 : "abc"
@@ -52,6 +53,12 @@ const c8 = E.A;
>E : typeof E
>A : E.A
const c8b = E["non identifier"];
>c8b : E.non identifier
>E["non identifier"] : E.non identifier
>E : typeof E
>"non identifier" : "non identifier"
const c9 = { x: "abc" };
>c9 : { x: string; }
>{ x: "abc" } : { x: string; }
+1 -1
View File
@@ -3,7 +3,7 @@
>E1 : E1
y = 4.23
>y : E1
>y : E1.y
>4.23 : 4.23
}
@@ -3,6 +3,6 @@ declare enum E {
>E : E
e = 3
>e : E
>e : E.e
>3 : 3
}
@@ -3,7 +3,7 @@ declare enum E {
>E : E
e = -3 // Negative
>e : E
>e : E.e
>-3 : -3
>3 : 3
}
@@ -3,6 +3,6 @@ declare enum E {
>E : E
e = 3.3 // Decimal
>e : E
>e : E.e
>3.3 : 3.3
}
@@ -3,6 +3,6 @@ declare enum E {
>E : E
e = 0xA
>e : E
>e : E.e
>0xA : 10
}
@@ -3,7 +3,7 @@ declare enum E {
>E : E
e = -0xA
>e : E
>e : E.e
>-0xA : -10
>0xA : 10
}
@@ -6,7 +6,7 @@ declare module M {
>E : E
e = 3
>e : E
>e : E.e
>3 : 3
}
}
@@ -46,7 +46,7 @@ declare enum E1 {
>E1 : E1
y = 4.23
>y : E1
>y : E1.y
>4.23 : 4.23
}
@@ -199,7 +199,7 @@ var r3 = foo3(a); // any
enum E { A }
>E : E
>A : E
>A : E.A
declare function foo14(x: E): E;
>foo14 : { (x: E): E; (x: any): any; }
@@ -20,7 +20,7 @@ var ai: I;
enum E { A }
>E : E
>A : E
>A : E.A
var ae: E;
>ae : E
@@ -129,7 +129,7 @@ interface I13 {
enum E { A }
>E : E
>A : E
>A : E.A
interface I14 {
[x: string]: E;
@@ -42,7 +42,7 @@ enum E {
>E : E
A
>A : E
>A : E.A
}
var g: E = x;
@@ -76,7 +76,7 @@ enum E {
>E : E
A
>A : E
>A : E.A
}
x = E.A;
@@ -294,7 +294,7 @@ enum E {
>E : E
A
>A : E
>A : E.A
}
E = undefined; // Error
>E = undefined : undefined
+1 -1
View File
@@ -24,7 +24,7 @@ C = null; // Error
enum E { A }
>E : E
>A : E
>A : E.A
E = null; // Error
>E = null : null
@@ -3,5 +3,5 @@ async enum E {
>E : E
Value
>Value : E
>Value : E.Value
}
@@ -3,5 +3,5 @@ async enum E {
>E : E
Value
>Value : E
>Value : E.Value
}
@@ -15,5 +15,5 @@ class c4 { public foo() { } }
enum c4 { One } // error
>c4 : c4
>One : c4
>One : c4.One
@@ -32,7 +32,7 @@ class c33 {
}
enum c33 { One };
>c33 : c33
>One : c33
>One : c33.One
// class then import
class c44 {
@@ -2,7 +2,7 @@
// enum then var
enum e1111 { One } // error
>e1111 : e1111
>One : e1111
>One : e1111.One
var e1111 = 1; // error
>e1111 : number
@@ -11,14 +11,14 @@ var e1111 = 1; // error
// enum then function
enum e2 { One } // error
>e2 : e2
>One : e2
>One : e2.One
function e2() { } // error
>e2 : () => void
enum e3 { One } // error
>e3 : e3
>One : e3
>One : e3.One
var e3 = () => { } // error
>e3 : () => void
@@ -27,7 +27,7 @@ var e3 = () => { } // error
// enum then class
enum e4 { One } // error
>e4 : e4
>One : e4
>One : e4.One
class e4 { public foo() { } } // error
>e4 : e4
@@ -36,30 +36,30 @@ class e4 { public foo() { } } // error
// enum then enum
enum e5 { One }
>e5 : e5
>One : e5
>One : e5.One
enum e5 { Two } // error
>e5 : e5
>Two : e5
>Two : e5.One
enum e5a { One } // error
>e5a : e5a
>One : e5a
>One : e5a.One
enum e5a { One } // error
>e5a : e5a
>One : e5a
>One : e5a.One
// enum then internal module
enum e6 { One }
>e6 : e6
>One : e6
>One : e6.One
module e6 { } // ok
enum e6a { One }
>e6a : e6a
>One : e6a
>One : e6a.One
module e6a { var y = 2; } // should be error
>e6a : typeof e6a
@@ -68,7 +68,7 @@ module e6a { var y = 2; } // should be error
enum e6b { One }
>e6b : e6b
>One : e6b
>One : e6b.One
module e6b { export var y = 2; } // should be error
>e6b : typeof e6b
@@ -2,7 +2,7 @@
// enum then interface
enum e1 { One } // error
>e1 : e1
>One : e1
>One : e1.One
interface e1 { // error
foo(): void;
@@ -14,7 +14,7 @@ interface e1 { // error
// enum then class
enum e2 { One }; // error
>e2 : e2
>One : e2
>One : e2.One
class e2 { // error
>e2 : e2
@@ -25,13 +25,13 @@ enum A {
>A : A
b
>b : A
>b : A.b
}
enum A {
>A : A
c
>c : A
>c : A.b
}
module A {
>A : typeof A
@@ -41,7 +41,7 @@ function y4() { } // error
enum y4 { One } // error
>y4 : y4
>One : y4
>One : y4.One
// function then internal module
function y5() { }
@@ -35,7 +35,7 @@ interface i3 { // error
}
enum i3 { One }; // error
>i3 : i3
>One : i3
>One : i3.One
// interface then import
interface i4 {
@@ -174,7 +174,7 @@ module m4a { var y = 2; }
enum m4a { One }
>m4a : m4a
>One : m4a
>One : m4a.One
module m4b { export var y = 2; }
>m4b : typeof m4b
@@ -183,14 +183,14 @@ module m4b { export var y = 2; }
enum m4b { One }
>m4b : m4b
>One : m4b
>One : m4b.One
module m4c { interface I { foo(): void } }
>foo : () => void
enum m4c { One }
>m4c : m4c
>One : m4c
>One : m4c.One
module m4d { class C { foo() { } } }
>m4d : typeof m4d
@@ -199,7 +199,7 @@ module m4d { class C { foo() { } } }
enum m4d { One }
>m4d : m4d
>One : m4d
>One : m4d.One
//// module then module
@@ -12,7 +12,7 @@ module m4a { var y = 2; }
enum m4a { One }
>m4a : m4a
>One : m4a
>One : m4a.One
module m4b { export var y = 2; }
>m4b : typeof m4b
@@ -21,14 +21,14 @@ module m4b { export var y = 2; }
enum m4b { One }
>m4b : m4b
>One : m4b
>One : m4b.One
module m4c { interface I { foo(): void } }
>foo : () => void
enum m4c { One }
>m4c : m4c
>One : m4c
>One : m4c.One
module m4d { class C { foo() { } } }
>m4d : typeof m4d
@@ -37,7 +37,7 @@ module m4d { class C { foo() { } } }
enum m4d { One }
>m4d : m4d
>One : m4d
>One : m4d.One
//// module then module
@@ -47,7 +47,7 @@ var x5 = 1;
enum x5 { One } // error
>x5 : x5
>One : x5
>One : x5.One
// var then module
var x6 = 1;
@@ -16,11 +16,11 @@ function f3(x: number): boolean { return true; }
enum E1 { one }
>E1 : E1
>one : E1
>one : E1.one
enum E2 { two }
>E2 : E2
>two : E2
>two : E2.two
var t1: [(x: number) => string, (x: number) => number];
@@ -46,9 +46,9 @@ t1 = [f1, f2];
>f2 : (x: number) => number
t2 = [E1.one, E2.two];
>t2 = [E1.one, E2.two] : [E1, E2]
>t2 = [E1.one, E2.two] : [E1.one, E2.two]
>t2 : [E1, E2]
>[E1.one, E2.two] : [E1, E2]
>[E1.one, E2.two] : [E1.one, E2.two]
>E1.one : E1
>E1 : typeof E1
>one : E1
@@ -64,9 +64,9 @@ t3 = [5, undefined];
>undefined : undefined
t4 = [E1.one, E2.two, 20];
>t4 = [E1.one, E2.two, 20] : [E1, E2, number]
>t4 = [E1.one, E2.two, 20] : [E1.one, E2.two, number]
>t4 : [E1, E2, number]
>[E1.one, E2.two, 20] : [E1, E2, number]
>[E1.one, E2.two, 20] : [E1.one, E2.two, number]
>E1.one : E1
>E1 : typeof E1
>one : E1
@@ -9,7 +9,7 @@ function foo1() {
enum E { A }
>E : E
>A : E
>A : E.A
}
function foo2() {
@@ -22,5 +22,5 @@ function foo2() {
const enum E { A }
>E : E
>A : E
>A : E.A
}
@@ -9,7 +9,7 @@ function foo1() {
enum E { A }
>E : E
>A : E
>A : E.A
}
function foo2() {
@@ -22,5 +22,5 @@ function foo2() {
const enum E { A }
>E : E
>A : E
>A : E.A
}
@@ -265,7 +265,7 @@ var r14 = foo14();
enum e1 { A }
>e1 : e1
>A : e1
>A : e1.A
module e1 { export var y = 1; }
>e1 : typeof e1
+3 -3
View File
@@ -25,11 +25,11 @@ class F extends A { f };
enum E1 { one }
>E1 : E1
>one : E1
>one : E1.one
enum E2 { one }
>E2 : E2
>one : E2
>one : E2.one
// no error
var numStrTuple: [number, string] = [5, "foo"];
@@ -90,7 +90,7 @@ var eleFromCDA2 = classCDATuple[5]; // C | D | A
var t10: [E1, E2] = [E1.one, E2.one];
>t10 : [E1, E2]
>[E1.one, E2.one] : [E1, E2]
>[E1.one, E2.one] : [E1.one, E2.one]
>E1.one : E1
>E1 : typeof E1
>one : E1
@@ -40,7 +40,7 @@ class C7 extends Undefined { }
enum E { A }
>E : E
>A : E
>A : E.A
class C8 extends E { }
>C8 : C8
@@ -25,7 +25,7 @@ enum Enum {
>Enum : Enum
A
>A : Enum
>A : Enum.A
}
const ObjLiteral = {
@@ -3,9 +3,9 @@ enum Color {
>Color : Color
Color,
>Color : Color
>Color : Color.Color
Thing = Color
>Thing : Color
>Thing : Color.Color
>Color : Color
}
@@ -6,10 +6,10 @@ module m1 {
>e : e
m1,
>m1 : e
>m1 : e.m1
m2 = m1
>m2 : e
>m2 : e.m1
>m1 : e
}
}
@@ -1,11 +1,11 @@
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames47_ES5.ts ===
enum E1 { x }
>E1 : E1
>x : E1
>x : E1.x
enum E2 { x }
>E2 : E2
>x : E2
>x : E2.x
var o = {
>o : { [E1.x || E2.x]: number; }
@@ -1,11 +1,11 @@
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames47_ES6.ts ===
enum E1 { x }
>E1 : E1
>x : E1
>x : E1.x
enum E2 { x }
>E2 : E2
>x : E2
>x : E2.x
var o = {
>o : { [E1.x || E2.x]: number; }
@@ -6,7 +6,7 @@ declare function extractIndexer<T>(p: { [n: number]: T }): T;
enum E { x }
>E : E
>x : E
>x : E.x
var a: any;
>a : any
@@ -6,7 +6,7 @@ declare function extractIndexer<T>(p: { [n: number]: T }): T;
enum E { x }
>E : E
>x : E
>x : E.x
var a: any;
>a : any
@@ -3,7 +3,7 @@ enum E {
>E : E
member
>member : E
>member : E.member
}
var v = {
>v : { [E.member]: number; }
@@ -3,7 +3,7 @@ enum E {
>E : E
member
>member : E
>member : E.member
}
var v = {
>v : { [E.member]: number; }
@@ -1,6 +1,6 @@
tests/cases/compiler/constDeclarations-ambient-errors.ts(2,29): error TS1039: Initializers are not allowed in ambient contexts.
tests/cases/compiler/constDeclarations-ambient-errors.ts(3,28): error TS1039: Initializers are not allowed in ambient contexts.
tests/cases/compiler/constDeclarations-ambient-errors.ts(4,20): error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal.
tests/cases/compiler/constDeclarations-ambient-errors.ts(4,20): error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.
tests/cases/compiler/constDeclarations-ambient-errors.ts(4,39): error TS1039: Initializers are not allowed in ambient contexts.
tests/cases/compiler/constDeclarations-ambient-errors.ts(4,53): error TS1039: Initializers are not allowed in ambient contexts.
tests/cases/compiler/constDeclarations-ambient-errors.ts(8,24): error TS1039: Initializers are not allowed in ambient contexts.
@@ -16,7 +16,7 @@ tests/cases/compiler/constDeclarations-ambient-errors.ts(8,24): error TS1039: In
!!! error TS1039: Initializers are not allowed in ambient contexts.
declare const c3 = null, c4 :string = "", c5: any = 0;
~~~~
!!! error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal.
!!! error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.
~~
!!! error TS1039: Initializers are not allowed in ambient contexts.
~
@@ -1,7 +1,7 @@
=== tests/cases/compiler/constEnumBadPropertyNames.ts ===
const enum E { A }
>E : E
>A : E
>A : E.A
var x = E["B"]
>x : any
@@ -3,7 +3,7 @@ const enum E {
>E : E
A
>A : E
>A : E.A
}
module E {
@@ -41,7 +41,7 @@ const enum E2 {
>E2 : E2
A
>A : E2
>A : E2.A
}
var y0 = E2[1]
@@ -13,7 +13,7 @@ const enum E {
>E : E
V = 100
>V : E
>V : E.V
>100 : 100
}
@@ -5,7 +5,7 @@ function foo() {}
module foo {
const enum E { X }
>E : E
>X : E
>X : E.X
}
export = foo
@@ -5,7 +5,7 @@ class foo {}
module foo {
const enum E { X }
>E : E
>X : E
>X : E.X
}
export = foo
@@ -1,12 +1,12 @@
=== tests/cases/compiler/m1.ts ===
enum foo { A }
>foo : foo
>A : foo
>A : foo.A
module foo {
const enum E { X }
>E : E
>X : E
>X : E.X
}
export = foo
@@ -2,7 +2,7 @@
module foo {
const enum E { X }
>E : E
>X : E
>X : E.X
}
module foo {
@@ -2,7 +2,7 @@
module foo {
const enum E { X }
>E : E
>X : E
>X : E.X
}
export = foo
@@ -10,7 +10,7 @@ module Outer {
module Outer {
export const enum A { X }
>A : A
>X : A
>X : A.X
}
module B {
@@ -7,14 +7,14 @@ enum Hello {
>Hello : Hello
World
>World : Hello
>World : Hello.World
}
enum Hello1 {
>Hello1 : Hello1
World1
>World1 : Hello1
>World1 : Hello1.World1
}
class Foo {
@@ -0,0 +1,36 @@
//// [declarationEmitEnumReadonlyProperty.ts]
enum E {
A = 'a',
B = 'b'
}
class C {
readonly type = E.A;
}
let x: E.A = new C().type;
//// [declarationEmitEnumReadonlyProperty.js]
var E;
(function (E) {
E["A"] = "a";
E["B"] = "b";
})(E || (E = {}));
var C = /** @class */ (function () {
function C() {
this.type = E.A;
}
return C;
}());
var x = new C().type;
//// [declarationEmitEnumReadonlyProperty.d.ts]
declare enum E {
A = "a",
B = "b"
}
declare class C {
readonly type = E.A;
}
declare let x: E.A;
@@ -0,0 +1,29 @@
=== tests/cases/compiler/declarationEmitEnumReadonlyProperty.ts ===
enum E {
>E : Symbol(E, Decl(declarationEmitEnumReadonlyProperty.ts, 0, 0))
A = 'a',
>A : Symbol(E.A, Decl(declarationEmitEnumReadonlyProperty.ts, 0, 8))
B = 'b'
>B : Symbol(E.B, Decl(declarationEmitEnumReadonlyProperty.ts, 1, 12))
}
class C {
>C : Symbol(C, Decl(declarationEmitEnumReadonlyProperty.ts, 3, 1))
readonly type = E.A;
>type : Symbol(C.type, Decl(declarationEmitEnumReadonlyProperty.ts, 5, 9))
>E.A : Symbol(E.A, Decl(declarationEmitEnumReadonlyProperty.ts, 0, 8))
>E : Symbol(E, Decl(declarationEmitEnumReadonlyProperty.ts, 0, 0))
>A : Symbol(E.A, Decl(declarationEmitEnumReadonlyProperty.ts, 0, 8))
}
let x: E.A = new C().type;
>x : Symbol(x, Decl(declarationEmitEnumReadonlyProperty.ts, 9, 3))
>E : Symbol(E, Decl(declarationEmitEnumReadonlyProperty.ts, 0, 0))
>A : Symbol(E.A, Decl(declarationEmitEnumReadonlyProperty.ts, 0, 8))
>new C().type : Symbol(C.type, Decl(declarationEmitEnumReadonlyProperty.ts, 5, 9))
>C : Symbol(C, Decl(declarationEmitEnumReadonlyProperty.ts, 3, 1))
>type : Symbol(C.type, Decl(declarationEmitEnumReadonlyProperty.ts, 5, 9))
@@ -0,0 +1,31 @@
=== tests/cases/compiler/declarationEmitEnumReadonlyProperty.ts ===
enum E {
>E : E
A = 'a',
>A : E.A
>'a' : "a"
B = 'b'
>B : E.B
>'b' : "b"
}
class C {
>C : C
readonly type = E.A;
>type : E.A
>E.A : E.A
>E : typeof E
>A : E.A
}
let x: E.A = new C().type;
>x : E.A
>E : any
>new C().type : E.A
>new C() : C
>C : typeof C
>type : E.A
@@ -41,7 +41,7 @@ module M.P {
>D : D
f
>f : D
>f : D.f
}
export var v: M.D; // ok
>v : M.D
@@ -191,7 +191,7 @@ b7([["string"], 1, [[true, false]]]); // Shouldn't be an error
// If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3)
enum Foo { a }
>Foo : Foo
>a : Foo
>a : Foo.a
function c0({z: {x, y: {j}}}) { }
>c0 : ({ z: { x, y: { j } } }: { z: { x: any; y: { j: any; }; }; }) => void
@@ -191,7 +191,7 @@ b7([["string"], 1, [[true, false]]]); // Shouldn't be an error
// If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3)
enum Foo { a }
>Foo : Foo
>a : Foo
>a : Foo.a
function c0({z: {x, y: {j}}}) { }
>c0 : ({ z: { x, y: { j } } }: { z: { x: any; y: { j: any; }; }; }) => void
@@ -174,7 +174,7 @@ b2("string", { x: 200, y: true });
// If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3)
enum Foo { a }
>Foo : Foo
>a : Foo
>a : Foo.a
function c0({z: {x, y: {j}}}) { }
>c0 : ({ z: { x, y: { j } } }: { z: { x: any; y: { j: any; }; }; }) => void
@@ -4,7 +4,7 @@ enum A {
>A : A
bar
>bar : A
>bar : A.bar
}
class A {
>A : A
@@ -21,7 +21,7 @@ const enum B {
>B : B
bar
>bar : B
>bar : B.bar
}
const enum C {
@@ -39,7 +39,7 @@ enum D {
>D : D
bar
>bar : D
>bar : D.bar
}
class E {
>E : E
@@ -59,5 +59,5 @@ enum E {
>E : E
bar
>bar : E
>bar : E.bar
}
@@ -3,7 +3,7 @@ enum E{
>E : E
a
>a : E
>a : E.a
}
var x = E;
@@ -1,4 +1,4 @@
/node_modules/a/node_modules/x/index.d.ts(1,18): error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal.
/node_modules/a/node_modules/x/index.d.ts(1,18): error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.
==== /src/a.ts (0 errors) ====
@@ -11,7 +11,7 @@
==== /node_modules/a/node_modules/x/index.d.ts (1 errors) ====
export const x = 1 + 1;
~~~~~
!!! error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal.
!!! error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.
==== /node_modules/a/node_modules/x/package.json (0 errors) ====
{ "name": "x", "version": "1.2.3" }
@@ -3,11 +3,11 @@
enum E { A }
>E : E
>A : E
>A : E.A
enum F { B }
>F : F
>B : F
>B : F.B
var e = E.A;
>e : E
@@ -4,7 +4,7 @@
enum E { A }
>E : E
>A : E
>A : E.A
interface I0 {
[x: string]: E;
@@ -243,7 +243,7 @@ var r4 = foo12(E.A);
enum E2 { A }
>E2 : E2
>A : E2
>A : E2.A
declare function foo13(x: E2): E2;
>foo13 : { (x: E2): E2; (x: E): E; }
@@ -6,7 +6,7 @@ namespace M {
>MyEnum : MyEnum
BAR
>BAR : MyEnum
>BAR : MyEnum.BAR
}
export var object2 = {
>object2 : { foo: MyEnum; }
@@ -28,7 +28,7 @@ namespace N {
>MyEnum : MyEnum
FOO
>FOO : MyEnum
>FOO : MyEnum.FOO
};
export var object1 = {
+2 -2
View File
@@ -162,10 +162,10 @@ enum E9 {
>E9 : E9
A,
>A : E9
>A : E9.A
B = A
>B : E9
>B : E9.A
>A : E9
}
@@ -10,14 +10,14 @@ enum E01 {
>E01 : E01
A
>A : E01
>A : E01.A
}
enum E02 {
>E02 : E02
A = 123
>A : E02
>A : E02.A
>123 : 123
}
@@ -25,7 +25,7 @@ enum E03 {
>E03 : E03
A = "hello"
>A : E03
>A : E03.A
>"hello" : "hello"
}
@@ -3,7 +3,7 @@ enum Position {
>Position : Position
IgnoreRulesSpecific = 0,
>IgnoreRulesSpecific : Position
>IgnoreRulesSpecific : Position.IgnoreRulesSpecific
>0 : 0
}
var x = IgnoreRulesSpecific.
@@ -75,7 +75,7 @@ enum T4 {
>T4 : T4
a = "1"
>a : T4
>a : T4.a
>"1" : "1"
}
@@ -83,7 +83,7 @@ enum T5 {
>T5 : T5
a = "1" + "2"
>a : T5
>a : T5.a
>"1" + "2" : string
>"1" : "1"
>"2" : "2"
@@ -53,7 +53,7 @@ enum T4 {
>T4 : T4
a = "1"
>a : T4
>a : T4.a
>"1" : "1"
}
@@ -61,7 +61,7 @@ enum T5 {
>T5 : T5
a = "1" + "2"
>a : T5
>a : T5.a
>"1" + "2" : string
>"1" : "1"
>"2" : "2"
+2 -2
View File
@@ -27,10 +27,10 @@ enum E9 {
>E9 : E9
A,
>A : E9
>A : E9.A
B = A
>B : E9
>B : E9.A
>A : E9
}
@@ -14,5 +14,5 @@ var x = f.Mode.Open;
=== tests/cases/compiler/enumFromExternalModule_0.ts ===
export enum Mode { Open }
>Mode : Mode
>Open : Mode
>Open : Mode.Open
@@ -4,5 +4,5 @@ class X<A,B,C> { }
enum X { MyVal }
>X : X
>MyVal : X
>MyVal : X.MyVal
@@ -3,7 +3,7 @@
enum E { A }
>E : E
>A : E
>A : E.A
interface I {
[x: string]: any;
@@ -133,7 +133,7 @@ interface I13 {
enum E2 { A }
>E2 : E2
>A : E2
>A : E2.A
interface I14 {
[x: string]: E2;
@@ -0,0 +1,48 @@
//// [enumLiteralUnionNotWidened.ts]
// repro from #22093
enum A { one = "one", two = "two" };
enum B { foo = "foo", bar = "bar" };
type C = A | B.foo;
type D = A | "foo";
class List<T>
{
private readonly items: T[] = [];
}
function asList<T>(arg: T): List<T> { return new List(); }
// TypeScript incorrectly infers the return type of "asList(x)" to be "List<A | B>"
// The correct type is "List<A | B.foo>"
function fn1(x: C): List<C> { return asList(x); }
// If we use the literal "foo" instead of B.foo, the correct type is inferred
function fn2(x: D): List<D> { return asList(x); }
//// [enumLiteralUnionNotWidened.js]
// repro from #22093
var A;
(function (A) {
A["one"] = "one";
A["two"] = "two";
})(A || (A = {}));
;
var B;
(function (B) {
B["foo"] = "foo";
B["bar"] = "bar";
})(B || (B = {}));
;
var List = /** @class */ (function () {
function List() {
this.items = [];
}
return List;
}());
function asList(arg) { return new List(); }
// TypeScript incorrectly infers the return type of "asList(x)" to be "List<A | B>"
// The correct type is "List<A | B.foo>"
function fn1(x) { return asList(x); }
// If we use the literal "foo" instead of B.foo, the correct type is inferred
function fn2(x) { return asList(x); }
@@ -0,0 +1,61 @@
=== tests/cases/compiler/enumLiteralUnionNotWidened.ts ===
// repro from #22093
enum A { one = "one", two = "two" };
>A : Symbol(A, Decl(enumLiteralUnionNotWidened.ts, 0, 0))
>one : Symbol(A.one, Decl(enumLiteralUnionNotWidened.ts, 1, 8))
>two : Symbol(A.two, Decl(enumLiteralUnionNotWidened.ts, 1, 21))
enum B { foo = "foo", bar = "bar" };
>B : Symbol(B, Decl(enumLiteralUnionNotWidened.ts, 1, 36))
>foo : Symbol(B.foo, Decl(enumLiteralUnionNotWidened.ts, 2, 8))
>bar : Symbol(B.bar, Decl(enumLiteralUnionNotWidened.ts, 2, 21))
type C = A | B.foo;
>C : Symbol(C, Decl(enumLiteralUnionNotWidened.ts, 2, 36))
>A : Symbol(A, Decl(enumLiteralUnionNotWidened.ts, 0, 0))
>B : Symbol(B, Decl(enumLiteralUnionNotWidened.ts, 1, 36))
>foo : Symbol(B.foo, Decl(enumLiteralUnionNotWidened.ts, 2, 8))
type D = A | "foo";
>D : Symbol(D, Decl(enumLiteralUnionNotWidened.ts, 4, 19))
>A : Symbol(A, Decl(enumLiteralUnionNotWidened.ts, 0, 0))
class List<T>
>List : Symbol(List, Decl(enumLiteralUnionNotWidened.ts, 5, 19))
>T : Symbol(T, Decl(enumLiteralUnionNotWidened.ts, 7, 11))
{
private readonly items: T[] = [];
>items : Symbol(List.items, Decl(enumLiteralUnionNotWidened.ts, 8, 1))
>T : Symbol(T, Decl(enumLiteralUnionNotWidened.ts, 7, 11))
}
function asList<T>(arg: T): List<T> { return new List(); }
>asList : Symbol(asList, Decl(enumLiteralUnionNotWidened.ts, 10, 1))
>T : Symbol(T, Decl(enumLiteralUnionNotWidened.ts, 12, 16))
>arg : Symbol(arg, Decl(enumLiteralUnionNotWidened.ts, 12, 19))
>T : Symbol(T, Decl(enumLiteralUnionNotWidened.ts, 12, 16))
>List : Symbol(List, Decl(enumLiteralUnionNotWidened.ts, 5, 19))
>T : Symbol(T, Decl(enumLiteralUnionNotWidened.ts, 12, 16))
>List : Symbol(List, Decl(enumLiteralUnionNotWidened.ts, 5, 19))
// TypeScript incorrectly infers the return type of "asList(x)" to be "List<A | B>"
// The correct type is "List<A | B.foo>"
function fn1(x: C): List<C> { return asList(x); }
>fn1 : Symbol(fn1, Decl(enumLiteralUnionNotWidened.ts, 12, 58))
>x : Symbol(x, Decl(enumLiteralUnionNotWidened.ts, 16, 13))
>C : Symbol(C, Decl(enumLiteralUnionNotWidened.ts, 2, 36))
>List : Symbol(List, Decl(enumLiteralUnionNotWidened.ts, 5, 19))
>C : Symbol(C, Decl(enumLiteralUnionNotWidened.ts, 2, 36))
>asList : Symbol(asList, Decl(enumLiteralUnionNotWidened.ts, 10, 1))
>x : Symbol(x, Decl(enumLiteralUnionNotWidened.ts, 16, 13))
// If we use the literal "foo" instead of B.foo, the correct type is inferred
function fn2(x: D): List<D> { return asList(x); }
>fn2 : Symbol(fn2, Decl(enumLiteralUnionNotWidened.ts, 16, 49))
>x : Symbol(x, Decl(enumLiteralUnionNotWidened.ts, 19, 13))
>D : Symbol(D, Decl(enumLiteralUnionNotWidened.ts, 4, 19))
>List : Symbol(List, Decl(enumLiteralUnionNotWidened.ts, 5, 19))
>D : Symbol(D, Decl(enumLiteralUnionNotWidened.ts, 4, 19))
>asList : Symbol(asList, Decl(enumLiteralUnionNotWidened.ts, 10, 1))
>x : Symbol(x, Decl(enumLiteralUnionNotWidened.ts, 19, 13))
@@ -0,0 +1,54 @@
=== tests/cases/compiler/enumLiteralUnionNotWidened.ts ===
// repro from #22093
enum A { one = "one", two = "two" };
>A : A
>one : A.one
>"one" : "one"
>two : A.two
>"two" : "two"
enum B { foo = "foo", bar = "bar" };
>B : B
>foo : B.foo
>"foo" : "foo"
>bar : B.bar
>"bar" : "bar"
type C = A | B.foo;
>C : C
>B : any
type D = A | "foo";
>D : D
class List<T>
>List : List<T>
{
private readonly items: T[] = [];
>items : T[]
>[] : undefined[]
}
function asList<T>(arg: T): List<T> { return new List(); }
>asList : <T>(arg: T) => List<T>
>arg : T
>new List() : List<T>
>List : typeof List
// TypeScript incorrectly infers the return type of "asList(x)" to be "List<A | B>"
// The correct type is "List<A | B.foo>"
function fn1(x: C): List<C> { return asList(x); }
>fn1 : (x: C) => List<C>
>x : C
>asList(x) : List<C>
>asList : <T>(arg: T) => List<T>
>x : C
// If we use the literal "foo" instead of B.foo, the correct type is inferred
function fn2(x: D): List<D> { return asList(x); }
>fn2 : (x: D) => List<D>
>x : D
>asList(x) : List<D>
>asList : <T>(arg: T) => List<T>
>x : D
@@ -3,7 +3,7 @@ enum Position2 {
>Position2 : Position2
IgnoreRulesSpecific = 0
>IgnoreRulesSpecific : Position2
>IgnoreRulesSpecific : Position2.IgnoreRulesSpecific
>0 : 0
}
var x = IgnoreRulesSpecific. // error
@@ -64,7 +64,7 @@ module M1 {
export enum E1 { A = 0 }
>E1 : E1
>A : E1
>A : E1.A
>0 : 0
}
module M1 {
@@ -72,14 +72,14 @@ module M1 {
export enum E1 { B }
>E1 : E1
>B : E1
>B : E1.A
}
module M1 {
>M1 : typeof M1
export enum E1 { C }
>E1 : E1
>C : E1
>C : E1.A
}
@@ -89,14 +89,14 @@ module M2 {
export enum E1 { A }
>E1 : E1
>A : E1
>A : E1.A
}
module M2 {
>M2 : typeof M2
export enum E1 { B = 0 }
>E1 : E1
>B : E1
>B : E1.A
>0 : 0
}
module M2 {
@@ -104,7 +104,7 @@ module M2 {
export enum E1 { C }
>E1 : E1
>C : E1
>C : E1.A
}
@@ -1,7 +1,7 @@
=== tests/cases/compiler/enumOperations.ts ===
enum Enum { None = 0 }
>Enum : Enum
>None : Enum
>None : Enum.None
>0 : 0
var enumType: Enum = Enum.None;
@@ -3,7 +3,7 @@ enum A {
>A : A
Infinity = 1
>Infinity : A
>Infinity : A.Infinity
>1 : 1
}
@@ -3,7 +3,7 @@ enum A {
>A : A
NaN = 1
>NaN : A
>NaN : A.NaN
>1 : 1
}
@@ -3,7 +3,7 @@ enum A {
>A : A
"-Infinity" = 1
>"-Infinity" : A
>"-Infinity" : A.-Infinity
>1 : 1
}
@@ -3,5 +3,5 @@ enum E {
>E : E
'fo"o',
>'fo"o' : E
>'fo"o' : E.fo"o
}
@@ -3,5 +3,5 @@ enum E {
>E : E
"fo'o",
>"fo'o" : E
>"fo'o" : E.fo'o
}
@@ -3,6 +3,6 @@ enum E {
>E : E
'gold \u2730'
>'gold \u2730' : E
>'gold \u2730' : E.gold ✰
}
@@ -3,19 +3,19 @@ enum E {
>E : E
A
>A : E
>A : E.A
}
enum E {
>E : E
B
>B : E
>B : E.A
}
enum E {
>E : E
C
>C : E
>C : E.A
}
@@ -6,5 +6,5 @@ enum E {
>E : E
A
>A : E
>A : E.A
}
@@ -3,12 +3,12 @@ export enum E1 {
>E1 : E1
value1
>value1 : E1
>value1 : E1.value1
}
export const enum E2 {
>E2 : E2
value1
>value1 : E2
>value1 : E2.value1
}
@@ -3,12 +3,12 @@ export enum E1 {
>E1 : E1
value1
>value1 : E1
>value1 : E1.value1
}
export const enum E2 {
>E2 : E2
value1
>value1 : E2
>value1 : E2.value1
}
@@ -20,7 +20,7 @@ var ai: I;
enum E { A }
>E : E
>A : E
>A : E.A
var ae: E;
>ae : E
@@ -66,7 +66,7 @@ module E {
export enum Color { Red }
>Color : Color
>Red : Color
>Red : Color.Red
export function fn() { }
>fn : () => void
@@ -94,7 +94,7 @@ module F {
enum Color { Red }
>Color : Color
>Red : Color
>Red : Color.Red
function fn() { }
>fn : () => void
+1 -1
View File
@@ -14,7 +14,7 @@ var array = [{ x: "", y: true }]
enum E { x }
>E : E
>x : E
>x : E.x
for ({x, y: y = E.x} of array) {
>{x, y: y = E.x} : { x: string; y?: E; }
+1 -1
View File
@@ -14,7 +14,7 @@ var array = [{ x: "", y: true }]
enum E { x }
>E : E
>x : E
>x : E.x
for ({x, y = E.x} of array) {
>{x, y = E.x} : { x: string; y?: number; }
Loaded 100 of 161 files, more files were not shown because too many files have changed in this diff. Show more