mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-02 17:47:21 +08:00
Extract symbolicateStackTrace into its own module
Summary: Having a function that symbolicates any given stack trace is convenient, e.g. in #7459 More cleanup to follow. Reviewed By: davidaurelio Differential Revision: D3348616 fbshipit-source-id: 6313ec837869c6080829c811345a06aa1b2dcd21
This commit is contained in:
committed by
Facebook Github Bot 2
parent
7e100ac7a2
commit
2ef533352f
@@ -7,31 +7,19 @@
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @providesModule parseErrorStack
|
||||
* @flow
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
export type StackFrame = {
|
||||
file: string;
|
||||
lineNumber: number;
|
||||
column: number;
|
||||
};
|
||||
|
||||
var stacktraceParser = require('stacktrace-parser');
|
||||
|
||||
function resolveSourceMaps(sourceMapInstance, stackFrame) {
|
||||
try {
|
||||
var orig = sourceMapInstance.originalPositionFor({
|
||||
line: stackFrame.lineNumber,
|
||||
column: stackFrame.column,
|
||||
});
|
||||
if (orig) {
|
||||
// remove query string if any
|
||||
const queryStringStartIndex = orig.source.indexOf('?');
|
||||
stackFrame.file = queryStringStartIndex === -1
|
||||
? orig.source
|
||||
: orig.source.substring(0, queryStringStartIndex);
|
||||
stackFrame.lineNumber = orig.line;
|
||||
stackFrame.column = orig.column;
|
||||
}
|
||||
} catch (innerEx) {
|
||||
}
|
||||
}
|
||||
|
||||
function parseErrorStack(e, sourceMaps) {
|
||||
function parseErrorStack(e: Error): Array<StackFrame> {
|
||||
if (!e || !e.stack) {
|
||||
return [];
|
||||
}
|
||||
@@ -43,19 +31,6 @@ function parseErrorStack(e, sourceMaps) {
|
||||
stack.shift();
|
||||
}
|
||||
|
||||
if (sourceMaps) {
|
||||
sourceMaps.forEach((sourceMap, index) => {
|
||||
stack.forEach(frame => {
|
||||
if (frame.file.indexOf(sourceMap.file) !== -1 ||
|
||||
frame.file.replace('.map', '.bundle').indexOf(
|
||||
sourceMap.file
|
||||
) !== -1) {
|
||||
resolveSourceMaps(sourceMap, frame);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user