-
Notifications
You must be signed in to change notification settings - Fork 2
/
prepare-stack-trace.js
52 lines (43 loc) · 1.57 KB
/
prepare-stack-trace.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
/* eslint-disable no-not-accumulator-reassign/no-not-accumulator-reassign, no-var, vars-on-top, prefer-template, prefer-arrow-callback, func-names, prefer-destructuring, object-shorthand */
var sourcemap = require('./source-map-stack-trace')
module.exports = function prepareStackTrace(stackTrace, options) {
var stack = stackTrace.split('\n')
stack = stack.map(function(s) {
return s.replace(/\sg/, '')
})
stack = stack.map(function(entry) {
// entry is something like `functionName@path/to/my/file:line:column`
// or `path/to/my/file:line:column`
// or `path/to/my/file`
// or `path/to/@my/file:line:column`
var parts = entry.split('@')
var fn = parts.shift()
var filePath = parts.join('@') // the path can contain @
if (fn.indexOf('/Users/') === 0) {
// actually we didn't have a fn so just put it back in the filePath
filePath = fn + (filePath ? '@' + filePath : '')
fn = null
}
if (!filePath) {
// we should always have a filePath, so if we don't have one here, it means that the function what actually anonymous and that it is the filePath instead
filePath = entry
fn = null
}
var filePathParts = filePath.split(':')
filePath = filePathParts[0]
// the file is the last part of the filePath
var file = filePath.split('/')
file = file[file.length - 1]
return {
fn: fn,
file: file,
filePath: filePath,
line: filePathParts[1],
column: filePathParts[2],
}
})
if (options && options.sourcemaps) {
return sourcemap(stack)
}
return stack
}