Remove many uses of 'null' in harness. Remaining uses should be commented.

This commit is contained in:
Andy Hanson 2016-05-25 13:38:53 -07:00
parent 1abc2a7846
commit 7ddb1631bc
11 changed files with 51 additions and 55 deletions

View file

@ -1,6 +1,7 @@
/// <reference path="harness.ts" />
/// <reference path="runnerbase.ts" />
/// <reference path="typeWriter.ts" />
// In harness baselines, null is different than undefined. See `generateActual` in `harness.ts`.
/* tslint:disable:no-null-keyword */
const enum CompilerTestType {

View file

@ -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;
}
}

View file

@ -18,7 +18,6 @@
/// <reference path="harnessLanguageService.ts" />
/// <reference path="harness.ts" />
/// <reference path="fourslashRunner.ts" />
/* 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 = <number>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.");
}

View file

@ -1,7 +1,6 @@
///<reference path="fourslash.ts" />
///<reference path="harness.ts"/>
///<reference path="runnerbase.ts" />
/* tslint:disable:no-null-keyword */
const enum FourSlashTestType {
Native,

View file

@ -23,7 +23,6 @@
/// <reference path="external\chai.d.ts"/>
/// <reference path="sourceMapRecorder.ts"/>
/// <reference path="runnerbase.ts"/>
/* 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 = <any>Function("return this").call(null);
var global = <any>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 = "<no content>";
}

View file

@ -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);
}

View file

@ -1,7 +1,6 @@
/// <reference path="..\..\src\compiler\sys.ts" />
/// <reference path="..\..\src\harness\harness.ts" />
/// <reference path="..\..\src\harness\runnerbase.ts" />
/* 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 {

View file

@ -1,6 +1,5 @@
///<reference path="harness.ts" />
///<reference path="runnerbase.ts" />
/* 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);
}

View file

@ -20,8 +20,6 @@
/// <reference path="rwcRunner.ts" />
/// <reference path="harness.ts" />
/* tslint:disable:no-null-keyword */
let runners: RunnerBase[] = [];
let iterations = 1;

View file

@ -2,6 +2,7 @@
/// <reference path="runnerbase.ts" />
/// <reference path="loggedIO.ts" />
/// <reference path="..\compiler\commandLineParser.ts"/>
// 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);
}

View file

@ -1,5 +1,6 @@
/// <reference path="harness.ts" />
/// <reference path="runnerbase.ts" />
// In harness baselines, null is different than undefined. See `generateActual` in `harness.ts`.
/* tslint:disable:no-null-keyword */
class Test262BaselineRunner extends RunnerBase {