1 | import { knownFolders } from '../file-system';
|
2 | export const debug = true;
|
3 | let applicationRootPath;
|
4 | function ensureAppRootPath() {
|
5 | if (!applicationRootPath) {
|
6 | applicationRootPath = knownFolders.currentApp().path;
|
7 | applicationRootPath = applicationRootPath.substring(0, applicationRootPath.length - 'app/'.length);
|
8 | }
|
9 | }
|
10 | export class Source {
|
11 | constructor(uri, line, column) {
|
12 | ensureAppRootPath();
|
13 | if (uri.length > applicationRootPath.length && uri.substring(0, applicationRootPath.length) === applicationRootPath) {
|
14 | this._uri = 'file://' + uri.substring(applicationRootPath.length);
|
15 | }
|
16 | else {
|
17 | this._uri = uri;
|
18 | }
|
19 | this._line = line;
|
20 | this._column = column;
|
21 | }
|
22 | get uri() {
|
23 | return this._uri;
|
24 | }
|
25 | get line() {
|
26 | return this._line;
|
27 | }
|
28 | get column() {
|
29 | return this._column;
|
30 | }
|
31 | toString() {
|
32 | return this._uri + ':' + this._line + ':' + this._column;
|
33 | }
|
34 | static get(object) {
|
35 | return object[Source._source];
|
36 | }
|
37 | static set(object, src) {
|
38 | object[Source._source] = src;
|
39 | }
|
40 | }
|
41 | Source._source = Symbol('source');
|
42 | export class ScopeError extends Error {
|
43 | constructor(inner, message) {
|
44 | let formattedMessage;
|
45 | if (message && inner.message) {
|
46 | formattedMessage = message + '\n > ' + inner.message.replace('\n', '\n ');
|
47 | }
|
48 | else {
|
49 | formattedMessage = message || inner.message || undefined;
|
50 | }
|
51 | super(formattedMessage);
|
52 | this.stack = __ANDROID__ ? 'Error: ' + this.message + '\n' + inner.stack.substr(inner.stack.indexOf('\n') + 1) : inner.stack;
|
53 | this.message = formattedMessage;
|
54 | }
|
55 | }
|
56 | export class SourceError extends ScopeError {
|
57 | constructor(child, source, message) {
|
58 | super(child, message ? message + ' @' + source + '' : source + '');
|
59 | }
|
60 | }
|
61 |
|
\ | No newline at end of file |