Skip to content

Conformance test for update in section 4.6 Array Literal #2753

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions tests/baselines/reference/arrayLiterals2ES5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
//// [arrayLiterals2ES5.ts]
// ElementList: ( Modified )
// Elisionopt AssignmentExpression
// Elisionopt SpreadElement
// ElementList, Elisionopt AssignmentExpression
// ElementList, Elisionopt SpreadElement

// SpreadElement:
// ... AssignmentExpression

var a0 = [,, 2, 3, 4]
var a1 = ["hello", "world"]
var a2 = [, , , ...a0, "hello"];
var a3 = [,, ...a0]
var a4 = [() => 1, ];
var a5 = [...a0, , ]

// Each element expression in a non-empty array literal is processed as follows:
// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19)
// 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,
// the element expression is contextually typed by the type of that property.

// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is contextually typed by a tuple-like type,
// the resulting type is a tuple type constructed from the types of the element expressions.

var b0: [any, any, any] = [undefined, null, undefined];
var b1: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];

// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1),
// the resulting type is a tuple type constructed from the types of the element expressions.

var [c0, c1] = [1, 2]; // tuple type [number, number]
var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean]

// The resulting type an array literal expression is determined as follows:
// - the resulting type is an array type with an element type that is the union of the types of the
// non - spread element expressions and the numeric index signature types of the spread element expressions
var temp = ["s", "t", "r"];
var temp1 = [1, 2, 3];
var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];
var temp3 = [undefined, null, undefined];
var temp4 = [];

interface myArray extends Array<Number> { }
interface myArray2 extends Array<Number|String> { }
var d0 = [1, true, ...temp,]; // has type (string|number|boolean)[]
var d1 = [...temp]; // has type string[]
var d2: number[] = [...temp1];
var d3: myArray = [...temp1];
var d4: myArray2 = [...temp, ...temp1];
var d5 = [...temp3];
var d6 = [...temp4];
var d7 = [...[...temp1]];
var d8: number[][] = [[...temp1]]
var d9 = [[...temp1], ...["hello"]];

//// [arrayLiterals2ES5.js]
// ElementList: ( Modified )
// Elisionopt AssignmentExpression
// Elisionopt SpreadElement
// ElementList, Elisionopt AssignmentExpression
// ElementList, Elisionopt SpreadElement
// SpreadElement:
// ... AssignmentExpression
var a0 = [, , 2, 3, 4];
var a1 = ["hello", "world"];
var a2 = [, , ].concat(a0, ["hello"]);
var a3 = [, ].concat(a0);
var a4 = [function () { return 1; },];
var a5 = a0.concat([,]);
// Each element expression in a non-empty array literal is processed as follows:
// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19)
// 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,
// the element expression is contextually typed by the type of that property.
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is contextually typed by a tuple-like type,
// the resulting type is a tuple type constructed from the types of the element expressions.
var b0 = [undefined, null, undefined];
var b1 = [[1, 2, 3], ["hello", "string"]];
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1),
// the resulting type is a tuple type constructed from the types of the element expressions.
var _a = [1, 2], c0 = _a[0], c1 = _a[1]; // tuple type [number, number]
var _b = [1, 2, true], c2 = _b[0], c3 = _b[1]; // tuple type [number, number, boolean]
// The resulting type an array literal expression is determined as follows:
// - the resulting type is an array type with an element type that is the union of the types of the
// non - spread element expressions and the numeric index signature types of the spread element expressions
var temp = ["s", "t", "r"];
var temp1 = [1, 2, 3];
var temp2 = [[1, 2, 3], ["hello", "string"]];
var temp3 = [undefined, null, undefined];
var temp4 = [];
var d0 = [1, true].concat(temp); // has type (string|number|boolean)[]
var d1 = temp; // has type string[]
var d2 = temp1;
var d3 = temp1;
var d4 = temp.concat(temp1);
var d5 = temp3;
var d6 = temp4;
var d7 = temp1;
var d8 = [temp1];
var d9 = [temp1].concat(["hello"]);
134 changes: 134 additions & 0 deletions tests/baselines/reference/arrayLiterals2ES5.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
=== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES5.ts ===
// ElementList: ( Modified )
// Elisionopt AssignmentExpression
// Elisionopt SpreadElement
// ElementList, Elisionopt AssignmentExpression
// ElementList, Elisionopt SpreadElement

// SpreadElement:
// ... AssignmentExpression

var a0 = [,, 2, 3, 4]
>a0 : Symbol(a0, Decl(arrayLiterals2ES5.ts, 9, 3))

var a1 = ["hello", "world"]
>a1 : Symbol(a1, Decl(arrayLiterals2ES5.ts, 10, 3))

var a2 = [, , , ...a0, "hello"];
>a2 : Symbol(a2, Decl(arrayLiterals2ES5.ts, 11, 3))
>a0 : Symbol(a0, Decl(arrayLiterals2ES5.ts, 9, 3))

