@@ -228,14 +228,20 @@ export default class JavascriptEventWorker extends EventWorker {
228228 * Fixes bug: https://github.com/codex-team/hawk.workers/issues/121
229229 */
230230 if ( originalLocation . source ) {
231- /**
232- * Get 5 lines above and 5 below
233- */
234- lines = this . readSourceLines ( consumer , originalLocation ) ;
231+ try {
232+ /**
233+ * Get 5 lines above and 5 below
234+ */
235+ lines = this . readSourceLines ( consumer , originalLocation ) ;
235236
236- const _originalContent = consumer . sourceContentFor ( originalLocation . source ) ;
237+ const originalContent = consumer . sourceContentFor ( originalLocation . source ) ;
237238
238- // functionContext = this.getFunctionContext(originalContent, originalLocation.line) ?? originalLocation.name;
239+ functionContext = this . getFunctionContext ( originalContent , originalLocation . line ) ?? originalLocation . name ;
240+ } catch ( e ) {
241+ HawkCatcher . send ( e ) ;
242+ this . logger . error ( 'Can\'t get function context' ) ;
243+ this . logger . error ( e ) ;
244+ }
239245 }
240246
241247 return Object . assign ( stackFrame , {
@@ -254,7 +260,7 @@ export default class JavascriptEventWorker extends EventWorker {
254260 * @param line - number of the line from the stack trace
255261 * @returns {string | null } - string of the function context or null if it could not be parsed
256262 */
257- private _getFunctionContext ( sourceCode : string , line : number ) : string | null {
263+ private getFunctionContext ( sourceCode : string , line : number ) : string | null {
258264 let functionName : string | null = null ;
259265 let className : string | null = null ;
260266 let isAsync = false ;
@@ -264,6 +270,7 @@ export default class JavascriptEventWorker extends EventWorker {
264270 const ast = parse ( sourceCode , {
265271 sourceType : 'module' ,
266272 plugins : [
273+ 'jsx' ,
267274 'typescript' ,
268275 'classProperties' ,
269276 'decorators' ,
@@ -284,7 +291,7 @@ export default class JavascriptEventWorker extends EventWorker {
284291 ClassDeclaration ( path ) {
285292 if ( path . node . loc && path . node . loc . start . line <= line && path . node . loc . end . line >= line ) {
286293 console . log ( `class declaration: loc: ${ path . node . loc } , line: ${ line } , node.start.line: ${ path . node . loc . start . line } , node.end.line: ${ path . node . loc . end . line } ` ) ;
287-
294+
288295 className = path . node . id . name || null ;
289296 }
290297 } ,
@@ -297,7 +304,7 @@ export default class JavascriptEventWorker extends EventWorker {
297304 ClassMethod ( path ) {
298305 if ( path . node . loc && path . node . loc . start . line <= line && path . node . loc . end . line >= line ) {
299306 console . log ( `class declaration: loc: ${ path . node . loc } , line: ${ line } , node.start.line: ${ path . node . loc . start . line } , node.end.line: ${ path . node . loc . end . line } ` ) ;
300-
307+
301308 // Handle different key types
302309 if ( path . node . key . type === 'Identifier' ) {
303310 functionName = path . node . key . name ;
@@ -313,7 +320,7 @@ export default class JavascriptEventWorker extends EventWorker {
313320 FunctionDeclaration ( path ) {
314321 if ( path . node . loc && path . node . loc . start . line <= line && path . node . loc . end . line >= line ) {
315322 console . log ( `function declaration: loc: ${ path . node . loc } , line: ${ line } , node.start.line: ${ path . node . loc . start . line } , node.end.line: ${ path . node . loc . end . line } ` ) ;
316-
323+
317324 functionName = path . node . id . name || null ;
318325 isAsync = path . node . async ;
319326 }
0 commit comments