Skip to content

Commit 193ad95

Browse files
committed
Add tests
1 parent 901ae94 commit 193ad95

12 files changed

+427
-1
lines changed

Diff for: tests/baselines/reference/arrayConcat2.js

+29
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@ a.concat('Hello');
66

77
var b = new Array<string>();
88
b.concat('hello');
9+
10+
const expected1: undefined = undefined as Flatten<undefined>;
11+
12+
// #19535
13+
14+
let [actual2] = (undefined as unknown as string[][]).concat([""]);
15+
const expected2: string | string[] = actual2;
16+
actual2 = undefined as unknown as string | string[];
17+
18+
// #26378
19+
20+
let [actual3] = [""].concat([1]);
21+
const expected3: string | number = actual3;
22+
actual3 = undefined as unknown as string | number;
23+
24+
// #26976
25+
26+
[].concat([""]);
927

1028

1129
//// [arrayConcat2.js]
@@ -14,3 +32,14 @@ a.concat("hello", 'world');
1432
a.concat('Hello');
1533
var b = new Array();
1634
b.concat('hello');
35+
var expected1 = undefined;
36+
// #19535
37+
var actual2 = undefined.concat([""])[0];
38+
var expected2 = actual2;
39+
actual2 = undefined;
40+
// #26378
41+
var actual3 = [""].concat([1])[0];
42+
var expected3 = actual3;
43+
actual3 = undefined;
44+
// #26976
45+
[].concat([""]);

Diff for: tests/baselines/reference/arrayConcat2.symbols

+42
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,45 @@ b.concat('hello');
2121
>b : Symbol(b, Decl(arrayConcat2.ts, 5, 3))
2222
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
2323

24+
const expected1: undefined = undefined as Flatten<undefined>;
25+
>expected1 : Symbol(expected1, Decl(arrayConcat2.ts, 8, 5))
26+
>undefined : Symbol(undefined)
27+
>Flatten : Symbol(Flatten, Decl(lib.es5.d.ts, --, --))
28+
29+
// #19535
30+
31+
let [actual2] = (undefined as unknown as string[][]).concat([""]);
32+
>actual2 : Symbol(actual2, Decl(arrayConcat2.ts, 12, 5))
33+
>(undefined as unknown as string[][]).concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
34+
>undefined : Symbol(undefined)
35+
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
36+
37+
const expected2: string | string[] = actual2;
38+
>expected2 : Symbol(expected2, Decl(arrayConcat2.ts, 13, 5))
39+
>actual2 : Symbol(actual2, Decl(arrayConcat2.ts, 12, 5))
40+
41+
actual2 = undefined as unknown as string | string[];
42+
>actual2 : Symbol(actual2, Decl(arrayConcat2.ts, 12, 5))
43+
>undefined : Symbol(undefined)
44+
45+
// #26378
46+
47+
let [actual3] = [""].concat([1]);
48+
>actual3 : Symbol(actual3, Decl(arrayConcat2.ts, 18, 5))
49+
>[""].concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
50+
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
51+
52+
const expected3: string | number = actual3;
53+
>expected3 : Symbol(expected3, Decl(arrayConcat2.ts, 19, 5))
54+
>actual3 : Symbol(actual3, Decl(arrayConcat2.ts, 18, 5))
55+
56+
actual3 = undefined as unknown as string | number;
57+
>actual3 : Symbol(actual3, Decl(arrayConcat2.ts, 18, 5))
58+
>undefined : Symbol(undefined)
59+
60+
// #26976
61+
62+
[].concat([""]);
63+
>[].concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
64+
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
65+

Diff for: tests/baselines/reference/arrayConcat2.types

+64-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
=== tests/cases/compiler/arrayConcat2.ts ===
22
var a: string[] = [];
33
>a : string[]
4-
>[] : undefined[]
4+
>[] : never[]
55

66
a.concat("hello", 'world');
77
>a.concat("hello", 'world') : string[]
@@ -30,3 +30,66 @@ b.concat('hello');
3030
>concat : { (...items: ConcatArray<string>[]): string[]; <U extends any[]>(...items: U): (string | Flatten<U[number]>)[]; }
3131
>'hello' : "hello"
3232

