Skip to content

Commit b543074

Browse files
committed
Compile with --noImplicitThis
1. Add to various tsconfig.json 2. Add to Jakefile 3. Add annotations where needed. 4. Add workaround to shims.ts, which uses toplevel `this`.
1 parent 81e8840 commit b543074

File tree

9 files changed

+12
-9
lines changed

9 files changed

+12
-9
lines changed

Jakefile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ var builtLocalCompiler = path.join(builtLocalDirectory, compilerFilename);
284284
function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts, callback) {
285285
file(outFile, prereqs, function() {
286286
var compilerPath = useBuiltCompiler ? builtLocalCompiler : LKGCompiler;
287-
var options = "--noImplicitAny --noEmitOnError --types --pretty";
287+
var options = "--noImplicitAny --noImplicitThis --noEmitOnError --types --pretty";
288288
opts = opts || {};
289289
// Keep comments when specifically requested
290290
// or when in debug mode.

src/compiler/core.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1237,20 +1237,20 @@ namespace ts {
12371237
getSignatureConstructor(): new (checker: TypeChecker) => Signature;
12381238
}
12391239

1240-
function Symbol(flags: SymbolFlags, name: string) {
1240+
function Symbol(this: Symbol, flags: SymbolFlags, name: string) {
12411241
this.flags = flags;
12421242
this.name = name;
12431243
this.declarations = undefined;
12441244
}
12451245

1246-
function Type(checker: TypeChecker, flags: TypeFlags) {
1246+
function Type(this: Type, checker: TypeChecker, flags: TypeFlags) {
12471247
this.flags = flags;
12481248
}
12491249

12501250
function Signature(checker: TypeChecker) {
12511251
}
12521252

1253-
function Node(kind: SyntaxKind, pos: number, end: number) {
1253+
function Node(this: Node, kind: SyntaxKind, pos: number, end: number) {
12541254
this.kind = kind;
12551255
this.pos = pos;
12561256
this.end = end;

src/compiler/program.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,7 @@ namespace ts {
13981398
return noDiagnosticsTypeChecker || (noDiagnosticsTypeChecker = createTypeChecker(program, /*produceDiagnostics:*/ false));
13991399
}
14001400

1401-
function emit(sourceFile?: SourceFile, writeFileCallback?: WriteFileCallback, cancellationToken?: CancellationToken): EmitResult {
1401+
function emit(this: Program, sourceFile?: SourceFile, writeFileCallback?: WriteFileCallback, cancellationToken?: CancellationToken): EmitResult {
14021402
return runWithCancellationToken(() => emitWorker(this, sourceFile, writeFileCallback, cancellationToken));
14031403
}
14041404

src/compiler/sys.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ namespace ts {
200200
directoryExists(path: string) {
201201
return fso.FolderExists(path);
202202
},
203-
createDirectory(directoryName: string) {
203+
createDirectory(this: System, directoryName: string) {
204204
if (!this.directoryExists(directoryName)) {
205205
fso.CreateFolder(directoryName);
206206
}
@@ -500,7 +500,7 @@ namespace ts {
500500
},
501501
fileExists,
502502
directoryExists,
503-
createDirectory(directoryName: string) {
503+
createDirectory(this: System, directoryName: string) {
504504
if (!this.directoryExists(directoryName)) {
505505
_fs.mkdirSync(directoryName);
506506
}

src/compiler/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"compilerOptions": {
33
"noImplicitAny": true,
4+
"noImplicitThis": true,
45
"removeComments": true,
56
"preserveConstEnums": true,
67
"outFile": "../../built/local/tsc.js",

src/server/editorServices.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2081,7 +2081,7 @@ namespace ts.server {
20812081
const walkFns = {
20822082
goSubtree: true,
20832083
done: false,
2084-
leaf: function (relativeStart: number, relativeLength: number, ll: LineLeaf) {
2084+
leaf: function (this: ILineIndexWalker, relativeStart: number, relativeLength: number, ll: LineLeaf) {
20852085
if (!f(ll, relativeStart, relativeLength)) {
20862086
this.done = true;
20872087
}

src/server/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"compilerOptions": {
33
"noImplicitAny": true,
4+
"noImplicitThis": true,
45
"removeComments": true,
56
"preserveConstEnums": true,
67
"out": "../../built/local/tsserver.js",

src/services/shims.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/// <reference path='services.ts' />
1717

1818
/* @internal */
19-
let debugObjectHost = (<any>this);
19+
let debugObjectHost = new Function("return this")();
2020

2121
// We need to use 'null' to interface with the managed side.
2222
/* tslint:disable:no-null-keyword */

src/services/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"compilerOptions": {
33
"noImplicitAny": true,
4+
"noImplicitThis": true,
45
"removeComments": false,
56
"preserveConstEnums": true,
67
"outFile": "../../built/local/typescriptServices.js",

0 commit comments

Comments
 (0)