index.js 426 B

123456789101112131415161718192021
  1. 'use strict';
  2. const internals = {};
  3. exports.location = function (depth = 0) {
  4. const orig = Error.prepareStackTrace;
  5. Error.prepareStackTrace = (ignore, stack) => stack;
  6. const capture = {};
  7. Error.captureStackTrace(capture, this);
  8. const line = capture.stack[depth + 1];
  9. Error.prepareStackTrace = orig;
  10. return {
  11. filename: line.getFileName(),
  12. line: line.getLineNumber()
  13. };
  14. };