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