react-native/Libraries/Core/Devtools/parseErrorStack.js
Wietse Venema 800dc77172 Fixes type definition of StackFrame
Summary:
**Motivation**
This PR fixes the flow type definition of StackFrame in parseErrorStack.js. The methodName was missing and the column could be `null`. We integrate with it in our codebase and we wanted to use `methodName`, but flow complained.

Refer to this file for possible values: [github.com/errwischt/stacktrace-parser/blob/master/lib/stacktrace-parser.js](https://github.com/errwischt/stacktrace-parser/blob/master/lib/stacktrace-parser.js)

This also allowed me to remove a flow error suppression.

**Test plan (required)**
I ran flow on the project, no errors
Closes https://github.com/facebook/react-native/pull/12499

Differential Revision: D4619885

Pulled By: ericvicenti

fbshipit-source-id: 0bf5a2304cb0dc9f2c6df026a5cee71c8a419c01
2017-02-27 14:04:57 -08:00

39 lines
896 B
JavaScript

/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule parseErrorStack
* @flow
*/
'use strict';
export type StackFrame = {
column: ?number,
file: string,
lineNumber: number,
methodName: string,
};
var stacktraceParser = require('stacktrace-parser');
function parseErrorStack(e: Error): Array<StackFrame> {
if (!e || !e.stack) {
return [];
}
var stack = Array.isArray(e.stack) ? e.stack : stacktraceParser.parse(e.stack);
var framesToPop = typeof e.framesToPop === 'number' ? e.framesToPop : 0;
while (framesToPop--) {
stack.shift();
}
return stack;
}
module.exports = parseErrorStack;