Skip to content
This repository has been archived by the owner on May 21, 2019. It is now read-only.

Commit

Permalink
Fix more null errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
vlad-shatskyi committed Jun 2, 2016
1 parent 229e1c4 commit 8ec342f
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/Buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default class Buffer extends events.EventEmitter {
}

toLines(): string[] {
return this.storage.map(row => row.map(char => char.toString()).join("")).toArray();
return this.storage.map(row => row!.map(char => char!.toString()).join("")).toArray();
}

toString(): string {
Expand Down
2 changes: 1 addition & 1 deletion src/CommandExpander.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function lex(input: string): string[] {
return [];
}

let lexemes = input.match(/"(?:\\"|[^"])+"|'(?:\\'|[^'])+'|(?:[^ ]+\\ )+[^ ]+|[^ ]+/g);
let lexemes: string[] = input.match(/"(?:\\"|[^"])+"|'(?:\\'|[^'])+'|(?:[^ ]+\\ )+[^ ]+|[^ ]+/g) || [];

if (input.endsWith(" ")) {
lexemes.push("");
Expand Down
2 changes: 1 addition & 1 deletion src/Decorators.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as _ from "lodash";

export function memoize(resolver: Function = undefined) {
export function memoize(resolver: Function | undefined = undefined) {
if (typeof resolver !== "function") {
resolver = (...args: any[]) => JSON.stringify(args);
}
Expand Down
8 changes: 6 additions & 2 deletions src/Job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ export default class Job extends EmitterWithUniqueID {
}

decorate(): React.ReactElement<any> {
return this.firstApplicableDecorator.decorate(this);
if (this.firstApplicableDecorator) {
return this.firstApplicableDecorator.decorate(this);
} else {
throw "No applicable decorator found.";
}
}

get environment(): Environment {
Expand All @@ -142,7 +146,7 @@ export default class Job extends EmitterWithUniqueID {
);
}

private get firstApplicableDecorator(): i.OutputDecorator {
private get firstApplicableDecorator(): i.OutputDecorator | undefined {
return this.decorators.find(decorator => decorator.isApplicable(this));
}

Expand Down
2 changes: 0 additions & 2 deletions src/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ export const string = (expected: string) => {
const progress = getProgress(context.input, expected);

return [{
parser: parser,
context: context,
parse: progress === Progress.Finished ? expected : "",
progress: progress,
suggestions: (progress === Progress.Finished)
Expand Down
4 changes: 2 additions & 2 deletions src/Serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class Serializer {
} else if (typeof serializable === "string") {
return `String:${serializable}`;
} else {
console.error(`Don"t know how to serialize ${serializable}`);
throw `Don"t know how to serialize ${serializable}`;
}
}

Expand All @@ -18,7 +18,7 @@ export default class Serializer {
} else if (_.startsWith(serialized, "History:")) {
return History.deserialize(serialized.slice("History:".length));
} else {
console.error(`Don"t know how to deserialize ${serialized}`);
throw `Don"t know how to deserialize ${serialized}`;
}
}
}
73 changes: 32 additions & 41 deletions src/main/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,46 @@ import menu from "./Menu";
import {readFileSync} from "fs";
import {windowBoundsFilePath} from "../utils/Common";


let browserWindow: Electron.BrowserWindow = undefined;

if (app.dock) {
app.dock.setIcon(nativeImage.createFromPath("build/icon.png"));
}

app.on("open-file", (event: Event, file: string) => getMainWindow().webContents.send("change-working-directory", file));
app.on("ready", getMainWindow);
app.on("activate", getMainWindow);
app.on("mainWindow-all-closed", () => process.platform === "darwin" || app.quit());

ipcMain.on("quit", app.quit);

function getMainWindow(): Electron.BrowserWindow {
app.on("ready", () => {
const bounds = windowBounds();

if (!browserWindow) {
let options: Electron.BrowserWindowOptions = {
webPreferences: {
experimentalFeatures: true,
experimentalCanvasFeatures: true,
},
titleBarStyle: "hidden",
resizable: true,
minWidth: 500,
minHeight: 300,
width: bounds.width,
height: bounds.height,
x: bounds.x,
y: bounds.y,
show: false,
};
browserWindow = new BrowserWindow(options);
let options: Electron.BrowserWindowOptions = {
webPreferences: {
experimentalFeatures: true,
experimentalCanvasFeatures: true,
},
titleBarStyle: "hidden",
resizable: true,
minWidth: 500,
minHeight: 300,
width: bounds.width,
height: bounds.height,
x: bounds.x,
y: bounds.y,
show: false,
};
const browserWindow = new BrowserWindow(options);

browserWindow.loadURL("file://" + __dirname + "/../views/index.html");
menu.setMenu(app, browserWindow);

browserWindow.on("focus", () => app.dock && app.dock.setBadge(""));

browserWindow.webContents.on("did-finish-load", () => {
browserWindow.show();
browserWindow.focus();
});

app.on("open-file", (event, file) => browserWindow.webContents.send("change-working-directory", file));
});

browserWindow.loadURL("file://" + __dirname + "/../views/index.html");
menu.setMenu(app, browserWindow);

browserWindow.on("closed", (): void => browserWindow = undefined)
.on("focus", (): void => app.dock && app.dock.setBadge(""));

browserWindow.webContents.on("did-finish-load", () => {
browserWindow.show();
browserWindow.focus();
});
}
app.on("mainWindow-all-closed", () => process.platform === "darwin" || app.quit());

return browserWindow;
}
ipcMain.on("quit", app.quit);

function windowBounds(): Electron.Bounds {
try {
Expand Down
8 changes: 5 additions & 3 deletions src/plugins/GitWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ class GitWatcher extends EventEmitter {
@debounce(1000 / 60)
private async updateGitData() {
let content = await readFile(Path.join(this.gitDirectory, "HEAD"));
const headMatch = /ref: refs\/heads\/(.*)/.exec(content);
const head = headMatch ? headMatch[1] : "Couldn't parse branch";

executeCommand("git", ["status", "--porcelain"], this.directory).then(changes => {
const status: VcsStatus = changes.length ? "dirty" : "clean";

const data: VcsData = {
isRepository: true,
branch: /ref: refs\/heads\/(.*)/.exec(content)[1],
branch: head,
status: status,
};

Expand All @@ -83,7 +85,7 @@ class WatchManager implements EnvironmentObserverPlugin {
return;
}

const details = this.directoryToDetails.get(oldDirectory);
const details = this.directoryToDetails.get(oldDirectory)!;
details.sessions.delete(session);

if (details.sessions.size === 0) {
Expand All @@ -94,7 +96,7 @@ class WatchManager implements EnvironmentObserverPlugin {

currentWorkingDirectoryDidChange(session: Session, directory: string) {
if (this.directoryToDetails.has(directory)) {
this.directoryToDetails.get(directory).sessions.add(session);
this.directoryToDetails.get(directory)!.sessions.add(session);
} else {
const watcher = new GitWatcher(directory);

Expand Down
5 changes: 2 additions & 3 deletions src/plugins/autocompletion_providers/Alias.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import * as _ from "lodash";
import {description, styles, style} from "./Suggestions";
import {choice, decorate, Context, string} from "../../Parser";
import {compose} from "../../utils/Common";
import {compose, mapObject} from "../../utils/Common";
import {command} from "./Command";

export const makeAlias = (aliases: Dictionary<string>) => choice(_.map(aliases, (expanded, key) => choice([
export const makeAlias = (aliases: Dictionary<string>) => choice(mapObject(aliases, (key, expanded) => choice([
decorate(string(key), compose(style(styles.alias), description(expanded))),
async (context: Context) => {
if (context.input.startsWith(key)) {
Expand Down

0 comments on commit 8ec342f

Please sign in to comment.