33+
const expected1: undefined = undefined as Flatten<undefined>;
34+
>expected1 : undefined
35+
>undefined as Flatten<undefined> : undefined
36+
>undefined : undefined
37+
38+
// #19535
39+
40+
let [actual2] = (undefined as unknown as string[][]).concat([""]);
41+
>actual2 : string | string[]
42+
>(undefined as unknown as string[][]).concat([""]) : (string | string[])[]
43+
>(undefined as unknown as string[][]).concat : { (...items: ConcatArray<string[]>[]): string[][]; <U extends any[]>(...items: U): (string[] | Flatten<U[number]>)[]; }
44+
>(undefined as unknown as string[][]) : string[][]
45+
>undefined as unknown as string[][] : string[][]
46+
>undefined as unknown : unknown
47+
>undefined : undefined
48+
>concat : { (...items: ConcatArray<string[]>[]): string[][]; <U extends any[]>(...items: U): (string[] | Flatten<U[number]>)[]; }
49+
>[""] : string[]
50+
>"" : ""
51+
52+
const expected2: string | string[] = actual2;
53+
>expected2 : string | string[]
54+
>actual2 : string | string[]
55+
56+
actual2 = undefined as unknown as string | string[];
57+
>actual2 = undefined as unknown as string | string[] : string | string[]
58+
>actual2 : string | string[]
59+
>undefined as unknown as string | string[] : string | string[]
60+
>undefined as unknown : unknown
61+
>undefined : undefined
62+
63+
// #26378
64+
65+
let [actual3] = [""].concat([1]);
66+
>actual3 : string | number
67+
>[""].concat([1]) : (string | number)[]
68+
>[""].concat : { (...items: ConcatArray<string>[]): string[]; <U extends any[]>(...items: U): (string | Flatten<U[number]>)[]; }
69+
>[""] : string[]
70+
>"" : ""
71+
>concat : { (...items: ConcatArray<string>[]): string[]; <U extends any[]>(...items: U): (string | Flatten<U[number]>)[]; }
72+
>[1] : number[]
73+
>1 : 1
74+
75+
const expected3: string | number = actual3;
76+
>expected3 : string | number
77+
>actual3 : string | number
78+
79+
actual3 = undefined as unknown as string | number;
80+
>actual3 = undefined as unknown as string | number : string | number
81+
>actual3 : string | number
82+
>undefined as unknown as string | number : string | number
83+
>undefined as unknown : unknown
84+
>undefined : undefined
85+
86+
// #26976
87+
88+
[].concat([""]);
89+
>[].concat([""]) : string[]
90+
>[].concat : { (...items: ConcatArray<never>[]): never[]; <U extends any[]>(...items: U): Flatten<U[number]>[]; }
91+
>[] : never[]
92+
>concat : { (...items: ConcatArray<never>[]): never[]; <U extends any[]>(...items: U): Flatten<U[number]>[]; }
93+
>[""] : string[]
94+
>"" : ""
95+

Diff for: tests/baselines/reference/arrayFlat.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//// [arrayFlat.ts]
2+
const expected1: string[][] = [[[""]]].flat();
3+
4+
const expected2: string[][][] = [[[""]]].flat(0);
5+
const expected3: string[][] = [[[""]]].flat(1);
6+
const expected4: string[] = [[[""]]].flat(2);
7+
const expected5: string[] = [[[""]]].flat(3);
8+
9+
let [actual6] = [[[""]]].flat(undefined as number);
10+
const expected6: string[][] | string[] | string = actual6;
11+
actual6 = undefined as string[][] | string[] | string;
12+
13+
// #24579 and #29604
14+
15+
let [actual7] = [[""], [1]].flat();
16+
const expected7: string | number = actual7;
17+
actual7 = undefined as string | number;
18+
const f: any extends typeof actual7 ? true : false = false;
19+
20+
21+
//// [arrayFlat.js]
22+
var expected1 = [[[""]]].flat();
23+
var expected2 = [[[""]]].flat(0);
24+
var expected3 = [[[""]]].flat(1);
25+
var expected4 = [[[""]]].flat(2);
26+
var expected5 = [[[""]]].flat(3);
27+
var actual6 = [[[""]]].flat(undefined)[0];
28+
var expected6 = actual6;
29+
actual6 = undefined;
30+
// #24579 and #29604
31+
var actual7 = [[""], [1]].flat()[0];
32+
var expected7 = actual7;
33+
actual7 = undefined;
34+
var f = false;

