|
| 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