import { knownFolders } from '../file-system' ; export const debug = true ; let applicationRootPath ; function ensureAppRootPath ( ) { 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 static _source = Symbol ( 'source' ) ; constructor ( uri , line , column ) { 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 ; } 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 static get ( object ) { return object [ Source . _source ] ; } public static set ( object , src ) { object [ Source . _source ] = src ; } } export class ScopeError extends Error { constructor ( inner , message ? ) { let formattedMessage ; if ( message && inner . message ) { formattedMessage = message + '\n > ' + inner . message . replace ( '\n' , '\n  ' ) ; } else { formattedMessage = message || inner . message || undefined ; } super ( formattedMessage ) ; this . stack = global . 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 , source , message ? ) { super ( child , message ? message + ' @' + source + '' : source + '' ) ; } }