@@ -3,9 +3,10 @@ import * as path from "path";
3
3
4
4
export class IOSLogFilter implements Mobile . IPlatformLogFilter {
5
5
6
+ private $projectData : IProjectData ;
7
+
6
8
constructor (
7
9
private $fs : IFileSystem ,
8
- private $projectData : IProjectData ,
9
10
private $loggingLevels : Mobile . ILoggingLevels ) { }
10
11
11
12
public filterData ( data : string , logLevel : string , pid ?: string ) : string {
@@ -22,16 +23,16 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter {
22
23
}
23
24
// CONSOLE LOG messages comme in the following form:
24
25
// <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>
27
28
if ( pid ) {
28
29
let searchString = "[" + pid + "]: " ;
29
30
let pidIndex = data . indexOf ( searchString ) ;
30
31
if ( pidIndex > 0 ) {
31
32
data = data . substring ( pidIndex + searchString . length , data . length ) ;
32
- data = this . getOriginalFileLocation ( data ) ;
33
33
}
34
34
}
35
+ data = this . getOriginalFileLocation ( data ) ;
35
36
return data . trim ( ) ;
36
37
}
37
38
@@ -45,24 +46,33 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter {
45
46
let parts = data . substring ( fileIndex + fileString . length ) . split ( ":" ) ;
46
47
if ( parts . length >= 4 ) {
47
48
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
+ }
61
64
}
62
65
}
63
66
}
64
67
}
65
68
return data ;
66
69
}
70
+
71
+ private ensureProjectData ( ) : boolean {
72
+ if ( ! this . $projectData ) {
73
+ this . $projectData = $injector . resolve ( "projectData" ) ;
74
+ }
75
+ return ! ! this . $projectData ;
76
+ }
67
77
}
68
78
$injector . register ( "iOSLogFilter" , IOSLogFilter ) ;
0 commit comments