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  // Native support for parsing for non-standard Hermes stack traces.
12  if (global.HermesInternal) {
13    return require('./parseHermesStack').parseErrorStack(stack);
14  }
15
16  return parse(stack).map((frame) => {
17    // frame.file will mostly look like `http://localhost:8081/index.bundle?platform=web&dev=true&hot=false`
18    return {
19      ...frame,
20      column: frame.column != null ? frame.column - 1 : null,
21    };
22  });
23}
24
25export default parseErrorStack;
26