1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 |
|
14 | function parse(err) {
|
15 | if (!err.stack) {
|
16 | return [];
|
17 | }
|
18 | var lines = err.stack.split('\n').slice(1);
|
19 | return lines
|
20 | .map(function (line) {
|
21 | if (line.match(/^\s*[-]{4,}$/)) {
|
22 | return {
|
23 | columnNumber: null,
|
24 | fileName: line,
|
25 | functionName: null,
|
26 | lineNumber: null,
|
27 | methodName: null,
|
28 | native: null,
|
29 | typeName: null,
|
30 | };
|
31 | }
|
32 | var lineMatch = line.match(/at (?:(.+?)\s+\()?(?:(.+?):(\d+)(?::(\d+))?|([^)]+))\)?/);
|
33 | if (!lineMatch) {
|
34 | return undefined;
|
35 | }
|
36 | var object = null;
|
37 | var method = null;
|
38 | var functionName = null;
|
39 | var typeName = null;
|
40 | var methodName = null;
|
41 | var isNative = lineMatch[5] === 'native';
|
42 | if (lineMatch[1]) {
|
43 | functionName = lineMatch[1];
|
44 | var methodStart = functionName.lastIndexOf('.');
|
45 | if (functionName[methodStart - 1] === '.') {
|
46 | methodStart--;
|
47 | }
|
48 | if (methodStart > 0) {
|
49 | object = functionName.substr(0, methodStart);
|
50 | method = functionName.substr(methodStart + 1);
|
51 | var objectEnd = object.indexOf('.Module');
|
52 | if (objectEnd > 0) {
|
53 | functionName = functionName.substr(objectEnd + 1);
|
54 | object = object.substr(0, objectEnd);
|
55 | }
|
56 | }
|
57 | typeName = null;
|
58 | }
|
59 | if (method) {
|
60 | typeName = object;
|
61 | methodName = method;
|
62 | }
|
63 | if (method === '<anonymous>') {
|
64 | methodName = null;
|
65 | functionName = null;
|
66 | }
|
67 | var properties = {
|
68 | columnNumber: parseInt(lineMatch[4], 10) || null,
|
69 | fileName: lineMatch[2] || null,
|
70 | functionName: functionName,
|
71 | lineNumber: parseInt(lineMatch[3], 10) || null,
|
72 | methodName: methodName,
|
73 | native: isNative,
|
74 | typeName: typeName,
|
75 | };
|
76 | return properties;
|
77 | })
|
78 | .filter(function (callSite) { return !!callSite; });
|
79 | }
|
80 | exports.parse = parse;
|
81 |
|
\ | No newline at end of file |