@@ -46,6 +46,20 @@ internal static class JintJsErrorHelpers
4646 @"(?<documentName>" + CommonRegExps . DocumentNamePattern + @"):" +
4747 @"(?<lineNumber>\d+)(?::(?<columnNumber>\d+))?$" ) ;
4848
49+ /// <summary>
50+ /// Regular expression for working with the syntax error message
51+ /// </summary>
52+ private static readonly Regex _syntaxErrorMessageRegex =
53+ new Regex ( @"^(?<description>[\s\S]+?) \(" + CommonRegExps . DocumentNamePattern + @":\d+:\d+\)$" ) ;
54+
55+ /// <summary>
56+ /// Regular expression for working with the script preparation error message
57+ /// </summary>
58+ private static readonly Regex _scriptPreparationErrorMessageRegex =
59+ new Regex ( @"^Could not prepare script: (?<description>[\s\S]+?) " +
60+ @"\((?<documentName>" + CommonRegExps . DocumentNamePattern + @"):" +
61+ @"(?<lineNumber>\d+):(?<columnNumber>\d+)\)$" ) ;
62+
4963
5064 /// <summary>
5165 /// Parses a string representation of the script error location to produce an array of
@@ -152,6 +166,50 @@ public static string ConvertCallChainToStack(string callChain)
152166 return callStack ;
153167 }
154168
169+ /// <summary>
170+ /// Gets a description from the syntax error message
171+ /// </summary>
172+ /// <param name="message">Error message</param>
173+ /// <returns>Description of error</returns>
174+ public static string GetDescriptionFromSyntaxErrorMessage ( string message )
175+ {
176+ Match messageMatch = _syntaxErrorMessageRegex . Match ( message ) ;
177+ string description = messageMatch . Success ?
178+ messageMatch . Groups [ "description" ] . Value : message ;
179+
180+ return description ;
181+ }
182+
183+ /// <summary>
184+ /// Parses a script preparation error message
185+ /// </summary>
186+ /// <param name="message">Error message</param>
187+ /// <param name="description">Description of error</param>
188+ /// <param name="errorLocation">Script error location</param>
189+ public static void ParseScriptPreparationErrorMessage ( string message , out string description ,
190+ out ErrorLocationItem errorLocation )
191+ {
192+ Match messageMatch = _scriptPreparationErrorMessageRegex . Match ( message ) ;
193+
194+ if ( messageMatch . Success )
195+ {
196+ GroupCollection messageGroups = messageMatch . Groups ;
197+
198+ description = messageGroups [ "description" ] . Value ;
199+ errorLocation = new ErrorLocationItem
200+ {
201+ DocumentName = messageGroups [ "documentName" ] . Value ,
202+ LineNumber = int . Parse ( messageGroups [ "lineNumber" ] . Value ) ,
203+ ColumnNumber = int . Parse ( messageGroups [ "columnNumber" ] . Value )
204+ } ;
205+ }
206+ else
207+ {
208+ description = message ;
209+ errorLocation = new ErrorLocationItem ( ) ;
210+ }
211+ }
212+
155213 #endregion
156214 }
157215}
0 commit comments