Diff for: tests/baselines/reference/arrayFlat.symbols

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
=== tests/cases/compiler/arrayFlat.ts ===
2+
const expected1: string[][] = [[[""]]].flat();
3+
>expected1 : Symbol(expected1, Decl(arrayFlat.ts, 0, 5))
4+
>[[[""]]].flat : Symbol(Array.flat, Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --) ... and 1 more)
5+
>flat : Symbol(Array.flat, Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --) ... and 1 more)
6+
7+
const expected2: string[][][] = [[[""]]].flat(0);
8+
>expected2 : Symbol(expected2, Decl(arrayFlat.ts, 2, 5))
9+
>[[[""]]].flat : Symbol(Array.flat, Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --) ... and 1 more)
10+
>flat : Symbol(Array.flat, Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --) ... and 1 more)
11+
12+
const expected3: string[][] = [[[""]]].flat(1);
13+
>expected3 : Symbol(expected3, Decl(arrayFlat.ts, 3, 5))
14+
>[[[""]]].flat : Symbol(Array.flat, Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --) ... and 1 more)
15+
>flat : Symbol(Array.flat, Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --) ... and 1 more)
16+
17+
const expected4: string[] = [[[""]]].flat(2);
18+
>expected4 : Symbol(expected4, Decl(arrayFlat.ts, 4, 5))
19+
>[[[""]]].flat : Symbol(Array.flat, Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --) ... and 1 more)
20+
>flat : Symbol(Array.flat, Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --) ... and 1 more)
21+
22+
const expected5: string[] = [[[""]]].flat(3);
23+
>expected5 : Symbol(expected5, Decl(arrayFlat.ts, 5, 5))
24+
>[[[""]]].flat : Symbol(Array.flat, Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --) ... and 1 more)
25+
>flat : Symbol(Array.flat, Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --) ... and 1 more)
26+
27+
let [actual6] = [[[""]]].flat(undefined as number);
28+
>actual6 : Symbol(actual6, Decl(arrayFlat.ts, 7, 5))
29+
>[[[""]]].flat : Symbol(Array.flat, Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --) ... and 1 more)
30+
>flat : Symbol(Array.flat, Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --) ... and 1 more)
31+
>undefined : Symbol(undefined)
32+
33+
const expected6: string[][] | string[] | string = actual6;
34+
>expected6 : Symbol(expected6, Decl(arrayFlat.ts, 8, 5))
35+
>actual6 : Symbol(actual6, Decl(arrayFlat.ts, 7, 5))
36+
37+
actual6 = undefined as string[][] | string[] | string;
38+
>actual6 : Symbol(actual6, Decl(arrayFlat.ts, 7, 5))
39+
>undefined : Symbol(undefined)
40+
41+
// #24579 and #29604
42+
43+
let [actual7] = [[""], [1]].flat();
44+
>actual7 : Symbol(actual7, Decl(arrayFlat.ts, 13, 5))
45+
>[[""], [1]].flat : Symbol(Array.flat, Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --) ... and 1 more)
46+
>flat : Symbol(Array.flat, Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --) ... and 1 more)
47+
48+
const expected7: string | number = actual7;
49+
>expected7 : Symbol(expected7, Decl(arrayFlat.ts, 14, 5))
50+
>actual7 : Symbol(actual7, Decl(arrayFlat.ts, 13, 5))
51+
52+
actual7 = undefined as string | number;
53+
>actual7 : Symbol(actual7, Decl(arrayFlat.ts, 13, 5))
54+
>undefined : Symbol(undefined)
55+
56+
const f: any extends typeof actual7 ? true : false = false;
57+
>f : Symbol(f, Decl(arrayFlat.ts, 16, 5))
58+
>actual7 : Symbol(actual7, Decl(arrayFlat.ts, 13, 5))
59+

