export function wrapFnWithLocation()

in src/helpers.ts [288:314]


export function wrapFnWithLocation<A extends unknown[], R>(
  func: (location: Location, ...args: A) => R
): (...args: A) => R {
  return (...args) => {
    const _prepareStackTrace = Error.prepareStackTrace;
    Error.prepareStackTrace = (_, stackFrames) => {
      // Deafult CallSite would not map to the original transpiled source
      // correctly, So we use source-map-support to map the CallSite to the
      // original source from our cached source map
      const frame: NodeJS.CallSite = sourceMapSupport.wrapCallSite(
        stackFrames[1]
      );
      return {
        file: frame.getFileName(),
        line: frame.getLineNumber(),
        column: frame.getColumnNumber(),
      };
    };
    Error.stackTraceLimit = 2;
    const obj: { stack: Location } = {} as any;
    Error.captureStackTrace(obj);
    const location = obj.stack;
    Error.stackTraceLimit = dstackTraceLimit;
    Error.prepareStackTrace = _prepareStackTrace;
    return func(location, ...args);
  };
}