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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
|
=== tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts ===
// GH#37454, GH#41044
type O = { a?: string; b: number; c: number; };
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 22))
>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 33))
type F1 = (arg: number) => any; // OK
>F1 : Symbol(F1, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 47))
>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 3, 11))
type F2 = ({ a: string }: O) => any; // Error
>F2 : Symbol(F2, Decl(renamingDestructuredPropertyInFunctionType.ts, 3, 31))
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 12))
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
type F3 = ({ a: string, b, c }: O) => any; // Error
>F3 : Symbol(F3, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 36))
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 12))
>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 23))
>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 26))
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
type F4 = ({ a: string }: O) => any; // Error
>F4 : Symbol(F4, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 42))
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 6, 12))
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
type F5 = ({ a: string, b, c }: O) => any; // Error
>F5 : Symbol(F5, Decl(renamingDestructuredPropertyInFunctionType.ts, 6, 36))
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 12))
>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 23))
>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 26))
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
type F6 = ({ a: string }) => typeof string; // OK
>F6 : Symbol(F6, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 42))
>a : Symbol(a)
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 12))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 12))
type F7 = ({ a: string, b: number }) => typeof number; // Error
>F7 : Symbol(F7, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 43))
>a : Symbol(a)
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 12))
>b : Symbol(b)
>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 23))
>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 23))
type F8 = ({ a, b: number }) => typeof number; // OK
>F8 : Symbol(F8, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 54))
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 12))
>b : Symbol(b)
>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 15))
>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 15))
type F9 = ([a, b, c]) => void; // OK
>F9 : Symbol(F9, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 46))
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 12))
>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 14))
>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 17))
type G1 = new (arg: number) => any; // OK
>G1 : Symbol(G1, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 30))
>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 15))
type G2 = new ({ a: string }: O) => any; // Error
>G2 : Symbol(G2, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 35))
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 14, 16))
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
type G3 = new ({ a: string, b, c }: O) => any; // Error
>G3 : Symbol(G3, Decl(renamingDestructuredPropertyInFunctionType.ts, 14, 40))
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 16))
>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 27))
>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 30))
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
type G4 = new ({ a: string }: O) => any; // Error
>G4 : Symbol(G4, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 46))
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 16, 16))
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
type G5 = new ({ a: string, b, c }: O) => any; // Error
>G5 : Symbol(G5, Decl(renamingDestructuredPropertyInFunctionType.ts, 16, 40))
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 16))
>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 27))
>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 30))
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
type G6 = new ({ a: string }) => typeof string; // OK
>G6 : Symbol(G6, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 46))
>a : Symbol(a)
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 16))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 16))
type G7 = new ({ a: string, b: number }) => typeof number; // Error
>G7 : Symbol(G7, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 47))
>a : Symbol(a)
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 16))
>b : Symbol(b)
>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 27))
>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 27))
type G8 = new ({ a, b: number }) => typeof number; // OK
>G8 : Symbol(G8, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 58))
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 16))
>b : Symbol(b)
>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 19))
>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 19))
type G9 = new ([a, b, c]) => void; // OK
>G9 : Symbol(G9, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 50))
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 16))
>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 18))
>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 21))
// Below are Error but renaming is retained in declaration emit,
// since elinding it would leave invalid syntax.
type F10 = ({ "a": string }) => void; // Error
>F10 : Symbol(F10, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 34))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 25, 13))
type F11 = ({ 2: string }) => void; // Error
>F11 : Symbol(F11, Decl(renamingDestructuredPropertyInFunctionType.ts, 25, 37))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 26, 13))
type F12 = ({ ["a"]: string }: O) => void; // Error
>F12 : Symbol(F12, Decl(renamingDestructuredPropertyInFunctionType.ts, 26, 35))
>"a" : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 27, 13))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 27, 13))
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
type F13 = ({ [2]: string }) => void; // Error
>F13 : Symbol(F13, Decl(renamingDestructuredPropertyInFunctionType.ts, 27, 42))
>2 : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 13))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 13))
type G10 = new ({ "a": string }) => void; // Error
>G10 : Symbol(G10, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 37))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 29, 17))
type G11 = new ({ 2: string }) => void; // Error
>G11 : Symbol(G11, Decl(renamingDestructuredPropertyInFunctionType.ts, 29, 41))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 30, 17))
type G12 = new ({ ["a"]: string }: O) => void; // Error
>G12 : Symbol(G12, Decl(renamingDestructuredPropertyInFunctionType.ts, 30, 39))
>"a" : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 31, 17))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 31, 17))
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
type G13 = new ({ [2]: string }) => void; // Error
>G13 : Symbol(G13, Decl(renamingDestructuredPropertyInFunctionType.ts, 31, 46))
>2 : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 32, 17))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 32, 17))
interface I {
>I : Symbol(I, Decl(renamingDestructuredPropertyInFunctionType.ts, 32, 41))
method1(arg: number): any; // OK
>method1 : Symbol(I.method1, Decl(renamingDestructuredPropertyInFunctionType.ts, 34, 13))
>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 35, 10))
method2({ a: string }): any; // Error
>method2 : Symbol(I.method2, Decl(renamingDestructuredPropertyInFunctionType.ts, 35, 28))
>a : Symbol(a)
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 36, 11))
(arg: number): any; // OK
>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 38, 3))
({ a: string }): any; // Error
>a : Symbol(a)
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 39, 4))
new (arg: number): any; // OK
>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 41, 7))
new ({ a: string }): any; // Error
>a : Symbol(a)
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 42, 8))
}
// Below are OK but renaming should be removed from declaration emit
function f1({ a: string }: O) { }
>f1 : Symbol(f1, Decl(renamingDestructuredPropertyInFunctionType.ts, 43, 1))
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 46, 13))
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
const f2 = function({ a: string }: O) { };
>f2 : Symbol(f2, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 5))
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 21))
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
const f3 = ({ a: string, b, c }: O) => { };
>f3 : Symbol(f3, Decl(renamingDestructuredPropertyInFunctionType.ts, 48, 5))
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 48, 13))
>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 48, 24))
>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 48, 27))
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
const f4 = function({ a: string }: O): typeof string { return string; };
>f4 : Symbol(f4, Decl(renamingDestructuredPropertyInFunctionType.ts, 49, 5))
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 49, 21))
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 49, 21))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 49, 21))
const f5 = ({ a: string, b, c }: O): typeof string => '';
>f5 : Symbol(f5, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 5))
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 13))
>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 24))
>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 27))
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 13))
const obj1 = {
>obj1 : Symbol(obj1, Decl(renamingDestructuredPropertyInFunctionType.ts, 51, 5))
method({ a: string }: O) { }
>method : Symbol(method, Decl(renamingDestructuredPropertyInFunctionType.ts, 51, 14))
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 52, 10))
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
};
const obj2 = {
>obj2 : Symbol(obj2, Decl(renamingDestructuredPropertyInFunctionType.ts, 54, 5))
method({ a: string }: O): typeof string { return string; }
>method : Symbol(method, Decl(renamingDestructuredPropertyInFunctionType.ts, 54, 14))
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 55, 10))
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 55, 10))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 55, 10))
};
function f6({ a: string = "" }: O) { }
>f6 : Symbol(f6, Decl(renamingDestructuredPropertyInFunctionType.ts, 56, 2))
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 57, 13))
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
const f7 = ({ a: string = "", b, c }: O) => { };
>f7 : Symbol(f7, Decl(renamingDestructuredPropertyInFunctionType.ts, 58, 5))
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 58, 13))
>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 58, 29))
>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 58, 32))
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
const f8 = ({ "a": string }: O) => { };
>f8 : Symbol(f8, Decl(renamingDestructuredPropertyInFunctionType.ts, 59, 5))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 59, 13))
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
function f9 ({ 2: string }) { };
>f9 : Symbol(f9, Decl(renamingDestructuredPropertyInFunctionType.ts, 59, 39))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 60, 14))
function f10 ({ ["a"]: string }: O) { };
>f10 : Symbol(f10, Decl(renamingDestructuredPropertyInFunctionType.ts, 60, 32))
>"a" : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 61, 15))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 61, 15))
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
const f11 = ({ [2]: string }) => { };
>f11 : Symbol(f11, Decl(renamingDestructuredPropertyInFunctionType.ts, 62, 5))
>2 : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 62, 15))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 62, 15))
// In below case `string` should be kept because it is used
function f12({ a: string = "" }: O): typeof string { return "a"; }
>f12 : Symbol(f12, Decl(renamingDestructuredPropertyInFunctionType.ts, 62, 38))
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 65, 14))
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 65, 14))
|