Skip to content

Commit 5bea122

Browse files
author
Joey Watts
committed
Add classExpressionInLoop test
Signed-off-by: Joey Watts <[email protected]>
1 parent 1608291 commit 5bea122

File tree

5 files changed

+105
-0
lines changed

5 files changed

+105
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
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.
2+
3+
4+
==== tests/cases/conformance/classes/classExpressions/classExpressionInLoop.ts (1 errors) ====
5+
let arr = [];
6+
for (let i = 0; i < 5; ++i)
7+
arr.push(class C {
8+
static hello = () => i;
9+
[i] = i;
10+
~~~
11+
!!! 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.
12+
});
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//// [classExpressionInLoop.ts]
2+
let arr = [];
3+
for (let i = 0; i < 5; ++i)
4+
arr.push(class C {
5+
static hello = () => i;
6+
[i] = i;
7+
});
8+
9+
10+
//// [classExpressionInLoop.js]
11+
var _a, _b;
12+
var arr = [];
13+
var _loop_1 = function (i) {
14+
arr.push((_b = /** @class */ (function () {
15+
function C() {
16+
this[_a] = i;
17+
}
18+
return C;
19+
}()),
20+
_a = i,
21+
_b.hello = function () { return i; },
22+
_b));
23+
};
24+
for (var i = 0; i < 5; ++i) {
25+
_loop_1(i);
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
=== tests/cases/conformance/classes/classExpressions/classExpressionInLoop.ts ===
2+
let arr = [];
3+
>arr : Symbol(arr, Decl(classExpressionInLoop.ts, 0, 3))
4+
5+
for (let i = 0; i < 5; ++i)
6+
>i : Symbol(i, Decl(classExpressionInLoop.ts, 1, 8))
7+
>i : Symbol(i, Decl(classExpressionInLoop.ts, 1, 8))
8+
>i : Symbol(i, Decl(classExpressionInLoop.ts, 1, 8))
9+
10+
arr.push(class C {
11+
>arr.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
12+
>arr : Symbol(arr, Decl(classExpressionInLoop.ts, 0, 3))
13+
>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
14+
>C : Symbol(C, Decl(classExpressionInLoop.ts, 2, 13))
15+
16+
static hello = () => i;
17+
>hello : Symbol(C.hello, Decl(classExpressionInLoop.ts, 2, 22))
18+
>i : Symbol(i, Decl(classExpressionInLoop.ts, 1, 8))
19+
20+
[i] = i;
21+
>[i] : Symbol(C[i], Decl(classExpressionInLoop.ts, 3, 31))
22+
>i : Symbol(i, Decl(classExpressionInLoop.ts, 1, 8))
23+
>i : Symbol(i, Decl(classExpressionInLoop.ts, 1, 8))
24+
25+
});
26+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
=== tests/cases/conformance/classes/classExpressions/classExpressionInLoop.ts ===
2+
let arr = [];
3+
>arr : any[]
4+
>[] : undefined[]
5+
6+
for (let i = 0; i < 5; ++i)
7+
>i : number
8+
>0 : 0
9+
>i < 5 : boolean
10+
>i : number
11+
>5 : 5
12+
>++i : number
13+
>i : number
14+
15+
arr.push(class C {
16+
>arr.push(class C { static hello = () => i; [i] = i; }) : number
17+
>arr.push : (...items: any[]) => number
18+
>arr : any[]
19+
>push : (...items: any[]) => number
20+
>class C { static hello = () => i; [i] = i; } : typeof C
21+
>C : typeof C
22+
23+
static hello = () => i;
24+
>hello : () => number
25+
>() => i : () => number
26+
>i : number
27+
28+
[i] = i;
29+
>[i] : number
30+
>i : number
31+
>i : number
32+
33+
});
34+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let arr = [];
2+
for (let i = 0; i < 5; ++i)
3+
arr.push(class C {
4+
static hello = () => i;
5+
[i] = i;
6+
});

0 commit comments

Comments
 (0)