Diff for: tests/baselines/reference/arrayFlat.types

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
=== tests/cases/compiler/arrayFlat.ts ===
2+
const expected1: string[][] = [[[""]]].flat();
3+
>expected1 : string[][]
4+
>[[[""]]].flat() : string[][]
5+
>[[[""]]].flat : { (depth: 4): string[]; (depth: 3): string[]; (depth: 2): string[]; (depth?: 1): string[][]; (depth: 0): string[][][]; (depth: number): string[] | string[][] | string[][][]; }
6+
>[[[""]]] : string[][][]
7+
>[[""]] : string[][]
8+
>[""] : string[]
9+
>"" : ""
10+
>flat : { (depth: 4): string[]; (depth: 3): string[]; (depth: 2): string[]; (depth?: 1): string[][]; (depth: 0): string[][][]; (depth: number): string[] | string[][] | string[][][]; }
11+
12+
const expected2: string[][][] = [[[""]]].flat(0);
13+
>expected2 : string[][][]
14+
>[[[""]]].flat(0) : string[][][]
15+
>[[[""]]].flat : { (depth: 4): string[]; (depth: 3): string[]; (depth: 2): string[]; (depth?: 1): string[][]; (depth: 0): string[][][]; (depth: number): string[] | string[][] | string[][][]; }
16+
>[[[""]]] : string[][][]
17+
>[[""]] : string[][]
18+
>[""] : string[]
19+
>"" : ""
20+
>flat : { (depth: 4): string[]; (depth: 3): string[]; (depth: 2): string[]; (depth?: 1): string[][]; (depth: 0): string[][][]; (depth: number): string[] | string[][] | string[][][]; }
21+
>0 : 0
22+
23+
const expected3: string[][] = [[[""]]].flat(1);
24+
>expected3 : string[][]
25+
>[[[""]]].flat(1) : string[][]
26+
>[[[""]]].flat : { (depth: 4): string[]; (depth: 3): string[]; (depth: 2): string[]; (depth?: 1): string[][]; (depth: 0): string[][][]; (depth: number): string[] | string[][] | string[][][]; }
27+
>[[[""]]] : string[][][]
28+
>[[""]] : string[][]
29+
>[""] : string[]
30+
>"" : ""
31+
>flat : { (depth: 4): string[]; (depth: 3): string[]; (depth: 2): string[]; (depth?: 1): string[][]; (depth: 0): string[][][]; (depth: number): string[] | string[][] | string[][][]; }
32+
>1 : 1
33+
34+
const expected4: string[] = [[[""]]].flat(2);
35+
>expected4 : string[]
36+
>[[[""]]].flat(2) : string[]
37+
>[[[""]]].flat : { (depth: 4): string[]; (depth: 3): string[]; (depth: 2): string[]; (depth?: 1): string[][]; (depth: 0): string[][][]; (depth: number): string[] | string[][] | string[][][]; }
38+
>[[[""]]] : string[][][]
39+
>[[""]] : string[][]
40+
>[""] : string[]
41+
>"" : ""
42+
>flat : { (depth: 4): string[]; (depth: 3): string[]; (depth: 2): string[]; (depth?: 1): string[][]; (depth: 0): string[][][]; (depth: number): string[] | string[][] | string[][][]; }
43+
>2 : 2
44+
45+
const expected5: string[] = [[[""]]].flat(3);
46+
>expected5 : string[]
47+
>[[[""]]].flat(3) : string[]
48+
>[[[""]]].flat : { (depth: 4): string[]; (depth: 3): string[]; (depth: 2): string[]; (depth?: 1): string[][]; (depth: 0): string[][][]; (depth: number): string[] | string[][] | string[][][]; }
49+
>[[[""]]] : string[][][]
50+
>[[""]] : string[][]
51+
>[""] : string[]
52+
>"" : ""
53+
>flat : { (depth: 4): string[]; (depth: 3): string[]; (depth: 2): string[]; (depth?: 1): string[][]; (depth: 0): string[][][]; (depth: number): string[] | string[][] | string[][][]; }
54+
>3 : 3
55+
56+
let [actual6] = [[[""]]].flat(undefined as number);
57+
>actual6 : string | string[] | string[][]
58+
>[[[""]]].flat(undefined as number) : string[] | string[][] | string[][][]
59+
>[[[""]]].flat : { (depth: 4): string[]; (depth: 3): string[]; (depth: 2): string[]; (depth?: 1): string[][]; (depth: 0): string[][][]; (depth: number): string[] | string[][] | string[][][]; }
60+
>[[[""]]] : string[][][]
61+
>[[""]] : string[][]
62+
>[""] : string[]
63+
>"" : ""
64+
>flat : { (depth: 4): string[]; (depth: 3): string[]; (depth: 2): string[]; (depth?: 1): string[][]; (depth: 0): string[][][]; (depth: number): string[] | string[][] | string[][][]; }
65+
>undefined as number : number
66+
>undefined : undefined
67+
68+
const expected6: string[][] | string[] | string = actual6;
69+
>expected6 : string | string[] | string[][]
70+
>actual6 : string | string[] | string[][]
71+
72+
actual6 = undefined as string[][] | string[] | string;
73+
>actual6 = undefined as string[][] | string[] | string : string | string[] | string[][]
74+
>actual6 : string | string[] | string[][]
75+
>undefined as string[][] | string[] | string : string | string[] | string[][]
76+
>undefined : undefined
77+
78+
// #24579 and #29604
79+
80+
let [actual7] = [[""], [1]].flat();
81+
>actual7 : string | number
82+
>[[""], [1]].flat() : (string | number)[]
83+
>[[""], [1]].flat : { (depth: 4): (string | number)[]; (depth: 3): (string | number)[]; (depth: 2): (string | number)[]; (depth?: 1): (string | number)[]; (depth: 0): (string[] | number[])[]; (depth: number): (string[] | number[])[] | (string | number)[]; }
84+
>[[""], [1]] : (string[] | number[])[]
85+
>[""] : string[]
86+
>"" : ""
87+
>[1] : number[]
88+
>1 : 1
89+
>flat : { (depth: 4): (string | number)[]; (depth: 3): (string | number)[]; (depth: 2): (string | number)[]; (depth?: 1): (string | number)[]; (depth: 0): (string[] | number[])[]; (depth: number): (string[] | number[])[] | (string | number)[]; }
90+
91+
const expected7: string | number = actual7;
92+
>expected7 : string | number
93+
>actual7 : string | number
94+
95+
actual7 = undefined as string | number;
96+
>actual7 = undefined as string | number : string | number
97+
>actual7 : string | number
98+
>undefined as string | number : string | number
99+
>undefined : undefined
100+
101+
const f: any extends typeof actual7 ? true : false = false;
102+
>f : boolean
103+
>actual7 : string | number
104+
>true : true
105+
>false : false
106+
>false : false
107+

Diff for: tests/baselines/reference/arrayFlatMap.js

+10
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@ const array: number[] = [];
33
const readonlyArray: ReadonlyArray<number> = [];
44
array.flatMap((): ReadonlyArray<number> => []); // ok
55
readonlyArray.flatMap((): ReadonlyArray<number> => []); // ok
6+
7+
// #19535
8+
9+
let [actual] = [""].flatMap(undefined as () => string[] | string[][]);
10+
const expected: string | string[] = actual;
11+
actual = undefined as string | string[];
612

713

814
//// [arrayFlatMap.js]
915
var array = [];
1016
var readonlyArray = [];
1117
array.flatMap(function () { return []; }); // ok
1218
readonlyArray.flatMap(function () { return []; }); // ok
19+
// #19535
20+
var actual = [""].flatMap(undefined)[0];
21+
var expected = actual;
22+
actual = undefined;

0 commit comments

Comments
 (0)