var a3 = [,, ...a0]
>a3 : Symbol(a3, Decl(arrayLiterals2ES5.ts, 12, 3))
>a0 : Symbol(a0, Decl(arrayLiterals2ES5.ts, 9, 3))

var a4 = [() => 1, ];
>a4 : Symbol(a4, Decl(arrayLiterals2ES5.ts, 13, 3))

var a5 = [...a0, , ]
>a5 : Symbol(a5, Decl(arrayLiterals2ES5.ts, 14, 3))
>a0 : Symbol(a0, Decl(arrayLiterals2ES5.ts, 9, 3))

// Each element expression in a non-empty array literal is processed as follows:
// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19)
// 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,
// the element expression is contextually typed by the type of that property.

// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is contextually typed by a tuple-like type,
// the resulting type is a tuple type constructed from the types of the element expressions.

var b0: [any, any, any] = [undefined, null, undefined];
>b0 : Symbol(b0, Decl(arrayLiterals2ES5.ts, 25, 3))
>undefined : Symbol(undefined)
>undefined : Symbol(undefined)

var b1: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];
>b1 : Symbol(b1, Decl(arrayLiterals2ES5.ts, 26, 3))

// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1),
// the resulting type is a tuple type constructed from the types of the element expressions.

var [c0, c1] = [1, 2]; // tuple type [number, number]
>c0 : Symbol(c0, Decl(arrayLiterals2ES5.ts, 32, 5))
>c1 : Symbol(c1, Decl(arrayLiterals2ES5.ts, 32, 8))

var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean]
>c2 : Symbol(c2, Decl(arrayLiterals2ES5.ts, 33, 5))
>c3 : Symbol(c3, Decl(arrayLiterals2ES5.ts, 33, 8))

// The resulting type an array literal expression is determined as follows:
// - the resulting type is an array type with an element type that is the union of the types of the
// non - spread element expressions and the numeric index signature types of the spread element expressions
var temp = ["s", "t", "r"];
>temp : Symbol(temp, Decl(arrayLiterals2ES5.ts, 38, 3))

var temp1 = [1, 2, 3];
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3))

var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];
>temp2 : Symbol(temp2, Decl(arrayLiterals2ES5.ts, 40, 3))

var temp3 = [undefined, null, undefined];
>temp3 : Symbol(temp3, Decl(arrayLiterals2ES5.ts, 41, 3))
>undefined : Symbol(undefined)
>undefined : Symbol(undefined)

var temp4 = [];
>temp4 : Symbol(temp4, Decl(arrayLiterals2ES5.ts, 42, 3))

interface myArray extends Array<Number> { }
>myArray : Symbol(myArray, Decl(arrayLiterals2ES5.ts, 42, 15))
>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11))
>Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11))

interface myArray2 extends Array<Number|String> { }
>myArray2 : Symbol(myArray2, Decl(arrayLiterals2ES5.ts, 44, 43))
>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11))
>Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11))
>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11))

var d0 = [1, true, ...temp,]; // has type (string|number|boolean)[]
>d0 : Symbol(d0, Decl(arrayLiterals2ES5.ts, 46, 3))
>temp : Symbol(temp, Decl(arrayLiterals2ES5.ts, 38, 3))

var d1 = [...temp]; // has type string[]
>d1 : Symbol(d1, Decl(arrayLiterals2ES5.ts, 47, 3))
>temp : Symbol(temp, Decl(arrayLiterals2ES5.ts, 38, 3))

var d2: number[] = [...temp1];
>d2 : Symbol(d2, Decl(arrayLiterals2ES5.ts, 48, 3))
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3))

var d3: myArray = [...temp1];
>d3 : Symbol(d3, Decl(arrayLiterals2ES5.ts, 49, 3))
>myArray : Symbol(myArray, Decl(arrayLiterals2ES5.ts, 42, 15))
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3))

var d4: myArray2 = [...temp, ...temp1];
>d4 : Symbol(d4, Decl(arrayLiterals2ES5.ts, 50, 3))
>myArray2 : Symbol(myArray2, Decl(arrayLiterals2ES5.ts, 44, 43))
>temp : Symbol(temp, Decl(arrayLiterals2ES5.ts, 38, 3))
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3))

var d5 = [...temp3];
>d5 : Symbol(d5, Decl(arrayLiterals2ES5.ts, 51, 3))
>temp3 : Symbol(temp3, Decl(arrayLiterals2ES5.ts, 41, 3))

var d6 = [...temp4];
>d6 : Symbol(d6, Decl(arrayLiterals2ES5.ts, 52, 3))
>temp4 : Symbol(temp4, Decl(arrayLiterals2ES5.ts, 42, 3))

var d7 = [...[...temp1]];
>d7 : Symbol(d7, Decl(arrayLiterals2ES5.ts, 53, 3))
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3))

var d8: number[][] = [[...temp1]]
>d8 : Symbol(d8, Decl(arrayLiterals2ES5.ts, 54, 3))
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3))

var d9 = [[...temp1], ...["hello"]];
>d9 : Symbol(d9, Decl(arrayLiterals2ES5.ts, 55, 3))
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3))

Loading