@@ -3,9 +3,10 @@ import * as path from "path";
33
44export class IOSLogFilter implements Mobile . IPlatformLogFilter {
55
6+ private $projectData : IProjectData ;
7+
68 constructor (
79 private $fs : IFileSystem ,
8- private $projectData : IProjectData ,
910 private $loggingLevels : Mobile . ILoggingLevels ) { }
1011
1112 public filterData ( data : string , logLevel : string , pid ?: string ) : string {
@@ -22,16 +23,16 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter {
2223 }
2324 // CONSOLE LOG messages comme in the following form:
2425 // <date> <domain> <app>[pid] CONSOLE LOG file:///location:row:column: <actual message goes here>
25- // This code removes unnecessary information from log messages. The output looks like:
26- // CONSOLE LOG file:///location:row:column: <actual message goes here>
26+ // This code removes unnecessary information from log messages. The output looks like:
27+ // CONSOLE LOG file:///location:row:column: <actual message goes here>
2728 if ( pid ) {
2829 let searchString = "[" + pid + "]: " ;
2930 let pidIndex = data . indexOf ( searchString ) ;
3031 if ( pidIndex > 0 ) {
3132 data = data . substring ( pidIndex + searchString . length , data . length ) ;
32- data = this . getOriginalFileLocation ( data ) ;
3333 }
3434 }
35+ data = this . getOriginalFileLocation ( data ) ;
3536 return data . trim ( ) ;
3637 }
3738
@@ -45,24 +46,33 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter {
4546 let parts = data . substring ( fileIndex + fileString . length ) . split ( ":" ) ;
4647 if ( parts . length >= 4 ) {
4748 let file = parts [ 0 ] ;
48- let sourceMapFile = path . join ( this . $projectData . projectDir , file + ".map" ) ;
49- let row = parseInt ( parts [ 1 ] ) ;
50- let column = parseInt ( parts [ 2 ] ) ;
51- if ( this . $fs . exists ( sourceMapFile ) . wait ( ) ) {
52- let sourceMap = this . $fs . readText ( sourceMapFile , "utf8" ) . wait ( ) ;
53- let smc = new sourcemap . SourceMapConsumer ( sourceMap ) ;
54- let originalPosition = smc . originalPositionFor ( { line :row , column :column } ) ;
55- data = data . substring ( 0 , fileIndex + fileString . length )
56- + file . replace ( ".js" , ".ts" ) + ":"
57- + originalPosition . line + ":"
58- + originalPosition . column ;
59- for ( let i = 3 ; i < parts . length ; i ++ ) {
60- data += ":" + parts [ i ] ;
49+ if ( this . ensureProjectData ( ) ) {
50+ let sourceMapFile = path . join ( this . $projectData . projectDir , file + ".map" ) ;
51+ let row = parseInt ( parts [ 1 ] ) ;
52+ let column = parseInt ( parts [ 2 ] ) ;
53+ if ( this . $fs . exists ( sourceMapFile ) . wait ( ) ) {
54+ let sourceMap = this . $fs . readText ( sourceMapFile , "utf8" ) . wait ( ) ;
55+ let smc = new sourcemap . SourceMapConsumer ( sourceMap ) ;
56+ let originalPosition = smc . originalPositionFor ( { line :row , column :column } ) ;
57+ data = data . substring ( 0 , fileIndex + fileString . length )
58+ + file . replace ( ".js" , ".ts" ) + ":"
59+ + originalPosition . line + ":"
60+ + originalPosition . column ;
61+ for ( let i = 3 ; i < parts . length ; i ++ ) {
62+ data += ":" + parts [ i ] ;
63+ }
6164 }
6265 }
6366 }
6467 }
6568 return data ;
6669 }
70+
71+ private ensureProjectData ( ) : boolean {
72+ if ( ! this . $projectData ) {
73+ this . $projectData = $injector . resolve ( "projectData" ) ;
74+ }
75+ return ! ! this . $projectData ;
76+ }
6777}
6878$injector . register ( "iOSLogFilter" , IOSLogFilter ) ;
0 commit comments