@@ -5,24 +5,24 @@ namespace SourceMaps.StackTraces
55{
66 public static class StackTraceParser
77 {
8- public static string ReTrace ( SourceMap sourceMap , string stacktrace , string sourceRoot = null )
8+ public static string ReTrace ( SourceMap sourceMap , string stacktrace , string ? sourceRoot = null )
99 {
1010 var collection = new SourceMapCollection ( ) ;
1111 collection . Register ( sourceMap ) ;
1212 return ReTrace ( collection , stacktrace , sourceRoot ) ;
1313 }
1414
15- public static string ReTrace ( SourceMapCollection sourceMaps , string stacktrace , string sourceRoot = null )
15+ public static string ReTrace ( SourceMapCollection sourceMaps , string stacktrace , string ? sourceRoot = null )
1616 {
1717 var trace = Parse ( stacktrace ) ;
1818
1919 foreach ( var frame in trace . Frames )
2020 {
2121 if ( ! string . IsNullOrEmpty ( sourceRoot ) )
22- frame . File = frame . File . Replace ( sourceRoot , "" ) ;
22+ frame . File = frame . File ? . Replace ( sourceRoot , "" ) ;
2323
2424 var sourceMap = sourceMaps . GetSourceMapFor ( frame . File ) ;
25- if ( sourceMap == null && frame . File . IndexOf ( '?' ) >= 0 )
25+ if ( sourceMap == null && frame . File ? . IndexOf ( '?' ) >= 0 ) // Allow querystring versioning missing from the registered filename
2626 sourceMap = sourceMaps . GetSourceMapFor ( frame . File . Substring ( 0 , frame . File . IndexOf ( '?' ) ) ) ;
2727
2828 if ( frame . LineNumber == null || frame . ColumnNumber == null )
@@ -32,10 +32,10 @@ public static string ReTrace(SourceMapCollection sourceMaps, string stacktrace,
3232 if ( originalPosition == null )
3333 continue ;
3434
35- frame . File = originalPosition ? . OriginalFileName ?? frame . File ;
36- frame . Method = originalPosition ? . OriginalName ?? frame . Method ;
37- frame . LineNumber = ( originalPosition ? . OriginalLineNumber + 1 ) ?? frame . LineNumber ;
38- frame . ColumnNumber = ( originalPosition ? . OriginalColumnNumber + 1 ) ?? frame . ColumnNumber ;
35+ frame . File = originalPosition ? . OriginalFileName ;
36+ frame . Method = originalPosition ? . OriginalName ;
37+ frame . LineNumber = originalPosition ? . OriginalLineNumber + 1 ;
38+ frame . ColumnNumber = originalPosition ? . OriginalColumnNumber + 1 ;
3939 }
4040
4141 return trace . ToString ( ) ;
@@ -48,7 +48,7 @@ public static StackTrace Parse(string stacktrace)
4848 var result = new StackTrace ( ) ;
4949 foreach ( var line in lines )
5050 {
51- StackFrame frame ;
51+ StackFrame ? frame ;
5252 var success =
5353 TryParseChrome ( line , out frame ) ||
5454 TryParseWinJs ( line , out frame ) ||
@@ -57,15 +57,15 @@ public static StackTrace Parse(string stacktrace)
5757 TryParseJsc ( line , out frame ) ;
5858
5959 if ( success )
60- result . Append ( frame ) ;
60+ result . Append ( frame ! ) ;
6161 }
6262
6363 return result ;
6464 }
6565
6666 private static readonly Regex ChromeRe = new Regex ( @"^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|<anonymous>|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
6767 private static readonly Regex ChromeEvalRe = new Regex ( @"\((\S*)(?::(\d+))(?::(\d+))\)" , RegexOptions . Compiled ) ;
68- internal static bool TryParseChrome ( string line , out StackFrame frame )
68+ internal static bool TryParseChrome ( string line , out StackFrame ? frame )
6969 {
7070 frame = null ;
7171
@@ -76,12 +76,14 @@ internal static bool TryParseChrome(string line, out StackFrame frame)
7676 var isNative = match . Groups [ 2 ] . Value ? . IndexOf ( "native" , StringComparison . Ordinal ) == 0 ;
7777 var isEval = match . Groups [ 2 ] . Value ? . IndexOf ( "eval" , StringComparison . Ordinal ) == 0 ;
7878
79- frame = new StackFrame ( ) ;
80- frame . File = ! isNative ? match . Groups [ 2 ] . Value : null ;
81- frame . Method = ! string . IsNullOrEmpty ( match . Groups [ 1 ] ? . Value ) ? match . Groups [ 1 ] . Value : null ;
82- frame . Arguments = isNative ? new [ ] { match . Groups [ 2 ] . Value } : Array . Empty < string > ( ) ;
83- frame . LineNumber = ! string . IsNullOrEmpty ( match . Groups [ 3 ] . Value ) ? int . Parse ( match . Groups [ 3 ] . Value ) : ( int ? ) null ;
84- frame . ColumnNumber = ! string . IsNullOrEmpty ( match . Groups [ 4 ] . Value ) ? int . Parse ( match . Groups [ 4 ] . Value ) : ( int ? ) null ;
79+ frame = new StackFrame
80+ {
81+ File = ! isNative ? match . Groups [ 2 ] . Value : null ,
82+ Method = ! string . IsNullOrEmpty ( match . Groups [ 1 ] ? . Value ) ? match . Groups [ 1 ] . Value : null ,
83+ Arguments = isNative ? new [ ] { match . Groups [ 2 ] . Value } : Array . Empty < string > ( ) ,
84+ LineNumber = ! string . IsNullOrEmpty ( match . Groups [ 3 ] . Value ) ? int . Parse ( match . Groups [ 3 ] . Value ) : ( int ? ) null ,
85+ ColumnNumber = ! string . IsNullOrEmpty ( match . Groups [ 4 ] . Value ) ? int . Parse ( match . Groups [ 4 ] . Value ) : ( int ? ) null
86+ } ;
8587
8688 var submatch = ChromeEvalRe . Match ( match . Groups [ 2 ] . Value ) ;
8789 if ( isEval && submatch . Success )
@@ -95,7 +97,7 @@ internal static bool TryParseChrome(string line, out StackFrame frame)
9597 }
9698
9799 private static readonly Regex WinJsRe = new Regex ( @"^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
98- internal static bool TryParseWinJs ( string line , out StackFrame frame )
100+ internal static bool TryParseWinJs ( string line , out StackFrame ? frame )
99101 {
100102 frame = null ;
101103
@@ -117,7 +119,7 @@ internal static bool TryParseWinJs(string line, out StackFrame frame)
117119
118120 private static readonly Regex GeckoRe = new Regex ( @"^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|resource|\[native|/).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
119121 private static readonly Regex GeckoEvalRe = new Regex ( @"(?:^\s*(?:.*?)(?:\((?:.*?)\))?@|^)(\S+) line (\d+)(?: > eval line \d+)* > eval" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
120- internal static bool TryParseGecko ( string line , out StackFrame frame )
122+ internal static bool TryParseGecko ( string line , out StackFrame ? frame )
121123 {
122124 frame = null ;
123125
@@ -148,40 +150,44 @@ internal static bool TryParseGecko(string line, out StackFrame frame)
148150 }
149151
150152 private static readonly Regex NodeRe = new Regex ( @"^\s*at (?:((?:\[object object\])?[^\\/]+(?: \[as \S+\])?) )?\(?(.*?):(\d+)(?::(\d+))?\)?\s*$" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
151- internal static bool TryParseNode ( string line , out StackFrame frame )
153+ internal static bool TryParseNode ( string line , out StackFrame ? frame )
152154 {
153155 frame = null ;
154156
155157 var match = NodeRe . Match ( line ) ;
156158 if ( ! match . Success )
157159 return false ;
158160
159- frame = new StackFrame ( ) ;
160- frame . File = match . Groups [ 2 ] . Value ;
161- frame . Method = ! string . IsNullOrEmpty ( match . Groups [ 1 ] ? . Value ) ? match . Groups [ 1 ] . Value : null ;
162- frame . Arguments = Array . Empty < string > ( ) ;
163- frame . LineNumber = int . Parse ( match . Groups [ 3 ] . Value ) ;
164- frame . ColumnNumber = ! string . IsNullOrEmpty ( match . Groups [ 4 ] . Value ) ? int . Parse ( match . Groups [ 4 ] . Value ) : ( int ? ) null ;
161+ frame = new StackFrame
162+ {
163+ File = match . Groups [ 2 ] . Value ,
164+ Method = ! string . IsNullOrEmpty ( match . Groups [ 1 ] ? . Value ) ? match . Groups [ 1 ] . Value : null ,
165+ Arguments = Array . Empty < string > ( ) ,
166+ LineNumber = int . Parse ( match . Groups [ 3 ] . Value ) ,
167+ ColumnNumber = ! string . IsNullOrEmpty ( match . Groups [ 4 ] . Value ) ? int . Parse ( match . Groups [ 4 ] . Value ) : ( int ? ) null
168+ } ;
165169
166170 return true ;
167171 }
168172
169173 private static readonly Regex JscRe = new Regex ( @"^\s*(?:([^@]*)(?:\((.*?)\))?@)?(\S.*?):(\d+)(?::(\d+))?\s*$" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
170174
171- internal static bool TryParseJsc ( string line , out StackFrame frame )
175+ internal static bool TryParseJsc ( string line , out StackFrame ? frame )
172176 {
173177 frame = null ;
174178
175179 var match = JscRe . Match ( line ) ;
176180 if ( ! match . Success )
177181 return false ;
178182
179- frame = new StackFrame ( ) ;
180- frame . File = match . Groups [ 3 ] . Value ;
181- frame . Method = ! string . IsNullOrEmpty ( match . Groups [ 1 ] . Value ) ? match . Groups [ 1 ] . Value : null ;
182- frame . Arguments = Array . Empty < string > ( ) ;
183- frame . LineNumber = int . Parse ( match . Groups [ 4 ] . Value ) ;
184- frame . ColumnNumber = ! string . IsNullOrEmpty ( match . Groups [ 5 ] . Value ) ? int . Parse ( match . Groups [ 5 ] . Value ) : ( int ? ) null ;
183+ frame = new StackFrame
184+ {
185+ File = match . Groups [ 3 ] . Value ,
186+ Method = ! string . IsNullOrEmpty ( match . Groups [ 1 ] . Value ) ? match . Groups [ 1 ] . Value : null ,
187+ Arguments = Array . Empty < string > ( ) ,
188+ LineNumber = int . Parse ( match . Groups [ 4 ] . Value ) ,
189+ ColumnNumber = ! string . IsNullOrEmpty ( match . Groups [ 5 ] . Value ) ? int . Parse ( match . Groups [ 5 ] . Value ) : ( int ? ) null
190+ } ;
185191
186192 return true ;
187193 }
0 commit comments