53 lines
1.8 KiB
JavaScript
53 lines
1.8 KiB
JavaScript
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.getFirstDestUrl = exports.replaceProxiedUrlsInStack = void 0;
|
||
|
const url_1 = require("./url");
|
||
|
const STACK_FRAME_REG_EXPS = [
|
||
|
/^\s*at .*\((\S+)\)/,
|
||
|
/^\s*at (\S+)/,
|
||
|
/^.*@(\S+)/,
|
||
|
/(.+)/, // Any string
|
||
|
];
|
||
|
const STACK_FRAME_REGEX = /(?:^|\n)(?:\s*at |.*@)(?:.*\()?(\S+?):\d+:\d+\)?/g;
|
||
|
const ROW_COLUMN_NUMBER_REG_EX = /:\d+:\d+$/;
|
||
|
function getDestSource(source) {
|
||
|
const parsedProxiedUrl = (0, url_1.parseProxyUrl)(source);
|
||
|
return parsedProxiedUrl && parsedProxiedUrl.destUrl;
|
||
|
}
|
||
|
function replaceUrlWithProxied(str, source) {
|
||
|
source = source.replace(ROW_COLUMN_NUMBER_REG_EX, '');
|
||
|
const destUrl = getDestSource(source);
|
||
|
return destUrl ? str.replace(source, destUrl) : str;
|
||
|
}
|
||
|
function replaceProxiedUrlsInStack(stack) {
|
||
|
if (!stack)
|
||
|
return stack;
|
||
|
const stackFrames = stack.split('\n');
|
||
|
for (let i = 0; i < stackFrames.length; i++) {
|
||
|
const stackFrame = stackFrames[i];
|
||
|
for (const stackFrameRegExp of STACK_FRAME_REG_EXPS) {
|
||
|
if (stackFrameRegExp.test(stackFrame)) {
|
||
|
stackFrames[i] = stackFrame.replace(stackFrameRegExp, replaceUrlWithProxied);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return stackFrames.join('\n');
|
||
|
}
|
||
|
exports.replaceProxiedUrlsInStack = replaceProxiedUrlsInStack;
|
||
|
function getFirstDestUrl(stack) {
|
||
|
if (!stack)
|
||
|
return null;
|
||
|
let searchResult = STACK_FRAME_REGEX.exec(stack);
|
||
|
while (searchResult) {
|
||
|
const destUrl = getDestSource(searchResult[1]);
|
||
|
if (destUrl) {
|
||
|
STACK_FRAME_REGEX.lastIndex = 0;
|
||
|
return destUrl;
|
||
|
}
|
||
|
searchResult = STACK_FRAME_REGEX.exec(stack);
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
exports.getFirstDestUrl = getFirstDestUrl;
|