UNPKG

@evojs/callsite

Version:
41 lines 2.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Callsite = void 0; var source_map_support_1 = require("source-map-support"); (0, source_map_support_1.install)(); var INTERNAL_CALLSITES_SHIFT = 2; var NATIVE_PREPARE_STACK_TRACE = Error.prepareStackTrace; var OVERRIDED_PREPARE_STACK_TRACE = function (err, callsites) { return callsites; }; var Callsite = /** @class */ (function () { function Callsite(nodeCallsite) { var _a, _b, _c, _d, _e, _f; this.source = (_a = nodeCallsite.getFileName()) !== null && _a !== void 0 ? _a : undefined; this.line = (_b = nodeCallsite.getLineNumber()) !== null && _b !== void 0 ? _b : undefined; this.column = (_c = nodeCallsite.getColumnNumber()) !== null && _c !== void 0 ? _c : undefined; this.typeName = (_d = nodeCallsite.getTypeName()) !== null && _d !== void 0 ? _d : undefined; this.functionName = (_f = (_e = nodeCallsite.getMethodName()) !== null && _e !== void 0 ? _e : nodeCallsite.getFunctionName()) !== null && _f !== void 0 ? _f : undefined; } /** * Get callsites */ Callsite.get = function (depth, count) { if (depth === void 0) { depth = 0; } if (count === void 0) { count = this.DEFAULT_CALLSITES_COUNT; } var nodeCallsites = this._getNodeCallsites(depth + count); var callsites = nodeCallsites.slice(depth).map(function (cs) { return new Callsite(cs); }); return callsites; }; Callsite._getNodeCallsites = function (limit) { var prevStackTraceLimit = Error.stackTraceLimit; Error.stackTraceLimit = INTERNAL_CALLSITES_SHIFT + limit; Error.prepareStackTrace = OVERRIDED_PREPARE_STACK_TRACE; var nodeCallsites = new Error().stack; Error.prepareStackTrace = NATIVE_PREPARE_STACK_TRACE; Error.stackTraceLimit = prevStackTraceLimit; return nodeCallsites.slice(INTERNAL_CALLSITES_SHIFT).map(function (cs) { return (0, source_map_support_1.wrapCallSite)(cs); }); }; Callsite.DEFAULT_CALLSITES_COUNT = 1; return Callsite; }()); exports.Callsite = Callsite; //# sourceMappingURL=index.js.map