Skip to content

Commit

Permalink
Add classExpressionInLoop test
Browse files Browse the repository at this point in the history
Signed-off-by: Joey Watts <jwatts43@bloomberg.net>
  • Loading branch information
Joey Watts committed Jun 27, 2019
1 parent 1608291 commit 5bea122
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/baselines/reference/classExpressionInLoop.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
tests/cases/conformance/classes/classExpressions/classExpressionInLoop.ts(5,9): error TS1166: A computed property name in a class property declaration must refer to an expression whose type is a literal type or a 'unique symbol' type.


==== tests/cases/conformance/classes/classExpressions/classExpressionInLoop.ts (1 errors) ====
let arr = [];
for (let i = 0; i < 5; ++i)
arr.push(class C {
static hello = () => i;
[i] = i;
~~~
!!! error TS1166: A computed property name in a class property declaration must refer to an expression whose type is a literal type or a 'unique symbol' type.
});

26 changes: 26 additions & 0 deletions tests/baselines/reference/classExpressionInLoop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//// [classExpressionInLoop.ts]
let arr = [];
for (let i = 0; i < 5; ++i)
arr.push(class C {
static hello = () => i;
[i] = i;
});


//// [classExpressionInLoop.js]
var _a, _b;
var arr = [];
var _loop_1 = function (i) {
arr.push((_b = /** @class */ (function () {
function C() {
this[_a] = i;
}
return C;
}()),
_a = i,
_b.hello = function () { return i; },
_b));
};
for (var i = 0; i < 5; ++i) {
_loop_1(i);
}
26 changes: 26 additions & 0 deletions tests/baselines/reference/classExpressionInLoop.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
=== tests/cases/conformance/classes/classExpressions/classExpressionInLoop.ts ===
let arr = [];
>arr : Symbol(arr, Decl(classExpressionInLoop.ts, 0, 3))

for (let i = 0; i < 5; ++i)
>i : Symbol(i, Decl(classExpressionInLoop.ts, 1, 8))
>i : Symbol(i, Decl(classExpressionInLoop.ts, 1, 8))
>i : Symbol(i, Decl(classExpressionInLoop.ts, 1, 8))

arr.push(class C {
>arr.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
>arr : Symbol(arr, Decl(classExpressionInLoop.ts, 0, 3))
>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
>C : Symbol(C, Decl(classExpressionInLoop.ts, 2, 13))

static hello = () => i;
>hello : Symbol(C.hello, Decl(classExpressionInLoop.ts, 2, 22))
>i : Symbol(i, Decl(classExpressionInLoop.ts, 1, 8))

[i] = i;
>[i] : Symbol(C[i], Decl(classExpressionInLoop.ts, 3, 31))
>i : Symbol(i, Decl(classExpressionInLoop.ts, 1, 8))
>i : Symbol(i, Decl(classExpressionInLoop.ts, 1, 8))

});

34 changes: 34 additions & 0 deletions tests/baselines/reference/classExpressionInLoop.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
=== tests/cases/conformance/classes/classExpressions/classExpressionInLoop.ts ===
let arr = [];
>arr : any[]
>[] : undefined[]

for (let i = 0; i < 5; ++i)
>i : number
>0 : 0
>i < 5 : boolean
>i : number
>5 : 5
>++i : number
>i : number

arr.push(class C {
>arr.push(class C { static hello = () => i; [i] = i; }) : number
>arr.push : (...items: any[]) => number
>arr : any[]
>push : (...items: any[]) => number
>class C { static hello = () => i; [i] = i; } : typeof C
>C : typeof C

static hello = () => i;
>hello : () => number
>() => i : () => number
>i : number

[i] = i;
>[i] : number
>i : number
>i : number

});

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
let arr = [];
for (let i = 0; i < 5; ++i)
arr.push(class C {
static hello = () => i;
[i] = i;
});

0 comments on commit 5bea122

Please sign in to comment.