1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.default = getCallsite;
|
7 | function _traceMapping() {
|
8 | const data = require('@jridgewell/trace-mapping');
|
9 | _traceMapping = function () {
|
10 | return data;
|
11 | };
|
12 | return data;
|
13 | }
|
14 | function _callsites() {
|
15 | const data = _interopRequireDefault(require('callsites'));
|
16 | _callsites = function () {
|
17 | return data;
|
18 | };
|
19 | return data;
|
20 | }
|
21 | function _gracefulFs() {
|
22 | const data = require('graceful-fs');
|
23 | _gracefulFs = function () {
|
24 | return data;
|
25 | };
|
26 | return data;
|
27 | }
|
28 | function _interopRequireDefault(obj) {
|
29 | return obj && obj.__esModule ? obj : {default: obj};
|
30 | }
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | const addSourceMapConsumer = (callsite, tracer) => {
|
40 | const getLineNumber = callsite.getLineNumber.bind(callsite);
|
41 | const getColumnNumber = callsite.getColumnNumber.bind(callsite);
|
42 | let position = null;
|
43 | function getPosition() {
|
44 | if (!position) {
|
45 | position = (0, _traceMapping().originalPositionFor)(tracer, {
|
46 | column: getColumnNumber() ?? -1,
|
47 | line: getLineNumber() ?? -1
|
48 | });
|
49 | }
|
50 | return position;
|
51 | }
|
52 | Object.defineProperties(callsite, {
|
53 | getColumnNumber: {
|
54 | value() {
|
55 | const value = getPosition().column;
|
56 | return value == null || value === 0 ? getColumnNumber() : value;
|
57 | },
|
58 | writable: false
|
59 | },
|
60 | getLineNumber: {
|
61 | value() {
|
62 | const value = getPosition().line;
|
63 | return value == null || value === 0 ? getLineNumber() : value;
|
64 | },
|
65 | writable: false
|
66 | }
|
67 | });
|
68 | };
|
69 | function getCallsite(level, sourceMaps) {
|
70 | const levelAfterThisCall = level + 1;
|
71 | const stack = (0, _callsites().default)()[levelAfterThisCall];
|
72 | const sourceMapFileName = sourceMaps?.get(stack.getFileName() ?? '');
|
73 | if (sourceMapFileName != null && sourceMapFileName !== '') {
|
74 | try {
|
75 | const sourceMap = (0, _gracefulFs().readFileSync)(
|
76 | sourceMapFileName,
|
77 | 'utf8'
|
78 | );
|
79 | addSourceMapConsumer(stack, new (_traceMapping().TraceMap)(sourceMap));
|
80 | } catch {
|
81 |
|
82 | }
|
83 | }
|
84 | return stack;
|
85 | }
|