105 lines
5.2 KiB
Text
105 lines
5.2 KiB
Text
=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts ===
|
|
/* AssignmentPattern:
|
|
* ObjectAssignmentPattern
|
|
* ArrayAssignmentPattern
|
|
* ArrayAssignmentPattern:
|
|
* [Elision<opt> AssignmentRestElementopt ]
|
|
* [AssignmentElementList]
|
|
* [AssignmentElementList, Elision<opt> AssignmentRestElementopt ]
|
|
* AssignmentElementList:
|
|
* Elision<opt> AssignmentElement
|
|
* AssignmentElementList, Elisionopt AssignmentElement
|
|
* AssignmentElement:
|
|
* LeftHandSideExpression Initialiseropt
|
|
* AssignmentPattern Initialiseropt
|
|
* AssignmentRestElement:
|
|
* ... LeftHandSideExpression
|
|
*/
|
|
|
|
// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left.
|
|
// An expression of type S is considered assignable to an assignment target V if one of the following is true
|
|
|
|
// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V,
|
|
// S is the type Any, or
|
|
|
|
var [a0, a1]: any = undefined;
|
|
>a0 : Symbol(a0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 23, 5))
|
|
>a1 : Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 23, 8))
|
|
>undefined : Symbol(undefined)
|
|
|
|
var [a2 = false, a3 = 1]: any = undefined;
|
|
>a2 : Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 24, 5))
|
|
>a3 : Symbol(a3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 24, 16))
|
|
>undefined : Symbol(undefined)
|
|
|
|
// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V,
|
|
// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E,
|
|
// where N is the numeric index of E in the array assignment pattern, or
|
|
var [b0, b1, b2] = [2, 3, 4];
|
|
>b0 : Symbol(b0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 5))
|
|
>b1 : Symbol(b1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 8))
|
|
>b2 : Symbol(b2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 12))
|
|
|
|
var [b3, b4, b5]: [number, number, string] = [1, 2, "string"];
|
|
>b3 : Symbol(b3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 5))
|
|
>b4 : Symbol(b4, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 8))
|
|
>b5 : Symbol(b5, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 12))
|
|
|
|
function foo() {
|
|
>foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62))
|
|
|
|
return [1, 2, 3];
|
|
}
|
|
|
|
var [b6, b7] = foo();
|
|
>b6 : Symbol(b6, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 36, 5))
|
|
>b7 : Symbol(b7, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 36, 8))
|
|
>foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62))
|
|
|
|
var [...b8] = foo();
|
|
>b8 : Symbol(b8, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 37, 5))
|
|
>foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62))
|
|
|
|
// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E.
|
|
var temp = [1,2,3]
|
|
>temp : Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 40, 3))
|
|
|
|
var [c0, c1] = [...temp];
|
|
>c0 : Symbol(c0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 41, 5))
|
|
>c1 : Symbol(c1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 41, 8))
|
|
>temp : Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 40, 3))
|
|
|
|
var [c2] = [];
|
|
>c2 : Symbol(c2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 42, 5))
|
|
|
|
var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]]
|
|
>c3 : Symbol(c3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 43, 7))
|
|
>c4 : Symbol(c4, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 43, 17))
|
|
|
|
var [[c5], c6]: [[string|number], boolean] = [[1], true];
|
|
>c5 : Symbol(c5, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 44, 6))
|
|
>c6 : Symbol(c6, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 44, 10))
|
|
|
|
var [, c7] = [1, 2, 3];
|
|
>c7 : Symbol(c7, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 45, 6))
|
|
|
|
var [,,, c8] = [1, 2, 3, 4];
|
|
>c8 : Symbol(c8, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 46, 8))
|
|
|
|
var [,,, c9] = [1, 2, 3, 4];
|
|
>c9 : Symbol(c9, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 47, 8))
|
|
|
|
var [,,,...c10] = [1, 2, 3, 4, "hello"];
|
|
>c10 : Symbol(c10, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 48, 8))
|
|
|
|
var [c11, c12, ...c13] = [1, 2, "string"];
|
|
>c11 : Symbol(c11, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 5))
|
|
>c12 : Symbol(c12, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 9))
|
|
>c13 : Symbol(c13, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 14))
|
|
|
|
var [c14, c15, c16] = [1, 2, "string"];
|
|
>c14 : Symbol(c14, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 5))
|
|
>c15 : Symbol(c15, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 9))
|
|
>c16 : Symbol(c16, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 14))
|
|
|
|
|