8000 browser: reformat Tracekit to 120 columns · phthhieu/sentry-javascript@a614b52 · GitHub
[go: up one dir, main page]

Skip to content

Commit a614b52

Browse files
committed
browser: reformat Tracekit to 120 columns
1 parent ac7e9d4 commit a614b52

File tree

1 file changed

+21
-78
lines changed

1 file changed

+21
-78
lines changed

packages/browser/src/tracekit/index.js

Lines changed: 21 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ 10000 -162,6 +162,9 @@ TraceKit.report = (function reportModuleWrapper() {
162162
* @memberof TraceKit.report
163163
*/
164164
function subscribe(handler) {
165+
// NOTE: We call both handlers manually in browser/integrations/globalhandler.ts
166+
// So user can choose which one he wants to attach
167+
165168
// installGlobalHandler();
166169
// installGlobalUnhandledRejectionHandler();
167170
handlers.push(handler);
@@ -234,12 +237,7 @@ TraceKit.report = (function reportModuleWrapper() {
234237
message = isErrorEvent(message) ? message.message : message;
235238

236239
if (lastExceptionStack) {
237-
TraceKit.computeStackTrace.augmentStackTraceWithInitialElement(
238-
lastExceptionStack,
239-
url,
240-
lineNo,
241-
message,
242-
);
240+
TraceKit.computeStackTrace.augmentStackTraceWithInitialElement(lastExceptionStack, url, lineNo, message);
243241
processLastException();
244242
} else if (errorObj && isError(errorObj)) {
245243
stack = TraceKit.computeStackTrace(errorObj);
@@ -261,14 +259,8 @@ TraceKit.report = (function reportModuleWrapper() {
261259
}
262260
}
263261

264-
location.func = TraceKit.computeStackTrace.guessFunctionName(
265-
location.url,
266-
location.line,
267-
);
268-
location.context = TraceKit.computeStackTrace.gatherContext(
269-
location.url,
270-
location.line,
271-
);
262+
location.func = TraceKit.computeStackTrace.guessFunctionName(location.url, location.line);
263+
location.context = TraceKit.computeStackTrace.gatherContext(location.url, location.line);
272264
stack = {
273265
name: name,
274266
message: msg,
@@ -748,15 +740,7 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() {
748740
args = parts[2].split(',').join('\\s*,\\s*');
749741

750742
body = escapeRegExp(parts[3]).replace(/;$/, ';?'); // semicolon is inserted if the function ends with a comment.replace(/\s+/g, '\\s+');
751-
re = new RegExp(
752-
'function' +
753-
name +
754-
'\\s*\\(\\s*' +
755-
args +
756-
'\\s*\\)\\s*{\\s*' +
757-
body +
758-
'\\s*}',
759-
);
743+
re = new RegExp('function' + name + '\\s*\\(\\s*' + args + '\\s*\\)\\s*{\\s*' + body + '\\s*}');
760744
}
761745

762746
// look for a normal function definition
@@ -770,10 +754,7 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() {
770754
body = escapeCodeAsRegExpForMatchingInsideHTML(parts[2]);
771755

772756
// look for a function defined in HTML as an onXXX handler
773-
re = new RegExp(
774-
'on' + event + '=[\\\'"]\\s*' + body + '\\s*[\\\'"]',
775-
'i',
776-
);
757+
re = new RegExp('on' + event + '=[\\\'"]\\s*' + body + '\\s*[\\\'"]', 'i');
777758

778759
if ((result = findSourceInUrls(re, urls[0]))) {
779760
return result;
@@ -935,8 +916,7 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() {
935916
// Now we check to see if it's a relative URL.
936917
// If it is, convert it to an absolute one.
937918
if (sourceMapAddress.charAt(0) === '~') {
938-
sourceMapAddress =
939-
getLocationOrigin() + sourceMapAddress.slice(1);
919+
sourceMapAddress = getLocationOrigin() + sourceMapAddress.slice(1);
940920
}
941921

942922
// Now we strip the '.map' off of the end of the URL and update the
@@ -946,9 +926,7 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() {
946926
}
947927
}
948928

949-
element.context = element.line
950-
? gatherContext(element.url, element.line)
951-
: null;
929+
element.context = element.line ? gatherContext(element.url, element.line) : null;
952930

953931
stack.push(element);
954932
}
@@ -958,11 +936,7 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() {
958936
}
959937

960938
if (stack[0] && stack[0].line && !stack[0].column && reference) {
961-
stack[0].column = findSourceInLine(
962-
reference[1],
963-
stack[0].url,
964-
stack[0].line,
965-
);
939+
stack[0].column = findSourceInLine(reference[1], stack[0].url, stack[0].line);
966940
}
967941

968942
return {
@@ -1080,10 +1054,7 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() {
10801054
lineRE2 = /^\s*Line (\d+) of inline#(\d+) script in ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i,
10811055
lineRE3 = /^\s*Line (\d+) of function script\s*$/i,
10821056
stack = [],
1083-
scripts =
1084-
window &&
1085-
window.document &&
1086-
window.document.getElementsByTagName('script'),
1057+
scripts = window && window.document && window.document.getElementsByTagName('script'),
10871058
inlineScriptBlocks = [],
10881059
parts;
10891060

@@ -1119,16 +1090,13 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() {
11191090
source = source.join('\n');
11201091
var pos = source.indexOf(script.innerText);
11211092
if (pos >= 0) {
1122-
item.line =
1123-
relativeLine + source.substring(0, pos).split('\n').length;
1093+
item.line = relativeLine + source.substring(0, pos).split('\n').length;
11241094
}
11251095
}
11261096
}
11271097
} else if ((parts = lineRE3.exec(lines[line]))) {
11281098
var url = getLocationHref().replace(/#.*$/, '');
1129-
var re = new RegExp(
1130-
escapeCodeAsRegExpForMatchingInsideHTML(lines[line + 1]),
1131-
);
1099+
var re = new RegExp(escapeCodeAsRegExpForMatchingInsideHTML(lines[line + 1]));
11321100
var src = findSourceInUrls(re, [url]);
11331101
item = {
11341102
url: url,
@@ -1145,10 +1113,7 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() {
11451113
}
11461114
var context = gatherContext(item.url, item.line);
11471115
var midline = context ? context[Math.floor(context.length / 2)] : null;
1148-
if (
1149-
context &&
1150-
midline.replace(/^\s*/, '') === lines[line + 1].replace(/^\s*/, '')
1151-
) {
1116+
if (context && midline.replace(/^\s*/, '') === lines[line + 1].replace(/^\s*/, '')) {
11521117
item.context = context;
11531118
} else {
11541119
// if (context) alert("Context mismatch. Correct midline:\n" + lines[i+1] + "\n\nMidline:\n" + midline + "\n\nContext:\n" + context.join("\n") + "\n\nURL:\n" + item.url);
@@ -1183,12 +1148,7 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() {
11831148
* augmented.
11841149
* @memberof TraceKit.computeStackTrace
11851150
*/
1186-
function augmentStackTraceWithInitialElement(
1187-
stackInfo,
1188-
url,
1189-
lineNo,
1190-
message,
1191-
) {
1151+
function augmentStackTraceWithInitialElement(stackInfo, url, lineNo, message) {
11921152
var initial = {
11931153
url: url,
11941154
line: lineNo,
@@ -1207,21 +1167,14 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() {
12071167

12081168
var reference = / '([^']+)' /.exec(message);
12091169
if (reference) {
1210-
initial.column = findSourceInLine(
1211-
reference[1],
1212-
initial.url,
1213-
initial.line,
1214-
);
1170+
initial.column = findSourceInLine(reference[1], initial.url, initial.line);
12151171
}
12161172

12171173
if (stackInfo.stack.length > 0) {
12181174
if (stackInfo.stack[0].url === initial.url) {
12191175
if (stackInfo.stack[0].line === initial.line) {
12201176
return false; // already in stack trace
1221-
} else if (
1222-
!stackInfo.stack[0].line &&
1223-
stackInfo.stack[0].func === initial.func
1224-
) {
1177+
} else if (!stackInfo.stack[0].line && stackInfo.stack[0].func === initial.func) {
12251178
stackInfo.stack[0].line = initial.line;
12261179
stackInfo.stack[0].context = initial.context;
12271180
return false;
@@ -1258,11 +1211,7 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() {
12581211
item,
12591212
source;
12601213

1261-
for (
1262-
var curr = computeStackTraceByWalkingCallerChain.caller;
1263-
curr && !recursion;
1264-
curr = curr.caller
1265-
) {
1214+
for (var curr = computeStackTraceByWalkingCallerChain.caller; curr && !recursion; curr = curr.caller) {
12661215
if (curr === computeStackTrace || curr === TraceKit.report) {
12671216
continue;
12681217
}
@@ -1462,13 +1411,7 @@ if (!TraceKit.linesOfContext || TraceKit.linesOfContext < 1) {
14621411

14631412
const subscribe = TraceKit.report.subscribe;
14641413
const installGlobalHandler = TraceKit.report.installGlobalHandler;
1465-
const installGlobalUnhandledRejectionHandler =
1466-
TraceKit.report.installGlobalUnhandledRejectionHandler;
1414+
const installGlobalUnhandledRejectionHandler = TraceKit.report.installGlobalUnhandledRejectionHandler;
14671415
const computeStackTrace = TraceKit.computeStackTrace;
14681416

1469-
export {
1470-
subscribe,
1471-
installGlobalHandler,
1472-
installGlobalUnhandledRejectionHandler,
1473-
computeStackTrace,
1474-
};
1417+
export { subscribe, installGlobalHandler, installGlobalUnhandledRejectionHandler, computeStackTrace };

0 commit comments

Comments
 (0)
0