Skip to content

Commit c9f5f3d

Browse files
committed
Remove --strictThisChecks
1 parent 1032cc5 commit c9f5f3d

17 files changed

Lines changed: 719 additions & 1123 deletions

src/compiler/binder.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,9 +1307,6 @@ namespace ts {
13071307
// as other properties in the object literal. So we use SymbolFlags.PropertyExcludes
13081308
// so that it will conflict with any other object literal members with the same
13091309
// name.
1310-
if (options.strictThisChecks) {
1311-
seenThisKeyword = true;
1312-
}
13131310
return bindPropertyOrMethodOrAccessor(<Declaration>node, SymbolFlags.Method | ((<MethodDeclaration>node).questionToken ? SymbolFlags.Optional : SymbolFlags.None),
13141311
isObjectLiteralMethod(node) ? SymbolFlags.PropertyExcludes : SymbolFlags.MethodExcludes);
13151312
case SyntaxKind.FunctionDeclaration:

src/compiler/checker.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3520,7 +3520,6 @@ namespace ts {
35203520
return isIndependentVariableLikeDeclaration(<VariableLikeDeclaration>declaration);
35213521
case SyntaxKind.MethodDeclaration:
35223522
case SyntaxKind.MethodSignature:
3523-
return compilerOptions.strictThisChecks ? false : isIndependentFunctionLikeDeclaration(<FunctionLikeDeclaration>declaration);
35243523
case SyntaxKind.Constructor:
35253524
return isIndependentFunctionLikeDeclaration(<FunctionLikeDeclaration>declaration);
35263525
}
@@ -4234,21 +4233,6 @@ namespace ts {
42344233
if (minArgumentCount < 0) {
42354234
minArgumentCount = declaration.parameters.length - (hasThisParameter ? 1 : 0);
42364235
}
4237-
if (!hasThisParameter && compilerOptions.strictThisChecks) {
4238-
if (declaration.kind === SyntaxKind.FunctionDeclaration ||
4239-
declaration.kind === SyntaxKind.CallSignature ||
4240-
declaration.kind == SyntaxKind.FunctionExpression ||
4241-
declaration.kind === SyntaxKind.FunctionType) {
4242-
thisType = voidType;
4243-
}
4244-
else if ((declaration.kind === SyntaxKind.MethodDeclaration || declaration.kind === SyntaxKind.MethodSignature)
4245-
&& (isClassLike(declaration.parent) || declaration.parent.kind === SyntaxKind.InterfaceDeclaration)) {
4246-
thisType = declaration.flags & NodeFlags.Static ?
4247-
getTypeOfSymbol(getSymbolOfNode(declaration.parent)) :
4248-
getThisType(declaration.name);
4249-
Debug.assert(!!thisType, "couldn't find implicit this type");
4250-
}
4251-
}
42524236

42534237
if (isJSConstructSignature) {
42544238
minArgumentCount--;

src/compiler/commandLineParser.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,6 @@ namespace ts {
137137
name: "skipDefaultLibCheck",
138138
type: "boolean",
139139
},
140-
{
141-
name: "strictThisChecks",
142-
type: "boolean",
143-
},
144140
{
145141
name: "out",
146142
type: "string",

src/compiler/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2407,7 +2407,6 @@ namespace ts {
24072407
rootDir?: string;
24082408
sourceMap?: boolean;
24092409
sourceRoot?: string;
2410-
strictThisChecks?: boolean;
24112410
suppressExcessPropertyErrors?: boolean;
24122411
suppressImplicitAnyIndexErrors?: boolean;
24132412
target?: ScriptTarget;

tests/baselines/reference/thisTypeInFunctions.js

Lines changed: 27 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ class C {
88
explicitThis(this: this, m: number): number {
99
return this.n + m;
1010
}
11-
implicitThis(m: number): number {
12-
return this.n + m;
13-
}
1411
explicitC(this: C, m: number): number {
1512
return this.n + m;
1613
}
@@ -29,8 +26,6 @@ interface I {
2926
explicitStructural(this: {a: number}): number;
3027
explicitInterface(this: I): number;
3128
explicitThis(this: this): number;
32-
implicitMethod(): number;
33-
implicitFunction: () => number;
3429
}
3530
function explicitStructural(this: { y: number }, x: number): number {
3631
return x + this.y;
@@ -39,7 +34,7 @@ function justThis(this: { y: number }): number {
3934
return this.y;
4035
}
4136
function implicitThis(n: number): number {
42-
return 12;
37+
return this.m + n + 12;
4338
}
4439
let impl: I = {
4540
a: 12,
@@ -54,10 +49,6 @@ let impl: I = {
5449
explicitThis() {
5550
return this.a;
5651
},
57-
implicitMethod() {
58-
return this.a;
59-
},
60-
implicitFunction: () => this.a, // ok, this: any because it refers to some outer object (window?)
6152
}
6253
impl.explicitVoid1 = function () { return 12; };
6354
impl.explicitVoid2 = () => 12;
@@ -66,9 +57,6 @@ impl.explicitInterface = function() { return this.a; };
6657
impl.explicitStructural = () => 12;
6758
impl.explicitInterface = () => 12;
6859
impl.explicitThis = function () { return this.a; };
69-
impl.implicitMethod = function () { return this.a; };
70-
impl.implicitMethod = () => 12;
71-
impl.implicitFunction = () => this.a; // ok, this: any because it refers to some outer object (window?)
7260
// parameter checking
7361
let ok: {y: number, f: (this: { y: number }, x: number) => number} = { y: 12, f: explicitStructural };
7462
let implicitAnyOk: {notSpecified: number, f: (x: number) => number} = { notSpecified: 12, f: implicitThis };
@@ -82,29 +70,26 @@ let ripped = c.explicitC;
8270
c.explicitC(12);
8371
c.explicitProperty(12);
8472
c.explicitThis(12);
85-
c.implicitThis(12);
8673
d.explicitC(12);
8774
d.explicitProperty(12);
8875
d.explicitThis(12);
89-
d.implicitThis(12);
9076
let reconstructed: {
9177
n: number,
9278
explicitThis(this: C, m: number): number, // note: this: this is not allowed in an object literal type.
93-
implicitThis(m: number): number,
9479
explicitC(this: C, m: number): number,
9580
explicitProperty: (this: {n : number}, m: number) => number,
9681
explicitVoid(this: void, m: number): number,
9782
} = {
9883
n: 12,
9984
explicitThis: c.explicitThis,
100-
implicitThis: c.implicitThis,
10185
explicitC: c.explicitC,
10286
explicitProperty: c.explicitProperty,
10387
explicitVoid: c.explicitVoid
10488
};
89+
reconstructed.explicitThis(10);
10590
reconstructed.explicitProperty(11);
106-
reconstructed.implicitThis(11);
107-
91+
let explicitVoid = reconstructed.explicitVoid;
92+
explicitVoid(12);
10893
// assignment checking
10994
let unboundToSpecified: (this: { y: number }, x: number) => number = x => x + this.y; // ok, this:any
11095
let specifiedToSpecified: (this: {y: number}, x: number) => number = explicitStructural;
@@ -143,8 +128,6 @@ c.explicitThis = function(this: C, m: number) { return this.n + m };
143128
c.explicitC = function(m) { return this.n + m };
144129
c.explicitProperty = function(m) { return this.n + m };
145130
c.explicitThis = function(m) { return this.n + m };
146-
c.implicitThis = function(m) { return this.n + m };
147-
c.implicitThis = reconstructed.implicitThis;
148131

149132
c.explicitC = function(this: B, m: number) { return this.n + m };
150133

@@ -154,19 +137,17 @@ c.explicitVoid = n => n;
154137
// class-based assignability
155138
class Base1 {
156139
x: number;
157-
public implicit(): number { return this.x; }
140+
public polymorphic(this: this): number { return this.x; }
158141
explicit(this: Base1): number { return this.x; }
159-
static implicitStatic(): number { return this.y; }
160142
static explicitStatic(this: typeof Base1): number { return this.y; }
161143
static y: number;
162-
163144
}
164145
class Derived1 extends Base1 {
165146
y: number
166147
}
167148
class Base2 {
168149
y: number
169-
implicit(): number { return this.y; }
150+
polymorphic(this: this): number { return this.y; }
170151
explicit(this: Base1): number { return this.x; }
171152
}
172153
class Derived2 extends Base2 {
@@ -176,14 +157,14 @@ let b1 = new Base1();
176157
let b2 = new Base2();
177158
let d1 = new Derived1();
178159
let d2 = new Derived2();
179-
d2.implicit = d1.implicit // ok, 'x' and 'y' in { x, y } (d assignable to f and vice versa)
180-
d1.implicit = d2.implicit // ok, 'x' and 'y' in { x, y } (f assignable to d and vice versa)
160+
d2.polymorphic = d1.polymorphic // ok, 'x' and 'y' in { x, y }
161+
d1.polymorphic = d2.polymorphic // ok, 'x' and 'y' in { x, y }
181162

182163
// bivariance-allowed cases
183-
d1.implicit = b2.implicit // ok, 'y' in D: { x, y } (d assignable e)
184-
d2.implicit = d1.explicit // ok, 'y' in { x, y } (c assignable to f)
185-
b1.implicit = d2.implicit // ok, 'x' and 'y' not in C: { x } (c assignable to f)
186-
b1.explicit = d2.implicit // ok, 'x' and 'y' not in C: { x } (c assignable to f)
164+
d1.polymorphic = b2.polymorphic // ok, 'y' in D: { x, y }
165+
d2.polymorphic = d1.explicit // ok, 'y' in { x, y }
166+
b1.polymorphic = d2.polymorphic // ok, 'x' and 'y' not in Base1: { x }
167+
b1.explicit = d2.polymorphic // ok, 'x' and 'y' not in Base1: { x }
187168

188169
////// use this-type for construction with new ////
189170
function InterfaceThis(this: I) {
@@ -206,7 +187,7 @@ declare var f: {
206187
};
207188
let n: number = f.call(12);
208189

209-
function missingTypeIsImplicitAny(this, a: number) { return a; }
190+
function missingTypeIsImplicitAny(this, a: number) { return this.anything + a; }
210191

211192

212193
//// [thisTypeInFunctions.js]
@@ -228,9 +209,6 @@ var C = (function () {
228209
C.prototype.explicitThis = function (m) {
229210
return this.n + m;
230211
};
231-
C.prototype.implicitThis = function (m) {
232-
return this.n + m;
233-
};
234212
C.prototype.explicitC = function (m) {
235213
return this.n + m;
236214
};
@@ -256,7 +234,7 @@ function justThis() {
256234
return this.y;
257235
}
258236
function implicitThis(n) {
259-
return 12;
237+
return this.m + n + 12;
260238
}
261239
var impl = {
262240
a: 12,
@@ -270,11 +248,7 @@ var impl = {
270248
},
271249
explicitThis: function () {
272250
return this.a;
273-
},
274-
implicitMethod: function () {
275-
return this.a;
276-
},
277-
implicitFunction: function () { return _this.a; }
251+
}
278252
};
279253
impl.explicitVoid1 = function () { return 12; };
280254
impl.explicitVoid2 = function () { return 12; };
@@ -283,9 +257,6 @@ impl.explicitInterface = function () { return this.a; };
283257
impl.explicitStructural = function () { return 12; };
284258
impl.explicitInterface = function () { return 12; };
285259
impl.explicitThis = function () { return this.a; };
286-
impl.implicitMethod = function () { return this.a; };
287-
impl.implicitMethod = function () { return 12; };
288-
impl.implicitFunction = function () { return _this.a; }; // ok, this: any because it refers to some outer object (window?)
289260
// parameter checking
290261
var ok = { y: 12, f: explicitStructural };
291262
var implicitAnyOk = { notSpecified: 12, f: implicitThis };
@@ -298,21 +269,20 @@ var ripped = c.explicitC;
298269
c.explicitC(12);
299270
c.explicitProperty(12);
300271
c.explicitThis(12);
301-
c.implicitThis(12);
302272
d.explicitC(12);
303273
d.explicitProperty(12);
304274
d.explicitThis(12);
305-
d.implicitThis(12);
306275
var reconstructed = {
307276
n: 12,
308277
explicitThis: c.explicitThis,
309-
implicitThis: c.implicitThis,
310278
explicitC: c.explicitC,
311279
explicitProperty: c.explicitProperty,
312280
explicitVoid: c.explicitVoid
313281
};
282+
reconstructed.explicitThis(10);
314283
reconstructed.explicitProperty(11);
315-
reconstructed.implicitThis(11);
284+
var explicitVoid = reconstructed.explicitVoid;
285+
explicitVoid(12);
316286
// assignment checking
317287
var unboundToSpecified = function (x) { return x + _this.y; }; // ok, this:any
318288
var specifiedToSpecified = explicitStructural;
@@ -344,18 +314,15 @@ c.explicitThis = function (m) { return this.n + m; };
344314
c.explicitC = function (m) { return this.n + m; };
345315
c.explicitProperty = function (m) { return this.n + m; };
346316
c.explicitThis = function (m) { return this.n + m; };
347-
c.implicitThis = function (m) { return this.n + m; };
348-
c.implicitThis = reconstructed.implicitThis;
349317
c.explicitC = function (m) { return this.n + m; };
350318
// this:void compatibility
351319
c.explicitVoid = function (n) { return n; };
352320
// class-based assignability
353321
var Base1 = (function () {
354322
function Base1() {
355323
}
356-
Base1.prototype.implicit = function () { return this.x; };
324+
Base1.prototype.polymorphic = function () { return this.x; };
357325
Base1.prototype.explicit = function () { return this.x; };
358-
Base1.implicitStatic = function () { return this.y; };
359326
Base1.explicitStatic = function () { return this.y; };
360327
return Base1;
361328
}());
@@ -369,7 +336,7 @@ var Derived1 = (function (_super) {
369336
var Base2 = (function () {
370337
function Base2() {
371338
}
372-
Base2.prototype.implicit = function () { return this.y; };
339+
Base2.prototype.polymorphic = function () { return this.y; };
373340
Base2.prototype.explicit = function () { return this.x; };
374341
return Base2;
375342
}());
@@ -384,13 +351,13 @@ var b1 = new Base1();
384351
var b2 = new Base2();
385352
var d1 = new Derived1();
386353
var d2 = new Derived2();
387-
d2.implicit = d1.implicit; // ok, 'x' and 'y' in { x, y } (d assignable to f and vice versa)
388-
d1.implicit = d2.implicit; // ok, 'x' and 'y' in { x, y } (f assignable to d and vice versa)
354+
d2.polymorphic = d1.polymorphic; // ok, 'x' and 'y' in { x, y }
355+
d1.polymorphic = d2.polymorphic; // ok, 'x' and 'y' in { x, y }
389356
// bivariance-allowed cases
390-
d1.implicit = b2.implicit; // ok, 'y' in D: { x, y } (d assignable e)
391-
d2.implicit = d1.explicit; // ok, 'y' in { x, y } (c assignable to f)
392-
b1.implicit = d2.implicit; // ok, 'x' and 'y' not in C: { x } (c assignable to f)
393-
b1.explicit = d2.implicit; // ok, 'x' and 'y' not in C: { x } (c assignable to f)
357+
d1.polymorphic = b2.polymorphic; // ok, 'y' in D: { x, y }
358+
d2.polymorphic = d1.explicit; // ok, 'y' in { x, y }
359+
b1.polymorphic = d2.polymorphic; // ok, 'x' and 'y' not in Base1: { x }
360+
b1.explicit = d2.polymorphic; // ok, 'x' and 'y' not in Base1: { x }
394361
////// use this-type for construction with new ////
395362
function InterfaceThis() {
396363
this.a = 12;
@@ -405,4 +372,4 @@ var interfaceThis = new InterfaceThis();
405372
var literalTypeThis = new LiteralTypeThis();
406373
var anyThis = new AnyThis();
407374
var n = f.call(12);
408-
function missingTypeIsImplicitAny(a) { return a; }
375+
function missingTypeIsImplicitAny(a) { return this.anything + a; }

0 commit comments

Comments
 (0)