Skip to content

Commit ab1458a

Browse files
committed
Tweak the test and add more duplicate name assignment tests
(Both valid and invalid.)
1 parent 38b5379 commit ab1458a

9 files changed

+529
-50
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
tests/cases/conformance/es6/destructuring/destructuringSameNames.ts(21,7): error TS2451: Cannot redeclare block-scoped variable 'foo1'.
2+
tests/cases/conformance/es6/destructuring/destructuringSameNames.ts(21,13): error TS2451: Cannot redeclare block-scoped variable 'foo1'.
3+
tests/cases/conformance/es6/destructuring/destructuringSameNames.ts(22,7): error TS2451: Cannot redeclare block-scoped variable 'foo2'.
4+
tests/cases/conformance/es6/destructuring/destructuringSameNames.ts(22,19): error TS2451: Cannot redeclare block-scoped variable 'foo2'.
5+
tests/cases/conformance/es6/destructuring/destructuringSameNames.ts(23,13): error TS2451: Cannot redeclare block-scoped variable 'foo3'.
6+
tests/cases/conformance/es6/destructuring/destructuringSameNames.ts(23,19): error TS2451: Cannot redeclare block-scoped variable 'foo3'.
7+
tests/cases/conformance/es6/destructuring/destructuringSameNames.ts(24,9): error TS2451: Cannot redeclare block-scoped variable 'foo4'.
8+
tests/cases/conformance/es6/destructuring/destructuringSameNames.ts(24,15): error TS2451: Cannot redeclare block-scoped variable 'foo4'.
9+
tests/cases/conformance/es6/destructuring/destructuringSameNames.ts(25,9): error TS2451: Cannot redeclare block-scoped variable 'foo5'.
10+
tests/cases/conformance/es6/destructuring/destructuringSameNames.ts(25,21): error TS2451: Cannot redeclare block-scoped variable 'foo5'.
11+
tests/cases/conformance/es6/destructuring/destructuringSameNames.ts(26,15): error TS2451: Cannot redeclare block-scoped variable 'foo6'.
12+
tests/cases/conformance/es6/destructuring/destructuringSameNames.ts(26,21): error TS2451: Cannot redeclare block-scoped variable 'foo6'.
13+
tests/cases/conformance/es6/destructuring/destructuringSameNames.ts(28,6): error TS2451: Cannot redeclare block-scoped variable 'blah1'.
14+
tests/cases/conformance/es6/destructuring/destructuringSameNames.ts(28,13): error TS2451: Cannot redeclare block-scoped variable 'blah1'.
15+
tests/cases/conformance/es6/destructuring/destructuringSameNames.ts(29,8): error TS2451: Cannot redeclare block-scoped variable 'blah2'.
16+
tests/cases/conformance/es6/destructuring/destructuringSameNames.ts(29,15): error TS2451: Cannot redeclare block-scoped variable 'blah2'.
17+
18+
19+
==== tests/cases/conformance/es6/destructuring/destructuringSameNames.ts (16 errors) ====
20+
// Valid cases
21+
22+
let { foo, foo: bar } = { foo: 1 };
23+
({ foo, foo } = { foo: 2 });
24+
({ foo, foo: bar } = { foo: 3 });
25+
({ foo: bar, foo } = { foo: 4 });
26+
({ foo, bar: foo } = { foo: 3, bar: 33 });
27+
({ bar: foo, foo } = { foo: 4, bar: 44 });
28+
({ foo: bar, foo: bar } = { foo: 5 });
29+
({ foo: bar, bar: foo } = { foo: 6, bar: 66 });
30+
({ foo: bar, foo: bar } = { foo: 7 });
31+
32+
[foo, foo] = [111, 1111];
33+
[foo, foo] = [222, 2222];
34+
[bar, foo, foo] = [333, 3333, 33333];
35+
[foo, bar, foo] = [333, 3333, 33333];
36+
[foo, foo, bar] = [444, 4444, 44444];
37+
38+
// Error cases
39+
40+
let { foo1, foo1 } = { foo1: 10 };
41+
~~~~
42+
!!! error TS2451: Cannot redeclare block-scoped variable 'foo1'.
43+
~~~~
44+
!!! error TS2451: Cannot redeclare block-scoped variable 'foo1'.
45+
let { foo2, bar2: foo2 } = { foo2: 20, bar2: 220 };
46+
~~~~
47+
!!! error TS2451: Cannot redeclare block-scoped variable 'foo2'.
48+
~~~~
49+
!!! error TS2451: Cannot redeclare block-scoped variable 'foo2'.
50+
let { bar3: foo3, foo3 } = { foo3: 30, bar3: 330 };
51+
~~~~
52+
!!! error TS2451: Cannot redeclare block-scoped variable 'foo3'.
53+
~~~~
54+
!!! error TS2451: Cannot redeclare block-scoped variable 'foo3'.
55+
const { foo4, foo4 } = { foo4: 40 };
56+
~~~~
57+
!!! error TS2451: Cannot redeclare block-scoped variable 'foo4'.
58+
~~~~
59+
!!! error TS2451: Cannot redeclare block-scoped variable 'foo4'.
60+
const { foo5, bar5: foo5 } = { foo5: 50, bar5: 550 };
61+
~~~~
62+
!!! error TS2451: Cannot redeclare block-scoped variable 'foo5'.
63+
~~~~
64+
!!! error TS2451: Cannot redeclare block-scoped variable 'foo5'.
65+
const { bar6: foo6, foo6 } = { foo6: 60, bar6: 660 };
66+
~~~~
67+
!!! error TS2451: Cannot redeclare block-scoped variable 'foo6'.
68+
~~~~
69+
!!! error TS2451: Cannot redeclare block-scoped variable 'foo6'.
70+
71+
let [blah1, blah1] = [111, 222];
72+
~~~~~
73+
!!! error TS2451: Cannot redeclare block-scoped variable 'blah1'.
74+
~~~~~
75+
!!! error TS2451: Cannot redeclare block-scoped variable 'blah1'.
76+
const [blah2, blah2] = [333, 444];
77+
~~~~~
78+
!!! error TS2451: Cannot redeclare block-scoped variable 'blah2'.
79+
~~~~~
80+
!!! error TS2451: Cannot redeclare block-scoped variable 'blah2'.
81+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//// [destructuringSameNames.ts]
2+
// Valid cases
3+
4+
let { foo, foo: bar } = { foo: 1 };
5+
({ foo, foo } = { foo: 2 });
6+
({ foo, foo: bar } = { foo: 3 });
7+
({ foo: bar, foo } = { foo: 4 });
8+
({ foo, bar: foo } = { foo: 3, bar: 33 });
9+
({ bar: foo, foo } = { foo: 4, bar: 44 });
10+
({ foo: bar, foo: bar } = { foo: 5 });
11+
({ foo: bar, bar: foo } = { foo: 6, bar: 66 });
12+
({ foo: bar, foo: bar } = { foo: 7 });
13+
14+
[foo, foo] = [111, 1111];
15+
[foo, foo] = [222, 2222];
16+
[bar, foo, foo] = [333, 3333, 33333];
17+
[foo, bar, foo] = [333, 3333, 33333];
18+
[foo, foo, bar] = [444, 4444, 44444];
19+
20+
// Error cases
21+
22+
let { foo1, foo1 } = { foo1: 10 };
23+
let { foo2, bar2: foo2 } = { foo2: 20, bar2: 220 };
24+
let { bar3: foo3, foo3 } = { foo3: 30, bar3: 330 };
25+
const { foo4, foo4 } = { foo4: 40 };
26+
const { foo5, bar5: foo5 } = { foo5: 50, bar5: 550 };
27+
const { bar6: foo6, foo6 } = { foo6: 60, bar6: 660 };
28+
29+
let [blah1, blah1] = [111, 222];
30+
const [blah2, blah2] = [333, 444];
31+
32+
33+
//// [destructuringSameNames.js]
34+
// Valid cases
35+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
36+
var _p = { foo: 1 }, foo = _p.foo, bar = _p.foo;
37+
(_a = { foo: 2 }, foo = _a.foo, foo = _a.foo);
38+
(_b = { foo: 3 }, foo = _b.foo, bar = _b.foo);
39+
(_c = { foo: 4 }, bar = _c.foo, foo = _c.foo);
40+
(_d = { foo: 3, bar: 33 }, foo = _d.foo, foo = _d.bar);
41+
(_e = { foo: 4, bar: 44 }, foo = _e.bar, foo = _e.foo);
42+
(_f = { foo: 5 }, bar = _f.foo, bar = _f.foo);
43+
(_g = { foo: 6, bar: 66 }, bar = _g.foo, foo = _g.bar);
44+
(_h = { foo: 7 }, bar = _h.foo, bar = _h.foo);
45+
_j = [111, 1111], foo = _j[0], foo = _j[1];
46+
_k = [222, 2222], foo = _k[0], foo = _k[1];
47+
_l = [333, 3333, 33333], bar = _l[0], foo = _l[1], foo = _l[2];
48+
_m = [333, 3333, 33333], foo = _m[0], bar = _m[1], foo = _m[2];
49+
_o = [444, 4444, 44444], foo = _o[0], foo = _o[1], bar = _o[2];
50+
// Error cases
51+
var _q = { foo1: 10 }, foo1 = _q.foo1, foo1 = _q.foo1;
52+
var _r = { foo2: 20, bar2: 220 }, foo2 = _r.foo2, foo2 = _r.bar2;
53+
var _s = { foo3: 30, bar3: 330 }, foo3 = _s.bar3, foo3 = _s.foo3;
54+
var _t = { foo4: 40 }, foo4 = _t.foo4, foo4 = _t.foo4;
55+
var _u = { foo5: 50, bar5: 550 }, foo5 = _u.foo5, foo5 = _u.bar5;
56+
var _v = { foo6: 60, bar6: 660 }, foo6 = _v.bar6, foo6 = _v.foo6;
57+
var _w = [111, 222], blah1 = _w[0], blah1 = _w[1];
58+
var _x = [333, 444], blah2 = _x[0], blah2 = _x[1];
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
=== tests/cases/conformance/es6/destructuring/destructuringSameNames.ts ===
2+
// Valid cases
3+
4+
let { foo, foo: bar } = { foo: 1 };
5+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 2, 5))
6+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 2, 25))
7+
>bar : Symbol(bar, Decl(destructuringSameNames.ts, 2, 10))
8+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 2, 25))
9+
10+
({ foo, foo } = { foo: 2 });
11+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 3, 2), Decl(destructuringSameNames.ts, 3, 7))
12+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 3, 2), Decl(destructuringSameNames.ts, 3, 7))
13+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 3, 17))
14+
15+
({ foo, foo: bar } = { foo: 3 });
16+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 4, 2), Decl(destructuringSameNames.ts, 4, 7))
17+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 4, 2), Decl(destructuringSameNames.ts, 4, 7))
18+
>bar : Symbol(bar, Decl(destructuringSameNames.ts, 2, 10))
19+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 4, 22))
20+
21+
({ foo: bar, foo } = { foo: 4 });
22+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 5, 2), Decl(destructuringSameNames.ts, 5, 12))
23+
>bar : Symbol(bar, Decl(destructuringSameNames.ts, 2, 10))
24+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 5, 2), Decl(destructuringSameNames.ts, 5, 12))
25+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 5, 22))
26+
27+
({ foo, bar: foo } = { foo: 3, bar: 33 });
28+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 6, 2))
29+
>bar : Symbol(bar, Decl(destructuringSameNames.ts, 6, 7))
30+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 2, 5))
31+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 6, 22))
32+
>bar : Symbol(bar, Decl(destructuringSameNames.ts, 6, 30))
33+
34+
({ bar: foo, foo } = { foo: 4, bar: 44 });
35+
>bar : Symbol(bar, Decl(destructuringSameNames.ts, 7, 2))
36+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 2, 5))
37+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 7, 12))
38+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 7, 22))
39+
>bar : Symbol(bar, Decl(destructuringSameNames.ts, 7, 30))
40+
41+
({ foo: bar, foo: bar } = { foo: 5 });
42+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 8, 2), Decl(destructuringSameNames.ts, 8, 12))
43+
>bar : Symbol(bar, Decl(destructuringSameNames.ts, 2, 10))
44+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 8, 2), Decl(destructuringSameNames.ts, 8, 12))
45+
>bar : Symbol(bar, Decl(destructuringSameNames.ts, 2, 10))
46+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 8, 27))
47+
48+
({ foo: bar, bar: foo } = { foo: 6, bar: 66 });
49+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 9, 2))
50+
>bar : Symbol(bar, Decl(destructuringSameNames.ts, 2, 10))
51+
>bar : Symbol(bar, Decl(destructuringSameNames.ts, 9, 12))
52+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 2, 5))
53+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 9, 27))
54+
>bar : Symbol(bar, Decl(destructuringSameNames.ts, 9, 35))
55+
56+
({ foo: bar, foo: bar } = { foo: 7 });
57+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 10, 2), Decl(destructuringSameNames.ts, 10, 12))
58+
>bar : Symbol(bar, Decl(destructuringSameNames.ts, 2, 10))
59+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 10, 2), Decl(destructuringSameNames.ts, 10, 12))
60+
>bar : Symbol(bar, Decl(destructuringSameNames.ts, 2, 10))
61+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 10, 27))
62+
63+
[foo, foo] = [111, 1111];
64+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 2, 5))
65+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 2, 5))
66+
67+
[foo, foo] = [222, 2222];
68+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 2, 5))
69+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 2, 5))
70+
71+
[bar, foo, foo] = [333, 3333, 33333];
72+
>bar : Symbol(bar, Decl(destructuringSameNames.ts, 2, 10))
73+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 2, 5))
74+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 2, 5))
75+
76+
[foo, bar, foo] = [333, 3333, 33333];
77+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 2, 5))
78+
>bar : Symbol(bar, Decl(destructuringSameNames.ts, 2, 10))
79+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 2, 5))
80+
81+
[foo, foo, bar] = [444, 4444, 44444];
82+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 2, 5))
83+
>foo : Symbol(foo, Decl(destructuringSameNames.ts, 2, 5))
84+
>bar : Symbol(bar, Decl(destructuringSameNames.ts, 2, 10))
85+
86+
// Error cases
87+
88+
let { foo1, foo1 } = { foo1: 10 };
89+
>foo1 : Symbol(foo1, Decl(destructuringSameNames.ts, 20, 5))
90+
>foo1 : Symbol(foo1, Decl(destructuringSameNames.ts, 20, 11))
91+
>foo1 : Symbol(foo1, Decl(destructuringSameNames.ts, 20, 22))
92+
93+
let { foo2, bar2: foo2 } = { foo2: 20, bar2: 220 };
94+
>foo2 : Symbol(foo2, Decl(destructuringSameNames.ts, 21, 5))
95+
>bar2 : Symbol(bar2, Decl(destructuringSameNames.ts, 21, 38))
96+
>foo2 : Symbol(foo2, Decl(destructuringSameNames.ts, 21, 11))
97+
>foo2 : Symbol(foo2, Decl(destructuringSameNames.ts, 21, 28))
98+
>bar2 : Symbol(bar2, Decl(destructuringSameNames.ts, 21, 38))
99+
100+
let { bar3: foo3, foo3 } = { foo3: 30, bar3: 330 };
101+
>bar3 : Symbol(bar3, Decl(destructuringSameNames.ts, 22, 38))
102+
>foo3 : Symbol(foo3, Decl(destructuringSameNames.ts, 22, 5))
103+
>foo3 : Symbol(foo3, Decl(destructuringSameNames.ts, 22, 17))
104+
>foo3 : Symbol(foo3, Decl(destructuringSameNames.ts, 22, 28))
105+
>bar3 : Symbol(bar3, Decl(destructuringSameNames.ts, 22, 38))
106+
107+
const { foo4, foo4 } = { foo4: 40 };
108+
>foo4 : Symbol(foo4, Decl(destructuringSameNames.ts, 23, 7))
109+
>foo4 : Symbol(foo4, Decl(destructuringSameNames.ts, 23, 13))
110+
>foo4 : Symbol(foo4, Decl(destructuringSameNames.ts, 23, 24))
111+
112+
const { foo5, bar5: foo5 } = { foo5: 50, bar5: 550 };
113+
>foo5 : Symbol(foo5, Decl(destructuringSameNames.ts, 24, 7))
114+
>bar5 : Symbol(bar5, Decl(destructuringSameNames.ts, 24, 40))
115+
>foo5 : Symbol(foo5, Decl(destructuringSameNames.ts, 24, 13))
116+
>foo5 : Symbol(foo5, Decl(destructuringSameNames.ts, 24, 30))
117+
>bar5 : Symbol(bar5, Decl(destructuringSameNames.ts, 24, 40))
118+
119+
const { bar6: foo6, foo6 } = { foo6: 60, bar6: 660 };
120+
>bar6 : Symbol(bar6, Decl(destructuringSameNames.ts, 25, 40))
121+
>foo6 : Symbol(foo6, Decl(destructuringSameNames.ts, 25, 7))
122+
>foo6 : Symbol(foo6, Decl(destructuringSameNames.ts, 25, 19))
123+
>foo6 : Symbol(foo6, Decl(destructuringSameNames.ts, 25, 30))
124+
>bar6 : Symbol(bar6, Decl(destructuringSameNames.ts, 25, 40))
125+
126+
let [blah1, blah1] = [111, 222];
127+
>blah1 : Symbol(blah1, Decl(destructuringSameNames.ts, 27, 5))
128+
>blah1 : Symbol(blah1, Decl(destructuringSameNames.ts, 27, 11))
129+
130+
const [blah2, blah2] = [333, 444];
131+
>blah2 : Symbol(blah2, Decl(destructuringSameNames.ts, 28, 7))
132+
>blah2 : Symbol(blah2, Decl(destructuringSameNames.ts, 28, 13))
133+

0 commit comments

Comments
 (0)