mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-01-31 17:18:45 +08:00
[ReactNative] Make JS stack traces in Xcode prettier
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Copyright 2004-present Facebook. All Rights Reserved.
|
||||
*
|
||||
* @providesModule parseErrorStack
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var stacktraceParser = require('stacktrace-parser');
|
||||
|
||||
function resolveSourceMaps(sourceMapInstance, stackFrame) {
|
||||
try {
|
||||
var orig = sourceMapInstance.originalPositionFor({
|
||||
line: stackFrame.lineNumber,
|
||||
column: stackFrame.column,
|
||||
});
|
||||
if (orig) {
|
||||
stackFrame.file = orig.source;
|
||||
stackFrame.lineNumber = orig.line;
|
||||
stackFrame.column = orig.column;
|
||||
}
|
||||
} catch (innerEx) {
|
||||
}
|
||||
}
|
||||
|
||||
function parseErrorStack(e, sourceMapInstance) {
|
||||
var stack = stacktraceParser.parse(e.stack);
|
||||
|
||||
var framesToPop = e.framesToPop || 0;
|
||||
while (framesToPop--) {
|
||||
stack.shift();
|
||||
}
|
||||
|
||||
if (sourceMapInstance) {
|
||||
stack.forEach(resolveSourceMaps.bind(null, sourceMapInstance));
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
module.exports = parseErrorStack;
|
||||
Reference in New Issue
Block a user