From 7ddb1631bc923c79d6c3f1b6bd10797f6aeac6be Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 25 May 2016 13:38:53 -0700 Subject: [PATCH 1/2] Remove many uses of 'null' in harness. Remaining uses should be commented. --- src/harness/compilerRunner.ts | 1 + src/harness/external/chai.d.ts | 3 +- src/harness/fourslash.ts | 43 +++++++++++++-------------- src/harness/fourslashRunner.ts | 1 - src/harness/harness.ts | 39 ++++++++++++------------ src/harness/harnessLanguageService.ts | 2 +- src/harness/loggedIO.ts | 6 ++-- src/harness/projectsRunner.ts | 3 +- src/harness/runner.ts | 2 -- src/harness/rwcRunner.ts | 5 ++-- src/harness/test262Runner.ts | 1 + 11 files changed, 51 insertions(+), 55 deletions(-) diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index d368293bd65..1a83f8c4582 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -1,6 +1,7 @@ /// /// /// +// In harness baselines, null is different than undefined. See `generateActual` in `harness.ts`. /* tslint:disable:no-null-keyword */ const enum CompilerTestType { diff --git a/src/harness/external/chai.d.ts b/src/harness/external/chai.d.ts index 814de75e7b2..59cf2834b27 100644 --- a/src/harness/external/chai.d.ts +++ b/src/harness/external/chai.d.ts @@ -169,7 +169,6 @@ declare module chai { function notEqual(actual: any, expected: any, message?: string): void; function isTrue(value: any, message?: string): void; function isFalse(value: any, message?: string): void; - function isNull(value: any, message?: string): void; - function isNotNull(value: any, message?: string): void; + function isOk(actual: any, message?: string): void; } } \ No newline at end of file diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 4fd3161d1dc..0f11d12097d 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -18,7 +18,6 @@ /// /// /// -/* tslint:disable:no-null-keyword */ namespace FourSlash { ts.disableIncrementalParsing = false; @@ -198,7 +197,7 @@ namespace FourSlash { public lastKnownMarker: string = ""; // The file that's currently 'opened' - public activeFile: FourSlashFile = null; + public activeFile: FourSlashFile; // Whether or not we should format on keystrokes public enableFormatting = true; @@ -922,7 +921,7 @@ namespace FourSlash { public verifyCurrentParameterIsletiable(isVariable: boolean) { const signature = this.getActiveSignatureHelpItem(); - assert.isNotNull(signature); + assert.isOk(signature); assert.equal(isVariable, signature.isVariadic); } @@ -1911,7 +1910,7 @@ namespace FourSlash { public verifyNavigationItemsCount(expected: number, searchValue: string, matchKind?: string) { const items = this.languageService.getNavigateToItems(searchValue); let actual = 0; - let item: ts.NavigateToItem = null; + let item: ts.NavigateToItem; // Count only the match that match the same MatchKind for (let i = 0; i < items.length; i++) { @@ -2183,7 +2182,7 @@ namespace FourSlash { } private findFile(indexOrName: any) { - let result: FourSlashFile = null; + let result: FourSlashFile; if (typeof indexOrName === "number") { const index = indexOrName; if (index >= this.testData.files.length) { @@ -2352,9 +2351,15 @@ ${code} const ranges: Range[] = []; // Stuff related to the subfile we're parsing - let currentFileContent: string = null; + let currentFileContent: string = undefined; let currentFileName = fileName; let currentFileOptions: { [s: string]: string } = {}; + + function resetLocalData() { + currentFileContent = undefined; + currentFileOptions = {}; + currentFileName = fileName; + } for (let i = 0; i < lines.length; i++) { let line = lines[i]; @@ -2368,7 +2373,7 @@ ${code} // Subfile content line // Append to the current subfile content, inserting a newline needed - if (currentFileContent === null) { + if (currentFileContent === undefined) { currentFileContent = ""; } else { @@ -2400,10 +2405,7 @@ ${code} // Store result file files.push(file); - // Reset local data - currentFileContent = null; - currentFileOptions = {}; - currentFileName = fileName; + resetLocalData(); } currentFileName = basePath + "/" + match[2]; @@ -2430,10 +2432,7 @@ ${code} // Store result file files.push(file); - // Reset local data - currentFileContent = null; - currentFileOptions = {}; - currentFileName = fileName; + resetLocalData(); } } } @@ -2498,7 +2497,7 @@ ${code} if (markerValue === undefined) { reportError(fileName, location.sourceLine, location.sourceColumn, "Object markers can not be empty"); - return null; + return undefined; } const marker: Marker = { @@ -2527,7 +2526,7 @@ ${code} if (markerMap[name] !== undefined) { const message = "Marker '" + name + "' is duplicated in the source file contents."; reportError(marker.fileName, location.sourceLine, location.sourceColumn, message); - return null; + return undefined; } else { markerMap[name] = marker; @@ -2546,7 +2545,7 @@ ${code} let output = ""; /// The current marker (or maybe multi-line comment?) we're parsing, possibly - let openMarker: LocationInformation = null; + let openMarker: LocationInformation = undefined; /// A stack of the open range markers that are still unclosed const openRanges: RangeLocationInformation[] = []; @@ -2654,7 +2653,7 @@ ${code} difference += i + 1 - openMarker.sourcePosition; // Reset the state - openMarker = null; + openMarker = undefined; state = State.none; } break; @@ -2676,7 +2675,7 @@ ${code} difference += i + 1 - openMarker.sourcePosition; // Reset the state - openMarker = null; + openMarker = undefined; state = State.none; } else if (validMarkerChars.indexOf(currentChar) < 0) { @@ -2688,7 +2687,7 @@ ${code} // Bail out the text we've gathered so far back into the output flush(i); lastNormalCharPosition = i; - openMarker = null; + openMarker = undefined; state = State.none; } @@ -2719,7 +2718,7 @@ ${code} reportError(fileName, openRange.sourceLine, openRange.sourceColumn, "Unterminated range."); } - if (openMarker !== null) { + if (openMarker) { reportError(fileName, openMarker.sourceLine, openMarker.sourceColumn, "Unterminated marker."); } diff --git a/src/harness/fourslashRunner.ts b/src/harness/fourslashRunner.ts index 386bd9e340c..0047e851fc1 100644 --- a/src/harness/fourslashRunner.ts +++ b/src/harness/fourslashRunner.ts @@ -1,7 +1,6 @@ /// /// /// -/* tslint:disable:no-null-keyword */ const enum FourSlashTestType { Native, diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 5b26829cf4a..d6959c2a54f 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -23,7 +23,6 @@ /// /// /// -/* tslint:disable:no-null-keyword */ // Block scoped definitions work poorly for global variables, temporarily enable var /* tslint:disable:no-var-keyword */ @@ -32,7 +31,7 @@ var _chai: typeof chai = require("chai"); var assert: typeof _chai.assert = _chai.assert; declare var __dirname: string; // Node-specific -var global = Function("return this").call(null); +var global = Function("return this").call(undefined); /* tslint:enable:no-var-keyword */ namespace Utils { @@ -558,15 +557,9 @@ namespace Harness { } export function directoryName(path: string) { - let dirPath = pathModule.dirname(path); - + const dirPath = pathModule.dirname(path); // Node will just continue to repeat the root path, rather than return null - if (dirPath === path) { - dirPath = null; - } - else { - return dirPath; - } + return dirPath === path ? undefined : dirPath; } export let listFiles: typeof IO.listFiles = (path, spec?, options?) => { @@ -634,7 +627,7 @@ namespace Harness { xhr.send(); } catch (e) { - return { status: 404, responseText: null }; + return { status: 404, responseText: undefined }; } return waitForXHR(xhr); @@ -651,7 +644,7 @@ namespace Harness { } catch (e) { log(`XHR Error: ${e}`); - return { status: 500, responseText: null }; + return { status: 500, responseText: undefined }; } return waitForXHR(xhr); @@ -663,7 +656,7 @@ namespace Harness { } export function deleteFile(path: string) { - Http.writeToServerSync(serverRoot + path, "DELETE", null); + Http.writeToServerSync(serverRoot + path, "DELETE"); } export function directoryExists(path: string): boolean { @@ -674,7 +667,7 @@ namespace Harness { let dirPath = path; // root of the server if (dirPath.match(/localhost:\d+$/) || dirPath.match(/localhost:\d+\/$/)) { - dirPath = null; + dirPath = undefined; // path + fileName } else if (dirPath.indexOf(".") === -1) { @@ -722,7 +715,7 @@ namespace Harness { return response.responseText; } else { - return null; + return undefined; } } @@ -1418,7 +1411,9 @@ namespace Harness { const opts: CompilerSettings = {}; let match: RegExpExecArray; - while ((match = optionRegex.exec(content)) != null) { + /* tslint:disable:no-null-keyword */ + while ((match = optionRegex.exec(content)) !== null) { + /* tslint:enable:no-null-keyword */ opts[match[1]] = match[2]; } @@ -1435,9 +1430,9 @@ namespace Harness { const lines = Utils.splitContentByNewlines(code); // Stuff related to the subfile we're parsing - let currentFileContent: string = null; + let currentFileContent: string = undefined; let currentFileOptions: any = {}; - let currentFileName: any = null; + let currentFileName: any = undefined; let refs: string[] = []; for (let i = 0; i < lines.length; i++) { @@ -1465,7 +1460,7 @@ namespace Harness { testUnitData.push(newTestFile); // Reset local data - currentFileContent = null; + currentFileContent = undefined; currentFileOptions = {}; currentFileName = testMetaData[2]; refs = []; @@ -1478,7 +1473,7 @@ namespace Harness { else { // Subfile content line // Append to the current subfile content, inserting a newline needed - if (currentFileContent === null) { + if (currentFileContent === undefined) { currentFileContent = ""; } else { @@ -1601,7 +1596,9 @@ namespace Harness { // Store the content in the 'local' folder so we // can accept it later (manually) + /* tslint:disable:no-null-keyword */ if (actual !== null) { + /* tslint:enable:no-null-keyword */ IO.writeFile(actualFileName, actual); } @@ -1618,7 +1615,9 @@ namespace Harness { const refFileName = referencePath(relativeFileName, opts && opts.Baselinefolder, opts && opts.Subfolder); + /* tslint:disable:no-null-keyword */ if (actual === null) { + /* tslint:enable:no-null-keyword */ actual = ""; } diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index bd370b3601b..b3478e40609 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -172,7 +172,7 @@ namespace Harness.LanguageService { */ public positionToLineAndCharacter(fileName: string, position: number): ts.LineAndCharacter { const script: ScriptInfo = this.fileNameToScript[fileName]; - assert.isNotNull(script); + assert.isOk(script); return ts.computeLineAndCharacterOfPosition(script.getLineMap(), position); } diff --git a/src/harness/loggedIO.ts b/src/harness/loggedIO.ts index d468b371fbe..1c399b30a1d 100644 --- a/src/harness/loggedIO.ts +++ b/src/harness/loggedIO.ts @@ -1,7 +1,6 @@ /// /// /// -/* tslint:disable:no-null-keyword */ interface FileInformation { contents: string; @@ -94,7 +93,7 @@ namespace Playback { return lookup[s] = func(s); }); run.reset = () => { - lookup = null; + lookup = undefined; }; return run; @@ -170,7 +169,8 @@ namespace Playback { path => callAndRecord(underlying.fileExists(path), recordLog.fileExists, { path }), memoize(path => { // If we read from the file, it must exist - if (findResultByPath(wrapper, replayLog.filesRead, path, null) !== null) { + const noResult = {}; + if (findResultByPath(wrapper, replayLog.filesRead, path, noResult) !== noResult) { return true; } else { diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index 9ee4359d8d3..d4e91d43efe 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -1,6 +1,5 @@ /// /// -/* tslint:disable:no-null-keyword */ // Test case is json of below type in tests/cases/project/ interface ProjectRunnerTestCase { @@ -53,7 +52,7 @@ class ProjectRunner extends RunnerBase { private runProjectTestCase(testCaseFileName: string) { let testCase: ProjectRunnerTestCase & ts.CompilerOptions; - let testFileText: string = null; + let testFileText: string; try { testFileText = Harness.IO.readFile(testCaseFileName); } diff --git a/src/harness/runner.ts b/src/harness/runner.ts index bb3cafea0a8..b56959d7e5d 100644 --- a/src/harness/runner.ts +++ b/src/harness/runner.ts @@ -20,8 +20,6 @@ /// /// -/* tslint:disable:no-null-keyword */ - let runners: RunnerBase[] = []; let iterations = 1; diff --git a/src/harness/rwcRunner.ts b/src/harness/rwcRunner.ts index 39231435bf5..99b1ce8cc88 100644 --- a/src/harness/rwcRunner.ts +++ b/src/harness/rwcRunner.ts @@ -2,6 +2,7 @@ /// /// /// +// In harness baselines, null is different than undefined. See `generateActual` in `harness.ts`. /* tslint:disable:no-null-keyword */ namespace RWC { @@ -123,7 +124,7 @@ namespace RWC { opts.options.noLib = true; // Emit the results - compilerOptions = null; + compilerOptions = undefined; const output = Harness.Compiler.compileFiles( inputFiles, otherFiles, @@ -139,7 +140,7 @@ namespace RWC { function getHarnessCompilerInputUnit(fileName: string): Harness.Compiler.TestFile { const unitName = ts.normalizeSlashes(Harness.IO.resolvePath(fileName)); - let content: string = null; + let content: string; try { content = Harness.IO.readFile(unitName); } diff --git a/src/harness/test262Runner.ts b/src/harness/test262Runner.ts index cc9957c1fac..241af5f3d00 100644 --- a/src/harness/test262Runner.ts +++ b/src/harness/test262Runner.ts @@ -1,5 +1,6 @@ /// /// +// In harness baselines, null is different than undefined. See `generateActual` in `harness.ts`. /* tslint:disable:no-null-keyword */ class Test262BaselineRunner extends RunnerBase { From 5a627ad1761218066bdcb2771c40750eac7d4a0b Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 26 May 2016 06:01:20 -0700 Subject: [PATCH 2/2] Fix trailing whitespace --- src/harness/fourslash.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 0f11d12097d..3bce13820d7 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2354,7 +2354,7 @@ ${code} let currentFileContent: string = undefined; let currentFileName = fileName; let currentFileOptions: { [s: string]: string } = {}; - + function resetLocalData() { currentFileContent = undefined; currentFileOptions = {};