Skip to content

Commit 6c2344e

Browse files
committed
Add comments to tests
1 parent 6ae5337 commit 6c2344e

File tree

2 files changed

+44
-24
lines changed

2 files changed

+44
-24
lines changed

tests/cases/compiler/controlFlowLetVar.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
declare let cond: boolean;
44

5+
// CFA for 'let' with no type annotation and initializer
56
function f1() {
67
let x;
78
if (cond) {
@@ -10,9 +11,10 @@ function f1() {
1011
if (cond) {
1112
x = "hello";
1213
}
13-
const y = x;
14+
const y = x; // string | number
1415
}
1516

17+
// CFA for 'let' with no type annotation and 'undefined' initializer
1618
function f2() {
1719
let x = undefined;
1820
if (cond) {
@@ -21,9 +23,10 @@ function f2() {
2123
if (cond) {
2224
x = "hello";
2325
}
24-
const y = x;
26+
const y = x; // string | number
2527
}
2628

29+
// CFA for 'let' with no type annotation and 'null' initializer
2730
function f3() {
2831
let x = null;
2932
if (cond) {
@@ -32,9 +35,10 @@ function f3() {
3235
if (cond) {
3336
x = "hello";
3437
}
35-
const y = x;
38+
const y = x; // string | number
3639
}
3740

41+
// No CFA for 'let' with with type annotation
3842
function f4() {
3943
let x: any;
4044
if (cond) {
@@ -43,9 +47,10 @@ function f4() {
4347
if (cond) {
4448
x = "hello";
4549
}
46-
const y = x;
50+
const y = x; // any
4751
}
4852

53+
// CFA for 'var' with no type annotation and initializer
4954
function f5() {
5055
var x;
5156
if (cond) {
@@ -54,9 +59,10 @@ function f5() {
5459
if (cond) {
5560
x = "hello";
5661
}
57-
const y = x;
62+
const y = x; // string | number
5863
}
5964

65+
// CFA for 'var' with no type annotation and 'undefined' initializer
6066
function f6() {
6167
var x = undefined;
6268
if (cond) {
@@ -65,9 +71,10 @@ function f6() {
6571
if (cond) {
6672
x = "hello";
6773
}
68-
const y = x;
74+
const y = x; // string | number
6975
}
7076

77+
// CFA for 'var' with no type annotation and 'null' initializer
7178
function f7() {
7279
var x = null;
7380
if (cond) {
@@ -76,9 +83,10 @@ function f7() {
7683
if (cond) {
7784
x = "hello";
7885
}
79-
const y = x;
86+
const y = x; // string | number
8087
}
8188

89+
// No CFA for 'var' with with type annotation
8290
function f8() {
8391
var x: any;
8492
if (cond) {
@@ -87,9 +95,10 @@ function f8() {
8795
if (cond) {
8896
x = "hello";
8997
}
90-
const y = x;
98+
const y = x; // any
9199
}
92100

101+
// No CFA for captured outer variables
93102
function f9() {
94103
let x;
95104
if (cond) {
@@ -98,12 +107,13 @@ function f9() {
98107
if (cond) {
99108
x = "hello";
100109
}
101-
const y = x;
110+
const y = x; // string | number
102111
function f() {
103-
const z = x;
112+
const z = x; // any
104113
}
105114
}
106115

116+
// No CFA for captured outer variables
107117
function f10() {
108118
let x;
109119
if (cond) {
@@ -112,8 +122,8 @@ function f10() {
112122
if (cond) {
113123
x = "hello";
114124
}
115-
const y = x;
125+
const y = x; // string | number
116126
const f = () => {
117-
const z = x;
127+
const z = x; // any
118128
};
119129
}

tests/cases/compiler/controlFlowNoImplicitAny.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
declare let cond: boolean;
55

6+
// CFA for 'let' with no type annotation and initializer
67
function f1() {
78
let x;
89
if (cond) {
@@ -11,9 +12,10 @@ function f1() {
1112
if (cond) {
1213
x = "hello";
1314
}
14-
const y = x;
15+
const y = x; // string | number
1516
}
1617

18+
// CFA for 'let' with no type annotation and 'undefined' initializer
1719
function f2() {
1820
let x = undefined;
1921
if (cond) {
@@ -22,9 +24,10 @@ function f2() {
2224
if (cond) {
2325
x = "hello";
2426
}
25-
const y = x;
27+
const y = x; // string | number
2628
}
2729

30+
// CFA for 'let' with no type annotation and 'null' initializer
2831
function f3() {
2932
let x = null;
3033
if (cond) {
@@ -33,9 +36,10 @@ function f3() {
3336
if (cond) {
3437
x = "hello";
3538
}
36-
const y = x;
39+
const y = x; // string | number
3740
}
3841

42+
// No CFA for 'let' with with type annotation
3943
function f4() {
4044
let x: any;
4145
if (cond) {
@@ -44,9 +48,10 @@ function f4() {
4448
if (cond) {
4549
x = "hello";
4650
}
47-
const y = x;
51+
const y = x; // any
4852
}
4953

54+
// CFA for 'var' with no type annotation and initializer
5055
function f5() {
5156
var x;
5257
if (cond) {
@@ -55,9 +60,10 @@ function f5() {
5560
if (cond) {
5661
x = "hello";
5762
}
58-
const y = x;
63+
const y = x; // string | number
5964
}
6065

66+
// CFA for 'var' with no type annotation and 'undefined' initializer
6167
function f6() {
6268
var x = undefined;
6369
if (cond) {
@@ -66,9 +72,10 @@ function f6() {
6672
if (cond) {
6773
x = "hello";
6874
}
69-
const y = x;
75+
const y = x; // string | number
7076
}
7177

78+
// CFA for 'var' with no type annotation and 'null' initializer
7279
function f7() {
7380
var x = null;
7481
if (cond) {
@@ -77,9 +84,10 @@ function f7() {
7784
if (cond) {
7885
x = "hello";
7986
}
80-
const y = x;
87+
const y = x; // string | number
8188
}
8289

90+
// No CFA for 'var' with with type annotation
8391
function f8() {
8492
var x: any;
8593
if (cond) {
@@ -88,9 +96,10 @@ function f8() {
8896
if (cond) {
8997
x = "hello";
9098
}
91-
const y = x;
99+
const y = x; // any
92100
}
93101

102+
// No CFA for captured outer variables
94103
function f9() {
95104
let x;
96105
if (cond) {
@@ -99,12 +108,13 @@ function f9() {
99108
if (cond) {
100109
x = "hello";
101110
}
102-
const y = x;
111+
const y = x; // string | number
103112
function f() {
104-
const z = x;
113+
const z = x; // any
105114
}
106115
}
107116

117+
// No CFA for captured outer variables
108118
function f10() {
109119
let x;
110120
if (cond) {
@@ -113,8 +123,8 @@ function f10() {
113123
if (cond) {
114124
x = "hello";
115125
}
116-
const y = x;
126+
const y = x; // string | number
117127
const f = () => {
118-
const z = x;
128+
const z = x; // any
119129
};
120130
}

0 commit comments

Comments
 (0)