This repository has been archived by the owner on Aug 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstackTrace.js
72 lines (61 loc) · 1.98 KB
/
stackTrace.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
https://github.com/felixge/node-stack-trace/
*/
module.exports.parse = function(err) {
if (!err.stack) {
return [];
}
let lines = err.stack.split('\n').slice(1);
return lines
.map(function(line) {
if (line.match(/^\s*[-]{4,}$/)) {
return {
fileName: line,
lineNumber: null,
functionName: null,
typeName: null,
methodName: null,
columnNumber: null,
'native': null,
};
}
let lineMatch = line.match(/at (?:(.+)\s+\()?(?:(.+?):(\d+):(\d+)|([^)]+))\)?/);
if (!lineMatch) {
return;
}
let object = null;
let method = null;
let functionName = null;
let typeName = null;
let methodName = null;
let isNative = (lineMatch[5] === 'native');
if (lineMatch[1]) {
let methodMatch = lineMatch[1].match(/([^\.]+)(?:\.(.+))?/);
object = methodMatch[1];
method = methodMatch[2];
functionName = lineMatch[1];
typeName = 'Object';
}
if (method) {
typeName = object;
methodName = method;
}
if (method === '<anonymous>') {
methodName = null;
functionName = '';
}
let properties = {
fileName: lineMatch[2] || null,
lineNumber: parseInt(lineMatch[3], 10) || null,
functionName: functionName,
typeName: typeName,
methodName: methodName,
columnNumber: parseInt(lineMatch[4], 10) || null,
'native': isNative,
};
return properties;
})
.filter(function(callSite) {
return !!callSite;
});
};