Skip to content

Commit

Permalink
SimpleTracing update
Browse files Browse the repository at this point in the history
  • Loading branch information
RNEvok committed Jun 10, 2024
1 parent 80fc68d commit 9a5c176
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion StackTracing/simpleTracing.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { StackTraceCallData } from "../types";
import { countOccurrences } from "./../helpers/helperFunctions";

export const nixSlashes = (x: string) => x.replace (/\\/g, '/');

Expand All @@ -15,8 +16,10 @@ type SimpleParsedStack = {
export const parseRawStack = (str: string = ""): SimpleParsedStack => {
const lines = str.split('\n');

const atOccurs = countOccurrences("at ", str);
const inOccurs = countOccurrences("in ", str);
// Preposition that refers to where in code is called. Usually is "at", but, for example, in RN can be "in"
const at = "(in|at)";
const at = atOccurs > inOccurs ? "at" : "in";

const regexp1 = new RegExp(`${at} (.+) \\(eval ${at} .+ \\((.+)\\), .+\\)`);
const regexp2 = new RegExp(`${at} (.+) \\((.+)\\)`);
Expand Down
6 changes: 6 additions & 0 deletions helpers/helperFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,10 @@ export const errorToJSON = (error: any) => {
}

return {error: error};
}

export const countOccurrences = (searchFor: string, searchIn: string) => {
const regex = new RegExp(searchFor, 'g');
const matches = searchIn.match(regex);
return matches ? matches.length : 0;
}

0 comments on commit 9a5c176

Please # to comment.