2
2
3
3
declare let cond: boolean ;
4
4
5
+ // CFA for 'let' with no type annotation and initializer
5
6
function f1 ( ) {
6
7
let x ;
7
8
if ( cond ) {
@@ -10,9 +11,10 @@ function f1() {
10
11
if ( cond ) {
11
12
x = "hello" ;
12
13
}
13
- const y = x ;
14
+ const y = x ; // string | number | undefined
14
15
}
15
16
17
+ // CFA for 'let' with no type annotation and 'undefined' initializer
16
18
function f2 ( ) {
17
19
let x = undefined ;
18
20
if ( cond ) {
@@ -21,9 +23,10 @@ function f2() {
21
23
if ( cond ) {
22
24
x = "hello" ;
23
25
}
24
- const y = x ;
26
+ const y = x ; // string | number | undefined
25
27
}
26
28
29
+ // CFA for 'let' with no type annotation and 'null' initializer
27
30
function f3 ( ) {
28
31
let x = null ;
29
32
if ( cond ) {
@@ -32,9 +35,10 @@ function f3() {
32
35
if ( cond ) {
33
36
x = "hello" ;
34
37
}
35
- const y = x ;
38
+ const y = x ; // string | number | null
36
39
}
37
40
41
+ // No CFA for 'let' with with type annotation
38
42
function f4 ( ) {
39
43
let x : any ;
40
44
if ( cond ) {
@@ -43,9 +47,10 @@ function f4() {
43
47
if ( cond ) {
44
48
x = "hello" ;
45
49
}
46
- const y = x ;
50
+ const y = x ; // any
47
51
}
48
52
53
+ // CFA for 'var' with no type annotation and initializer
49
54
function f5 ( ) {
50
55
var x ;
51
56
if ( cond ) {
@@ -54,9 +59,10 @@ function f5() {
54
59
if ( cond ) {
55
60
x = "hello" ;
56
61
}
57
- const y = x ;
62
+ const y = x ; // string | number | undefined
58
63
}
59
64
65
+ // CFA for 'var' with no type annotation and 'undefined' initializer
60
66
function f6 ( ) {
61
67
var x = undefined ;
62
68
if ( cond ) {
@@ -65,9 +71,10 @@ function f6() {
65
71
if ( cond ) {
66
72
x = "hello" ;
67
73
}
68
- const y = x ;
74
+ const y = x ; // string | number | undefined
69
75
}
70
76
77
+ // CFA for 'var' with no type annotation and 'null' initializer
71
78
function f7 ( ) {
72
79
var x = null ;
73
80
if ( cond ) {
@@ -76,9 +83,10 @@ function f7() {
76
83
if ( cond ) {
77
84
x = "hello" ;
78
85
}
79
- const y = x ;
86
+ const y = x ; // string | number | null
80
87
}
81
88
89
+ // No CFA for 'var' with with type annotation
82
90
function f8 ( ) {
83
91
var x : any ;
84
92
if ( cond ) {
@@ -87,9 +95,10 @@ function f8() {
87
95
if ( cond ) {
88
96
x = "hello" ;
89
97
}
90
- const y = x ;
98
+ const y = x ; // any
91
99
}
92
100
101
+ // No CFA for captured outer variables
93
102
function f9 ( ) {
94
103
let x ;
95
104
if ( cond ) {
@@ -98,12 +107,13 @@ function f9() {
98
107
if ( cond ) {
99
108
x = "hello" ;
100
109
}
101
- const y = x ;
110
+ const y = x ; // string | number | undefined
102
111
function f ( ) {
103
- const z = x ;
112
+ const z = x ; // any
104
113
}
105
114
}
106
115
116
+ // No CFA for captured outer variables
107
117
function f10 ( ) {
108
118
let x ;
109
119
if ( cond ) {
@@ -112,13 +122,14 @@ function f10() {
112
122
if ( cond ) {
113
123
x = "hello" ;
114
124
}
115
- const y = x ;
125
+ const y = x ; // string | number | undefined
116
126
const f = ( ) => {
117
- const z = x ;
127
+ const z = x ; // any
118
128
} ;
119
129
}
120
130
121
131
//// [controlFlowLetVar.js]
132
+ // CFA for 'let' with no type annotation and initializer
122
133
function f1 ( ) {
123
134
var x ;
124
135
if ( cond ) {
@@ -127,8 +138,9 @@ function f1() {
127
138
if ( cond ) {
128
139
x = "hello" ;
129
140
}
130
- var y = x ;
141
+ var y = x ; // string | number | undefined
131
142
}
143
+ // CFA for 'let' with no type annotation and 'undefined' initializer
132
144
function f2 ( ) {
133
145
var x = undefined ;
134
146
if ( cond ) {
@@ -137,8 +149,9 @@ function f2() {
137
149
if ( cond ) {
138
150
x = "hello" ;
139
151
}
140
- var y = x ;
152
+ var y = x ; // string | number | undefined
141
153
}
154
+ // CFA for 'let' with no type annotation and 'null' initializer
142
155
function f3 ( ) {
143
156
var x = null ;
144
157
if ( cond ) {
@@ -147,8 +160,9 @@ function f3() {
147
160
if ( cond ) {
148
161
x = "hello" ;
149
162
}
150
- var y = x ;
163
+ var y = x ; // string | number | null
151
164
}
165
+ // No CFA for 'let' with with type annotation
152
166
function f4 ( ) {
153
167
var x ;
154
168
if ( cond ) {
@@ -157,8 +171,9 @@ function f4() {
157
171
if ( cond ) {
158
172
x = "hello" ;
159
173
}
160
- var y = x ;
174
+ var y = x ; // any
161
175
}
176
+ // CFA for 'var' with no type annotation and initializer
162
177
function f5 ( ) {
163
178
var x ;
164
179
if ( cond ) {
@@ -167,8 +182,9 @@ function f5() {
167
182
if ( cond ) {
168
183
x = "hello" ;
169
184
}
170
- var y = x ;
185
+ var y = x ; // string | number | undefined
171
186
}
187
+ // CFA for 'var' with no type annotation and 'undefined' initializer
172
188
function f6 ( ) {
173
189
var x = undefined ;
174
190
if ( cond ) {
@@ -177,8 +193,9 @@ function f6() {
177
193
if ( cond ) {
178
194
x = "hello" ;
179
195
}
180
- var y = x ;
196
+ var y = x ; // string | number | undefined
181
197
}
198
+ // CFA for 'var' with no type annotation and 'null' initializer
182
199
function f7 ( ) {
183
200
var x = null ;
184
201
if ( cond ) {
@@ -187,8 +204,9 @@ function f7() {
187
204
if ( cond ) {
188
205
x = "hello" ;
189
206
}
190
- var y = x ;
207
+ var y = x ; // string | number | null
191
208
}
209
+ // No CFA for 'var' with with type annotation
192
210
function f8 ( ) {
193
211
var x ;
194
212
if ( cond ) {
@@ -197,8 +215,9 @@ function f8() {
197
215
if ( cond ) {
198
216
x = "hello" ;
199
217
}
200
- var y = x ;
218
+ var y = x ; // any
201
219
}
220
+ // No CFA for captured outer variables
202
221
function f9 ( ) {
203
222
var x ;
204
223
if ( cond ) {
@@ -207,11 +226,12 @@ function f9() {
207
226
if ( cond ) {
208
227
x = "hello" ;
209
228
}
210
- var y = x ;
229
+ var y = x ; // string | number | undefined
211
230
function f ( ) {
212
- var z = x ;
231
+ var z = x ; // any
213
232
}
214
233
}
234
+ // No CFA for captured outer variables
215
235
function f10 ( ) {
216
236
var x ;
217
237
if ( cond ) {
@@ -220,8 +240,8 @@ function f10() {
220
240
if ( cond ) {
221
241
x = "hello" ;
222
242
}
223
- var y = x ;
243
+ var y = x ; // string | number | undefined
224
244
var f = function ( ) {
225
- var z = x ;
245
+ var z = x ; // any
226
246
} ;
227
247
}
0 commit comments