chore: cleanup

This commit is contained in:
Nathan Walker
2020-07-06 14:25:11 -07:00
parent 94cf5c4706
commit 6336eac4b5
477 changed files with 59087 additions and 74961 deletions

View File

@@ -1,86 +1,74 @@
import { knownFolders } from "../file-system";
import { isAndroid } from "../platform";
import { knownFolders } from '../file-system';
import { isAndroid } from '../platform';
export let debug = true;
let applicationRootPath: string;
function ensureAppRootPath() {
if (!applicationRootPath) {
applicationRootPath = knownFolders.currentApp().path;
applicationRootPath = applicationRootPath.substr(
0,
applicationRootPath.length - "app/".length
);
}
if (!applicationRootPath) {
applicationRootPath = knownFolders.currentApp().path;
applicationRootPath = applicationRootPath.substr(0, applicationRootPath.length - 'app/'.length);
}
}
export class Source {
private _uri: string;
private _line: number;
private _column: number;
private _uri: string;
private _line: number;
private _column: number;
private static _source: symbol = Symbol("source");
private static _source: symbol = Symbol('source');
constructor(uri: string, line: number, column: number) {
ensureAppRootPath();
constructor(uri: string, line: number, column: number) {
ensureAppRootPath();
if (
uri.length > applicationRootPath.length &&
uri.substr(0, applicationRootPath.length) === applicationRootPath
) {
this._uri = "file://" + uri.substr(applicationRootPath.length);
} else {
this._uri = uri;
}
this._line = line;
this._column = column;
}
if (uri.length > applicationRootPath.length && uri.substr(0, applicationRootPath.length) === applicationRootPath) {
this._uri = 'file://' + uri.substr(applicationRootPath.length);
} else {
this._uri = uri;
}
this._line = line;
this._column = column;
}
get uri(): string {
return this._uri;
}
get line(): number {
return this._line;
}
get column(): number {
return this._column;
}
get uri(): string {
return this._uri;
}
get line(): number {
return this._line;
}
get column(): number {
return this._column;
}
public toString() {
return this._uri + ":" + this._line + ":" + this._column;
}
public toString() {
return this._uri + ':' + this._line + ':' + this._column;
}
public static get(object: any): Source {
return object[Source._source];
}
public static get(object: any): Source {
return object[Source._source];
}
public static set(object: any, src: Source) {
object[Source._source] = src;
}
public static set(object: any, src: Source) {
object[Source._source] = src;
}
}
export class ScopeError extends Error {
constructor(inner: Error, message?: string) {
let formattedMessage;
if (message && inner.message) {
formattedMessage =
message + "\n > " + inner.message.replace("\n", "\n ");
} else {
formattedMessage = message || inner.message || undefined;
}
super(formattedMessage);
this.stack = isAndroid
? "Error: " +
this.message +
"\n" +
inner.stack.substr(inner.stack.indexOf("\n") + 1)
: inner.stack;
this.message = formattedMessage;
}
constructor(inner: Error, message?: string) {
let formattedMessage;
if (message && inner.message) {
formattedMessage = message + '\n > ' + inner.message.replace('\n', '\n ');
} else {
formattedMessage = message || inner.message || undefined;
}
super(formattedMessage);
this.stack = isAndroid ? 'Error: ' + this.message + '\n' + inner.stack.substr(inner.stack.indexOf('\n') + 1) : inner.stack;
this.message = formattedMessage;
}
}
export class SourceError extends ScopeError {
constructor(child: Error, source: Source, message?: string) {
super(child, message ? message + " @" + source + "" : source + "");
}
constructor(child: Error, source: Source, message?: string) {
super(child, message ? message + ' @' + source + '' : source + '');
}
}