1import { parse, StackFrame } from 'stacktrace-parser'; 2 3function parseErrorStack(stack?: string): (StackFrame & { collapse?: boolean })[] { 4 if (stack == null) { 5 return []; 6 } 7 if (Array.isArray(stack)) { 8 return stack; 9 } 10 11 // This file seems to be web-only, so we can remove this. 12 // // Native support for parsing for non-standard Hermes stack traces. 13 // if (global.HermesInternal) { 14 // return require('./parseHermesStack').parseErrorStack(stack); 15 // } 16 17 return parse(stack).map((frame) => { 18 // frame.file will mostly look like `http://localhost:8081/index.bundle?platform=web&dev=true&hot=false` 19 return { 20 ...frame, 21 column: frame.column != null ? frame.column - 1 : null, 22 }; 23 }); 24} 25 26export default parseErrorStack; 27