Skip to content

Commit f19844f

Browse files
authored
Merge pull request #9580 from Microsoft/compile-with-noImplicitThis
Compile with --noImplicitThis
2 parents 1d202f6 + 6414a57 commit f19844f

File tree

11 files changed

+29
-13
lines changed

11 files changed

+29
-13
lines changed

Gulpfile.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ import newer = require("gulp-newer");
1111
import tsc = require("gulp-typescript");
1212
declare module "gulp-typescript" {
1313
interface Settings {
14-
stripInternal?: boolean;
14+
pretty?: boolean;
1515
newLine?: string;
16+
noImplicitThis?: boolean;
17+
stripInternal?: boolean;
18+
types?: string[];
1619
}
1720
interface CompileStream extends NodeJS.ReadWriteStream {} // Either gulp or gulp-typescript has some odd typings which don't reflect reality, making this required
1821
}
@@ -306,6 +309,11 @@ function needsUpdate(source: string | string[], dest: string | string[]): boolea
306309

307310
function getCompilerSettings(base: tsc.Settings, useBuiltCompiler?: boolean): tsc.Settings {
308311
const copy: tsc.Settings = {};
312+
copy.noEmitOnError = true;
313+
copy.noImplicitAny = true;
314+
copy.noImplicitThis = true;
315+
copy.pretty = true;
316+
copy.types = [];
309317
for (const key in base) {
310318
copy[key] = base[key];
311319
}

Jakefile.js

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ namespace ts {
13991399
}
14001400

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

14051405
function isEmitBlocked(emitFileName: string): boolean {

src/compiler/sys.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ namespace ts {
182182
return matchFiles(path, extensions, excludes, includes, /*useCaseSensitiveFileNames*/ false, shell.CurrentDirectory, getAccessibleFileSystemEntries);
183183
}
184184

185-
return {
185+
const wscriptSystem: System = {
186186
args,
187187
newLine: "\r\n",
188188
useCaseSensitiveFileNames: false,
@@ -201,7 +201,7 @@ namespace ts {
201201
return fso.FolderExists(path);
202202
},
203203
createDirectory(directoryName: string) {
204-
if (!this.directoryExists(directoryName)) {
204+
if (!wscriptSystem.directoryExists(directoryName)) {
205205
fso.CreateFolder(directoryName);
206206
}
207207
},
@@ -221,6 +221,7 @@ namespace ts {
221221
}
222222
}
223223
};
224+
return wscriptSystem;
224225
}
225226

226227
function getNodeSystem(): System {
@@ -439,7 +440,7 @@ namespace ts {
439440
return filter<string>(_fs.readdirSync(path), p => fileSystemEntryExists(combinePaths(path, p), FileSystemEntryKind.Directory));
440441
}
441442

442-
return {
443+
const nodeSystem: System = {
443444
args: process.argv.slice(2),
444445
newLine: _os.EOL,
445446
useCaseSensitiveFileNames: useCaseSensitiveFileNames,
@@ -501,7 +502,7 @@ namespace ts {
501502
fileExists,
502503
directoryExists,
503504
createDirectory(directoryName: string) {
504-
if (!this.directoryExists(directoryName)) {
505+
if (!nodeSystem.directoryExists(directoryName)) {
505506
_fs.mkdirSync(directoryName);
506507
}
507508
},
@@ -549,6 +550,7 @@ namespace ts {
549550
return _fs.realpathSync(path);
550551
}
551552
};
553+
return nodeSystem;
552554
}
553555

554556
function getChakraSystem(): System {

src/compiler/tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
"compilerOptions": {
33
"noImplicitAny": true,
4+
"noImplicitThis": true,
45
"removeComments": true,
56
"preserveConstEnums": true,
7+
"pretty": true,
68
"outFile": "../../built/local/tsc.js",
79
"sourceMap": true,
810
"declaration": true,

src/harness/harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ namespace Utils {
127127
export function memoize<T extends Function>(f: T): T {
128128
const cache: { [idx: string]: any } = {};
129129

130-
return <any>(function() {
130+
return <any>(function(this: any) {
131131
const key = Array.prototype.join.call(arguments);
132132
const cachedResult = cache[key];
133133
if (cachedResult) {

src/server/editorServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2083,7 +2083,7 @@ namespace ts.server {
20832083
done: false,
20842084
leaf: function (relativeStart: number, relativeLength: number, ll: LineLeaf) {
20852085
if (!f(ll, relativeStart, relativeLength)) {
2086-
this.done = true;
2086+
walkFns.done = true;
20872087
}
20882088
}
20892089
};

src/server/tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
"compilerOptions": {
33
"noImplicitAny": true,
4+
"noImplicitThis": true,
45
"removeComments": true,
56
"preserveConstEnums": true,
7+
"pretty": true,
68
"out": "../../built/local/tsserver.js",
79
"sourceMap": true,
810
"stripInternal": true

src/services/shims.ts

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
"compilerOptions": {
33
"noImplicitAny": true,
4+
"noImplicitThis": true,
45
"removeComments": false,
56
"preserveConstEnums": true,
7+
"pretty": true,
68
"outFile": "../../built/local/typescriptServices.js",
79
"sourceMap": true,
810
"stripInternal": true,

0 commit comments

Comments
 (0)