forked from prettier/prettier
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrebinding.js
197 lines (157 loc) · 3.35 KB
/
rebinding.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/* @flow
* test errors on illegal rebinding/reassignment
*
* type class let const var (reassign)
* type x x x x x x
* class x x x x x
* let x x x x x
* const x x x x x x
* var x x x x
*/
// type x *
function type_type() {
type A = number;
type A = number; // error: name already bound
}
function type_class() {
type A = number;
class A {} // error: name already bound
}
function type_let() {
type A = number;
let A = 0; // error: name already bound
}
function type_const() {
type A = number;
const A = 0; // error: name already bound
}
function type_var() {
type A = number;
var A = 0; // error: name already bound
}
function type_reassign() {
type A = number;
A = 42; // error: type alias ref'd from value pos
}
// class x *
function class_type() {
class A {}
type A = number; // error: name already bound
}
function class_class() {
class A {}
class A {} // error: name already bound
}
function class_let() {
class A {}
let A = 0; // error: name already bound
}
function class_const() {
class A {}
const A = 0; // error: name already bound
}
function class_var() {
class A {}
var A = 0; // error: name already bound
}
// let x *
function let_type() {
let A = 0;
type A = number; // error: name already bound
}
function let_class() {
let A = 0;
class A {} // error: name already bound
}
function let_let() {
let A = 0;
let A = 0; // error: name already bound
}
function let_const() {
let A = 0;
const A = 0; // error: name already bound
}
function let_var() {
let A = 0;
var A = 0; // error: name already bound
}
// const x *
function const_type() {
const A = 0;
type A = number; // error: name already bound
}
function const_class() {
const A = 0;
class A {} // error: name already bound
}
function const_let() {
const A = 0;
let A = 0; // error: name already bound
}
function const_const() {
const A = 0;
const A = 0; // error: name already bound
}
function const_var() {
const A = 0;
var A = 0; // error: name already bound
}
function const_reassign() {
const A = 0;
A = 42; // error: cannot be reassigned
}
// var x *
function var_type() {
var A = 0;
type A = number; // error: name already bound
}
function var_class() {
var A = 0;
class A {} // error: name already bound
}
function var_let() {
var A = 0;
let A = 0; // error: name already bound
}
function var_const() {
var A = 0;
const A = 0; // error: name already bound
}
function var_var() {
var A = 0;
var A = 0; // OK
}
// function x *
function function_toplevel() {
function a() {};
function a() {}; // OK
}
function function_block() {
{
function a() {};
function a() {}; // error: name already bound
}
}
// corner cases
function var_shadow_nested_scope() {
{
let x = 0;
{
var x = 0; // error: name already bound
}
}
}
function type_shadow_nested_scope() {
{
let x = 0;
{
type x = string; // error: name already bound
}
}
}
// fn params name clash
function fn_params_name_clash(x, x /* error: x already bound */) {}
function fn_params_clash_fn_binding(x,y) {
let x = 0; // error: x already bound
var y = 0; // OK
}