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
|
=== tests/cases/compiler/collisionThisExpressionAndParameter.ts ===
class Foo {
>Foo : Foo
x() {
>x : () => void
var _this = 10; // Local var. No this capture in x(), so no conflict.
>_this : number
>10 : 10
function inner(_this: number) { // Error
>inner : (_this: number) => (x: any) => any
>_this : number
return x => this; // New scope. So should inject new _this capture into function inner
>x => this : (x: any) => any
>x : any
>this : any
}
}
y() {
>y : () => void
var lamda = (_this: number) => { // Error
>lamda : (_this: number) => (x: any) => this
>(_this: number) => { // Error return x => this; // New scope. So should inject new _this capture } : (_this: number) => (x: any) => this
>_this : number
return x => this; // New scope. So should inject new _this capture
>x => this : (x: any) => this
>x : any
>this : this
}
}
z(_this: number) { // Error
>z : (_this: number) => void
>_this : number
var lambda = () => {
>lambda : () => (x: any) => this
>() => { return x => this; // New scope. So should inject new _this capture } : () => (x: any) => this
return x => this; // New scope. So should inject new _this capture
>x => this : (x: any) => this
>x : any
>this : this
}
}
x1() {
>x1 : () => void
var _this = 10; // Local var. No this capture in x(), so no conflict.
>_this : number
>10 : 10
function inner(_this: number) { // No Error
>inner : (_this: number) => void
>_this : number
}
}
y1() {
>y1 : () => void
var lamda = (_this: number) => { // No Error
>lamda : (_this: number) => void
>(_this: number) => { // No Error } : (_this: number) => void
>_this : number
}
}
z1(_this: number) { // No Error
>z1 : (_this: number) => void
>_this : number
var lambda = () => {
>lambda : () => void
>() => { } : () => void
}
}
}
class Foo1 {
>Foo1 : Foo1
constructor(_this: number) { // Error
>_this : number
var x2 = {
>x2 : { doStuff: (callback: any) => () => any; }
>{ doStuff: (callback) => () => { return callback(this); } } : { doStuff: (callback: any) => () => any; }
doStuff: (callback) => () => {
>doStuff : (callback: any) => () => any
>(callback) => () => { return callback(this); } : (callback: any) => () => any
>callback : any
>() => { return callback(this); } : () => any
return callback(this);
>callback(this) : any
>callback : any
>this : this
}
}
}
}
declare var console: {
>console : { log(msg: any): any; }
log(msg: any);
>log : (msg: any) => any
>msg : any
}
function f1(_this: number) {
>f1 : (_this: number) => void
>_this : number
x => { console.log(this.x); };
>x => { console.log(this.x); } : (x: any) => void
>x : any
>console.log(this.x) : any
>console.log : (msg: any) => any
>console : { log(msg: any): any; }
>log : (msg: any) => any
>this.x : any
>this : any
>x : any
}
declare class Foo2 {
>Foo2 : Foo2
constructor(_this: number); // no error - no code gen
>_this : number
z(_this: number); // no error - no code gen
>z : (_this: number) => any
>_this : number
}
declare function f2(_this: number); // no error
>f2 : (_this: number) => any
>_this : number
class Foo3 {
>Foo3 : Foo3
constructor(_this: string); // no code gen - no error
>_this : string
constructor(_this: number); // no code gen - no error
>_this : number
constructor(_this: any) { // Error
>_this : any
var x2 = {
>x2 : { doStuff: (callback: any) => () => any; }
>{ doStuff: (callback) => () => { return callback(this); } } : { doStuff: (callback: any) => () => any; }
doStuff: (callback) => () => {
>doStuff : (callback: any) => () => any
>(callback) => () => { return callback(this); } : (callback: any) => () => any
>callback : any
>() => { return callback(this); } : () => any
return callback(this);
>callback(this) : any
>callback : any
>this : this
}
}
}
z(_this: string); // no code gen - no error
>z : { (_this: string): any; (_this: number): any; }
>_this : string
z(_this: number); // no code gen - no error
>z : { (_this: string): any; (_this: number): any; }
>_this : number
z(_this: any) { // Error
>z : { (_this: string): any; (_this: number): any; }
>_this : any
var lambda = () => {
>lambda : () => (x: any) => this
>() => { return x => this; // New scope. So should inject new _this capture } : () => (x: any) => this
return x => this; // New scope. So should inject new _this capture
>x => this : (x: any) => this
>x : any
>this : this
}
}
}
declare var console: {
>console : { log(msg: any): any; }
log(msg: any);
>log : (msg: any) => any
>msg : any
}
function f3(_this: number); // no code gen - no error
>f3 : { (_this: number): any; (_this: string): any; }
>_this : number
function f3(_this: string); // no code gen - no error
>f3 : { (_this: number): any; (_this: string): any; }
>_this : string
function f3(_this: any) {
>f3 : { (_this: number): any; (_this: string): any; }
>_this : any
x => { console.log(this.x); };
>x => { console.log(this.x); } : (x: any) => void
>x : any
>console.log(this.x) : any
>console.log : (msg: any) => any
>console : { log(msg: any): any; }
>log : (msg: any) => any
>this.x : any
>this : any
>x : any
}
declare class Foo4 {
>Foo4 : Foo4
constructor(_this: string); // no code gen - no error
>_this : string
constructor(_this: number); // no code gen - no error
>_this : number
z(_this: string); // no code gen - no error
>z : { (_this: string): any; (_this: number): any; }
>_this : string
z(_this: number); // no code gen - no error
>z : { (_this: string): any; (_this: number): any; }
>_this : number
}
declare function f4(_this: number); // no code gen - no error
>f4 : { (_this: number): any; (_this: string): any; }
>_this : number
declare function f4(_this: string); // no code gen - no error
>f4 : { (_this: number): any; (_this: string): any; }
>_this : string
|