Skip to content

Commit 183c1c4

Browse files
committed
Merge pull request #2753 from Microsoft/conformanceArrayLiteral
Conformance test for update in section 4.6 Array Literal
2 parents 3da1315 + db3705f commit 183c1c4

File tree

11 files changed

+1192
-0
lines changed

11 files changed

+1192
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
//// [arrayLiterals2ES5.ts]
2+
// ElementList: ( Modified )
3+
// Elisionopt AssignmentExpression
4+
// Elisionopt SpreadElement
5+
// ElementList, Elisionopt AssignmentExpression
6+
// ElementList, Elisionopt SpreadElement
7+
8+
// SpreadElement:
9+
// ... AssignmentExpression
10+
11+
var a0 = [,, 2, 3, 4]
12+
var a1 = ["hello", "world"]
13+
var a2 = [, , , ...a0, "hello"];
14+
var a3 = [,, ...a0]
15+
var a4 = [() => 1, ];
16+
var a5 = [...a0, , ]
17+
18+
// Each element expression in a non-empty array literal is processed as follows:
19+
// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19)
20+
// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal,
21+
// the element expression is contextually typed by the type of that property.
22+
23+
// The resulting type an array literal expression is determined as follows:
24+
// - If the array literal contains no spread elements and is contextually typed by a tuple-like type,
25+
// the resulting type is a tuple type constructed from the types of the element expressions.
26+
27+
var b0: [any, any, any] = [undefined, null, undefined];
28+
var b1: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];
29+
30+
// The resulting type an array literal expression is determined as follows:
31+
// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1),
32+
// the resulting type is a tuple type constructed from the types of the element expressions.
33+
34+
var [c0, c1] = [1, 2]; // tuple type [number, number]
35+
var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean]
36+
37+
// The resulting type an array literal expression is determined as follows:
38+
// - the resulting type is an array type with an element type that is the union of the types of the
39+
// non - spread element expressions and the numeric index signature types of the spread element expressions
40+
var temp = ["s", "t", "r"];
41+
var temp1 = [1, 2, 3];
42+
var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];
43+
var temp3 = [undefined, null, undefined];
44+
var temp4 = [];
45+
46+
interface myArray extends Array<Number> { }
47+
interface myArray2 extends Array<Number|String> { }
48+
var d0 = [1, true, ...temp,]; // has type (string|number|boolean)[]
49+
var d1 = [...temp]; // has type string[]
50+
var d2: number[] = [...temp1];
51+
var d3: myArray = [...temp1];
52+
var d4: myArray2 = [...temp, ...temp1];
53+
var d5 = [...temp3];
54+
var d6 = [...temp4];
55+
var d7 = [...[...temp1]];
56+
var d8: number[][] = [[...temp1]]
57+
var d9 = [[...temp1], ...["hello"]];
58+
59+
//// [arrayLiterals2ES5.js]
60+
// ElementList: ( Modified )
61+
// Elisionopt AssignmentExpression
62+
// Elisionopt SpreadElement
63+
// ElementList, Elisionopt AssignmentExpression
64+
// ElementList, Elisionopt SpreadElement
65+
// SpreadElement:
66+
// ... AssignmentExpression
67+
var a0 = [, , 2, 3, 4];
68+
var a1 = ["hello", "world"];
69+
var a2 = [, , ].concat(a0, ["hello"]);
70+
var a3 = [, ].concat(a0);
71+
var a4 = [function () { return 1; },];
72+
var a5 = a0.concat([,]);
73+
// Each element expression in a non-empty array literal is processed as follows:
74+
// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19)
75+
// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal,
76+
// the element expression is contextually typed by the type of that property.
77+
// The resulting type an array literal expression is determined as follows:
78+
// - If the array literal contains no spread elements and is contextually typed by a tuple-like type,
79+
// the resulting type is a tuple type constructed from the types of the element expressions.
80+
var b0 = [undefined, null, undefined];
81+
var b1 = [[1, 2, 3], ["hello", "string"]];
82+
// The resulting type an array literal expression is determined as follows:
83+
// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1),
84+
// the resulting type is a tuple type constructed from the types of the element expressions.
85+
var _a = [1, 2], c0 = _a[0], c1 = _a[1]; // tuple type [number, number]
86+
var _b = [1, 2, true], c2 = _b[0], c3 = _b[1]; // tuple type [number, number, boolean]
87+
// The resulting type an array literal expression is determined as follows:
88+
// - the resulting type is an array type with an element type that is the union of the types of the
89+
// non - spread element expressions and the numeric index signature types of the spread element expressions
90+
var temp = ["s", "t", "r"];
91+
var temp1 = [1, 2, 3];
92+
var temp2 = [[1, 2, 3], ["hello", "string"]];
93+
var temp3 = [undefined, null, undefined];
94+
var temp4 = [];
95+
var d0 = [1, true].concat(temp); // has type (string|number|boolean)[]
96+
var d1 = temp; // has type string[]
97+
var d2 = temp1;
98+
var d3 = temp1;
99+
var d4 = temp.concat(temp1);
100+
var d5 = temp3;
101+
var d6 = temp4;
102+
var d7 = temp1;
103+
var d8 = [temp1];
104+
var d9 = [temp1].concat(["hello"]);
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
=== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES5.ts ===
2+
// ElementList: ( Modified )
3+
// Elisionopt AssignmentExpression
4+
// Elisionopt SpreadElement
5+
// ElementList, Elisionopt AssignmentExpression
6+
// ElementList, Elisionopt SpreadElement
7+
8+
// SpreadElement:
9+
// ... AssignmentExpression
10+
11+
var a0 = [,, 2, 3, 4]
12+
>a0 : Symbol(a0, Decl(arrayLiterals2ES5.ts, 9, 3))
13+
14+
var a1 = ["hello", "world"]
15+
>a1 : Symbol(a1, Decl(arrayLiterals2ES5.ts, 10, 3))
16+
17+
var a2 = [, , , ...a0, "hello"];
18+
>a2 : Symbol(a2, Decl(arrayLiterals2ES5.ts, 11, 3))
19+
>a0 : Symbol(a0, Decl(arrayLiterals2ES5.ts, 9, 3))
20+
21+
var a3 = [,, ...a0]
22+
>a3 : Symbol(a3, Decl(arrayLiterals2ES5.ts, 12, 3))
23+
>a0 : Symbol(a0, Decl(arrayLiterals2ES5.ts, 9, 3))
24+
25+
var a4 = [() => 1, ];
26+
>a4 : Symbol(a4, Decl(arrayLiterals2ES5.ts, 13, 3))
27+
28+
var a5 = [...a0, , ]
29+
>a5 : Symbol(a5, Decl(arrayLiterals2ES5.ts, 14, 3))
30+
>a0 : Symbol(a0, Decl(arrayLiterals2ES5.ts, 9, 3))
31+
32+
// Each element expression in a non-empty array literal is processed as follows:
33+
// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19)
34+
// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal,
35+
// the element expression is contextually typed by the type of that property.
36+
37+
// The resulting type an array literal expression is determined as follows:
38+
// - If the array literal contains no spread elements and is contextually typed by a tuple-like type,
39+
// the resulting type is a tuple type constructed from the types of the element expressions.
40+
41+
var b0: [any, any, any] = [undefined, null, undefined];
42+
>b0 : Symbol(b0, Decl(arrayLiterals2ES5.ts, 25, 3))
43+
>undefined : Symbol(undefined)
44+
>undefined : Symbol(undefined)
45+
46+
var b1: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];
47+
>b1 : Symbol(b1, Decl(arrayLiterals2ES5.ts, 26, 3))
48+
49+
// The resulting type an array literal expression is determined as follows:
50+
// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1),
51+
// the resulting type is a tuple type constructed from the types of the element expressions.
52+
53+
var [c0, c1] = [1, 2]; // tuple type [number, number]
54+
>c0 : Symbol(c0, Decl(arrayLiterals2ES5.ts, 32, 5))
55+
>c1 : Symbol(c1, Decl(arrayLiterals2ES5.ts, 32, 8))
56+
57+
var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean]
58+
>c2 : Symbol(c2, Decl(arrayLiterals2ES5.ts, 33, 5))
59+
>c3 : Symbol(c3, Decl(arrayLiterals2ES5.ts, 33, 8))
60+
61+
// The resulting type an array literal expression is determined as follows:
62+
// - the resulting type is an array type with an element type that is the union of the types of the
63+
// non - spread element expressions and the numeric index signature types of the spread element expressions
64+
var temp = ["s", "t", "r"];
65+
>temp : Symbol(temp, Decl(arrayLiterals2ES5.ts, 38, 3))
66+
67+
var temp1 = [1, 2, 3];
68+
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3))
69+
70+
var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];
71+
>temp2 : Symbol(temp2, Decl(arrayLiterals2ES5.ts, 40, 3))
72+
73+
var temp3 = [undefined, null, undefined];
74+
>temp3 : Symbol(temp3, Decl(arrayLiterals2ES5.ts, 41, 3))
75+
>undefined : Symbol(undefined)
76+
>undefined : Symbol(undefined)
77+
78+
var temp4 = [];
79+
>temp4 : Symbol(temp4, Decl(arrayLiterals2ES5.ts, 42, 3))
80+
81+
interface myArray extends Array<Number> { }
82+
>myArray : Symbol(myArray, Decl(arrayLiterals2ES5.ts, 42, 15))
83+
>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11))
84+
>Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11))
85+
86+
interface myArray2 extends Array<Number|String> { }
87+
>myArray2 : Symbol(myArray2, Decl(arrayLiterals2ES5.ts, 44, 43))
88+
>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11))
89+
>Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11))
90+
>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11))
91+
92+
var d0 = [1, true, ...temp,]; // has type (string|number|boolean)[]
93+
>d0 : Symbol(d0, Decl(arrayLiterals2ES5.ts, 46, 3))
94+
>temp : Symbol(temp, Decl(arrayLiterals2ES5.ts, 38, 3))
95+
96+
var d1 = [...temp]; // has type string[]
97+
>d1 : Symbol(d1, Decl(arrayLiterals2ES5.ts, 47, 3))
98+
>temp : Symbol(temp, Decl(arrayLiterals2ES5.ts, 38, 3))
99+
100+
var d2: number[] = [...temp1];
101+
>d2 : Symbol(d2, Decl(arrayLiterals2ES5.ts, 48, 3))
102+
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3))
103+
104+
var d3: myArray = [...temp1];
105+
>d3 : Symbol(d3, Decl(arrayLiterals2ES5.ts, 49, 3))
106+
>myArray : Symbol(myArray, Decl(arrayLiterals2ES5.ts, 42, 15))
107+
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3))
108+
109+
var d4: myArray2 = [...temp, ...temp1];
110+
>d4 : Symbol(d4, Decl(arrayLiterals2ES5.ts, 50, 3))
111+
>myArray2 : Symbol(myArray2, Decl(arrayLiterals2ES5.ts, 44, 43))
112+
>temp : Symbol(temp, Decl(arrayLiterals2ES5.ts, 38, 3))
113+
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3))
114+
115+
var d5 = [...temp3];
116+
>d5 : Symbol(d5, Decl(arrayLiterals2ES5.ts, 51, 3))
117+
>temp3 : Symbol(temp3, Decl(arrayLiterals2ES5.ts, 41, 3))
118+
119+
var d6 = [...temp4];
120+
>d6 : Symbol(d6, Decl(arrayLiterals2ES5.ts, 52, 3))
121+
>temp4 : Symbol(temp4, Decl(arrayLiterals2ES5.ts, 42, 3))
122+
123+
var d7 = [...[...temp1]];
124+
>d7 : Symbol(d7, Decl(arrayLiterals2ES5.ts, 53, 3))
125+
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3))
126+
127+
var d8: number[][] = [[...temp1]]
128+
>d8 : Symbol(d8, Decl(arrayLiterals2ES5.ts, 54, 3))
129+
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3))
130+
131+
var d9 = [[...temp1], ...["hello"]];
132+
>d9 : Symbol(d9, Decl(arrayLiterals2ES5.ts, 55, 3))
133+
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3))
134+

0 commit comments

Comments
 (0)