Skip to content

Commit 75c0bbc

Browse files
committed
Merge pull request microsoft#2773 from Microsoft/conformanceDestructuringAssignment
Conformance test spec change in section 4.17.1 destructuring assignment and 5.1.2 variable declaration conformance tests
2 parents 031c344 + 5ba01f3 commit 75c0bbc

File tree

33 files changed

+2847
-0
lines changed

33 files changed

+2847
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
//// [destructuringArrayBindingPatternAndAssignment1ES5.ts]
2+
/* AssignmentPattern:
3+
* ObjectAssignmentPattern
4+
* ArrayAssignmentPattern
5+
* ArrayAssignmentPattern:
6+
* [Elision<opt> AssignmentRestElementopt ]
7+
* [AssignmentElementList]
8+
* [AssignmentElementList, Elision<opt> AssignmentRestElementopt ]
9+
* AssignmentElementList:
10+
* Elision<opt> AssignmentElement
11+
* AssignmentElementList, Elisionopt AssignmentElement
12+
* AssignmentElement:
13+
* LeftHandSideExpression Initialiseropt
14+
* AssignmentPattern Initialiseropt
15+
* AssignmentRestElement:
16+
* ... LeftHandSideExpression
17+
*/
18+
19+
// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left.
20+
// An expression of type S is considered assignable to an assignment target V if one of the following is true
21+
22+
// 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,
23+
// S is the type Any, or
24+
25+
var [a0, a1]: any = undefined;
26+
var [a2 = false, a3 = 1]: any = undefined;
27+
28+
// 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,
29+
// 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,
30+
// where N is the numeric index of E in the array assignment pattern, or
31+
var [b0, b1, b2] = [2, 3, 4];
32+
var [b3, b4, b5]: [number, number, string] = [1, 2, "string"];
33+
34+
function foo() {
35+
return [1, 2, 3];
36+
}
37+
38+
var [b6, b7] = foo();
39+
var [...b8] = foo();
40+
41+
// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E.
42+
var temp = [1,2,3]
43+
var [c0, c1] = [...temp];
44+
var [c2] = [];
45+
var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]]
46+
var [[c5], c6]: [[string|number], boolean] = [[1], true];
47+
var [, c7] = [1, 2, 3];
48+
var [,,, c8] = [1, 2, 3, 4];
49+
var [,,, c9] = [1, 2, 3, 4];
50+
var [,,,...c10] = [1, 2, 3, 4, "hello"];
51+
var [c11, c12, ...c13] = [1, 2, "string"];
52+
var [c14, c15, c16] = [1, 2, "string"];
53+
54+
55+
56+
//// [destructuringArrayBindingPatternAndAssignment1ES5.js]
57+
/* AssignmentPattern:
58+
* ObjectAssignmentPattern
59+
* ArrayAssignmentPattern
60+
* ArrayAssignmentPattern:
61+
* [Elision<opt> AssignmentRestElementopt ]
62+
* [AssignmentElementList]
63+
* [AssignmentElementList, Elision<opt> AssignmentRestElementopt ]
64+
* AssignmentElementList:
65+
* Elision<opt> AssignmentElement
66+
* AssignmentElementList, Elisionopt AssignmentElement
67+
* AssignmentElement:
68+
* LeftHandSideExpression Initialiseropt
69+
* AssignmentPattern Initialiseropt
70+
* AssignmentRestElement:
71+
* ... LeftHandSideExpression
72+
*/
73+
// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left.
74+
// An expression of type S is considered assignable to an assignment target V if one of the following is true
75+
// 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,
76+
// S is the type Any, or
77+
var a0 = undefined[0], a1 = undefined[1];
78+
var _a = undefined[0], a2 = _a === void 0 ? false : _a, _b = undefined[1], a3 = _b === void 0 ? 1 : _b;
79+
// 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,
80+
// 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,
81+
// where N is the numeric index of E in the array assignment pattern, or
82+
var _c = [2, 3, 4], b0 = _c[0], b1 = _c[1], b2 = _c[2];
83+
var _d = [1, 2, "string"], b3 = _d[0], b4 = _d[1], b5 = _d[2];
84+
function foo() {
85+
return [1, 2, 3];
86+
}
87+
var _e = foo(), b6 = _e[0], b7 = _e[1];
88+
var b8 = foo().slice(0);
89+
// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E.
90+
var temp = [1, 2, 3];
91+
var _f = temp, c0 = _f[0], c1 = _f[1];
92+
var c2 = [][0];
93+
var _g = [[[]], [[[[]]]]], c3 = _g[0][0][0], c4 = _g[1][0][0][0][0];
94+
var _h = [[1], true], c5 = _h[0][0], c6 = _h[1];
95+
var _j = [1, 2, 3], c7 = _j[1];
96+
var _k = [1, 2, 3, 4], c8 = _k[3];
97+
var _l = [1, 2, 3, 4], c9 = _l[3];
98+
var _m = [1, 2, 3, 4, "hello"], c10 = _m.slice(3);
99+
var _o = [1, 2, "string"], c11 = _o[0], c12 = _o[1], c13 = _o.slice(2);
100+
var _p = [1, 2, "string"], c14 = _p[0], c15 = _p[1], c16 = _p[2];
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts ===
2+
/* AssignmentPattern:
3+
* ObjectAssignmentPattern
4+
* ArrayAssignmentPattern
5+
* ArrayAssignmentPattern:
6+
* [Elision<opt> AssignmentRestElementopt ]
7+
* [AssignmentElementList]
8+
* [AssignmentElementList, Elision<opt> AssignmentRestElementopt ]
9+
* AssignmentElementList:
10+
* Elision<opt> AssignmentElement
11+
* AssignmentElementList, Elisionopt AssignmentElement
12+
* AssignmentElement:
13+
* LeftHandSideExpression Initialiseropt
14+
* AssignmentPattern Initialiseropt
15+
* AssignmentRestElement:
16+
* ... LeftHandSideExpression
17+
*/
18+
19+
// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left.
20+
// An expression of type S is considered assignable to an assignment target V if one of the following is true
21+
22+
// 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,
23+
// S is the type Any, or
24+
25+
var [a0, a1]: any = undefined;
26+
>a0 : Symbol(a0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 23, 5))
27+
>a1 : Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 23, 8))
28+
>undefined : Symbol(undefined)
29+
30+
var [a2 = false, a3 = 1]: any = undefined;
31+
>a2 : Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 24, 5))
32+
>a3 : Symbol(a3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 24, 16))
33+
>undefined : Symbol(undefined)
34+
35+
// 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,
36+
// 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,
37+
// where N is the numeric index of E in the array assignment pattern, or
38+
var [b0, b1, b2] = [2, 3, 4];
39+
>b0 : Symbol(b0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 5))
40+
>b1 : Symbol(b1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 8))
41+
>b2 : Symbol(b2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 12))
42+
43+
var [b3, b4, b5]: [number, number, string] = [1, 2, "string"];
44+
>b3 : Symbol(b3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 5))
45+
>b4 : Symbol(b4, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 8))
46+
>b5 : Symbol(b5, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 12))
47+
48+
function foo() {
49+
>foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62))
50+
51+
return [1, 2, 3];
52+
}
53+
54+
var [b6, b7] = foo();
55+
>b6 : Symbol(b6, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 36, 5))
56+
>b7 : Symbol(b7, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 36, 8))
57+
>foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62))
58+
59+
var [...b8] = foo();
60+
>b8 : Symbol(b8, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 37, 5))
61+
>foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62))
62+
63+
// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E.
64+
var temp = [1,2,3]
65+
>temp : Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 40, 3))
66+
67+
var [c0, c1] = [...temp];
68+
>c0 : Symbol(c0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 41, 5))
69+
>c1 : Symbol(c1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 41, 8))
70+
>temp : Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 40, 3))
71+
72+
var [c2] = [];
73+
>c2 : Symbol(c2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 42, 5))
74+
75+
var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]]
76+
>c3 : Symbol(c3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 43, 7))
77+
>c4 : Symbol(c4, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 43, 17))
78+
79+
var [[c5], c6]: [[string|number], boolean] = [[1], true];
80+
>c5 : Symbol(c5, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 44, 6))
81+
>c6 : Symbol(c6, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 44, 10))
82+
83+
var [, c7] = [1, 2, 3];
84+
>c7 : Symbol(c7, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 45, 6))
85+
86+
var [,,, c8] = [1, 2, 3, 4];
87+
>c8 : Symbol(c8, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 46, 8))
88+
89+
var [,,, c9] = [1, 2, 3, 4];
90+
>c9 : Symbol(c9, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 47, 8))
91+
92+
var [,,,...c10] = [1, 2, 3, 4, "hello"];
93+
>c10 : Symbol(c10, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 48, 8))
94+
95+
var [c11, c12, ...c13] = [1, 2, "string"];
96+
>c11 : Symbol(c11, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 5))
97+
>c12 : Symbol(c12, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 9))
98+
>c13 : Symbol(c13, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 14))
99+
100+
var [c14, c15, c16] = [1, 2, "string"];
101+
>c14 : Symbol(c14, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 5))
102+
>c15 : Symbol(c15, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 9))
103+
>c16 : Symbol(c16, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 14))
104+
105+
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts ===
2+
/* AssignmentPattern:
3+
* ObjectAssignmentPattern
4+
* ArrayAssignmentPattern
5+
* ArrayAssignmentPattern:
6+
* [Elision<opt> AssignmentRestElementopt ]
7+
* [AssignmentElementList]
8+
* [AssignmentElementList, Elision<opt> AssignmentRestElementopt ]
9+
* AssignmentElementList:
10+
* Elision<opt> AssignmentElement
11+
* AssignmentElementList, Elisionopt AssignmentElement
12+
* AssignmentElement:
13+
* LeftHandSideExpression Initialiseropt
14+
* AssignmentPattern Initialiseropt
15+
* AssignmentRestElement:
16+
* ... LeftHandSideExpression
17+
*/
18+
19+
// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left.
20+
// An expression of type S is considered assignable to an assignment target V if one of the following is true
21+
22+
// 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,
23+
// S is the type Any, or
24+
25+
var [a0, a1]: any = undefined;
26+
>a0 : any
27+
>a1 : any
28+
>undefined : undefined
29+
30+
var [a2 = false, a3 = 1]: any = undefined;
31+
>a2 : boolean
32+
>false : boolean
33+
>a3 : number
34+
>1 : number
35+
>undefined : undefined
36+
37+
// 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,
38+
// 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,
39+
// where N is the numeric index of E in the array assignment pattern, or
40+
var [b0, b1, b2] = [2, 3, 4];
41+
>b0 : number
42+
>b1 : number
43+
>b2 : number
44+
>[2, 3, 4] : [number, number, number]
45+
>2 : number
46+
>3 : number
47+
>4 : number
48+
49+
var [b3, b4, b5]: [number, number, string] = [1, 2, "string"];
50+
>b3 : number
51+
>b4 : number
52+
>b5 : string
53+
>[1, 2, "string"] : [number, number, string]
54+
>1 : number
55+
>2 : number
56+
>"string" : string
57+
58+
function foo() {
59+
>foo : () => number[]
60+
61+
return [1, 2, 3];
62+
>[1, 2, 3] : number[]
63+
>1 : number
64+
>2 : number
65+
>3 : number
66+
}
67+
68+
var [b6, b7] = foo();
69+
>b6 : number
70+
>b7 : number
71+
>foo() : number[]
72+
>foo : () => number[]
73+
74+
var [...b8] = foo();
75+
>b8 : number[]
76+
>foo() : number[]
77+
>foo : () => number[]
78+
79+
// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E.
80+
var temp = [1,2,3]
81+
>temp : number[]
82+
>[1,2,3] : number[]
83+
>1 : number
84+
>2 : number
85+
>3 : number
86+
87+
var [c0, c1] = [...temp];
88+
>c0 : number
89+
>c1 : number
90+
>[...temp] : number[]
91+
>...temp : number
92+
>temp : number[]
93+
94+
var [c2] = [];
95+
>c2 : any
96+
>[] : undefined[]
97+
98+
var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]]
99+
>c3 : any
100+
>c4 : any
101+
>[[[]], [[[[]]]]] : [[undefined[]], [[[undefined[]]]]]
102+
>[[]] : [undefined[]]
103+
>[] : undefined[]
104+
>[[[[]]]] : [[[undefined[]]]]
105+
>[[[]]] : [[undefined[]]]
106+
>[[]] : [undefined[]]
107+
>[] : undefined[]
108+
109+
var [[c5], c6]: [[string|number], boolean] = [[1], true];
110+
>c5 : string | number
111+
>c6 : boolean
112+
>[[1], true] : [[number], boolean]
113+
>[1] : [number]
114+
>1 : number
115+
>true : boolean
116+
117+
var [, c7] = [1, 2, 3];
118+
> : undefined
119+
>c7 : number
120+
>[1, 2, 3] : [number, number, number]
121+
>1 : number
122+
>2 : number
123+
>3 : number
124+
125+
var [,,, c8] = [1, 2, 3, 4];
126+
> : undefined
127+
> : undefined
128+
> : undefined
129+
>c8 : number
130+
>[1, 2, 3, 4] : [number, number, number, number]
131+
>1 : number
132+
>2 : number
133+
>3 : number
134+
>4 : number
135+
136+
var [,,, c9] = [1, 2, 3, 4];
137+
> : undefined
138+
> : undefined
139+
> : undefined
140+
>c9 : number
141+
>[1, 2, 3, 4] : [number, number, number, number]
142+
>1 : number
143+
>2 : number
144+
>3 : number
145+
>4 : number
146+
147+
var [,,,...c10] = [1, 2, 3, 4, "hello"];
148+
> : undefined
149+
> : undefined
150+
> : undefined
151+
>c10 : (string | number)[]
152+
>[1, 2, 3, 4, "hello"] : (string | number)[]
153+
>1 : number
154+
>2 : number
155+
>3 : number
156+
>4 : number
157+
>"hello" : string
158+
159+
var [c11, c12, ...c13] = [1, 2, "string"];
160+
>c11 : string | number
161+
>c12 : string | number
162+
>c13 : (string | number)[]
163+
>[1, 2, "string"] : (string | number)[]
164+
>1 : number
165+
>2 : number
166+
>"string" : string
167+
168+
var [c14, c15, c16] = [1, 2, "string"];
169+
>c14 : number
170+
>c15 : number
171+
>c16 : string
172+
>[1, 2, "string"] : [number, number, string]
173+
>1 : number
174+
>2 : number
175+
>"string" : string
176+
177+

0 commit comments

Comments
 (0)