mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
05418f8fcc
Summary: Flow is changing the behavior of object types to no longer be valid supertypes of classes. This replaces object types when they appear as supertypes of classes to be interfaces to avoid errors when this change rolls out. Changelog: [Internal] Reviewed By: pieterv Differential Revision: D27193522 fbshipit-source-id: c3e3fca8a4cacd90770a95b773ff2c659774b9a6
70 lines
1.7 KiB
JavaScript
70 lines
1.7 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @flow strict
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
import type {StackFrame} from '../NativeExceptionsManager';
|
|
import type {HermesParsedStack} from './parseHermesStack';
|
|
|
|
const parseHermesStack = require('./parseHermesStack');
|
|
|
|
// $FlowFixMe[incompatible-exact]
|
|
export type ExtendedError = Error &
|
|
interface {
|
|
jsEngine?: string,
|
|
preventSymbolication?: boolean,
|
|
componentStack?: string,
|
|
forceRedbox?: boolean,
|
|
isComponentError?: boolean,
|
|
};
|
|
|
|
function convertHermesStack(stack: HermesParsedStack): Array<StackFrame> {
|
|
const frames = [];
|
|
for (const entry of stack.entries) {
|
|
if (entry.type !== 'FRAME') {
|
|
continue;
|
|
}
|
|
const {location, functionName} = entry;
|
|
if (location.type === 'NATIVE') {
|
|
continue;
|
|
}
|
|
frames.push({
|
|
methodName: functionName,
|
|
file: location.sourceUrl,
|
|
lineNumber: location.line1Based,
|
|
column:
|
|
location.type === 'SOURCE'
|
|
? location.column1Based - 1
|
|
: location.virtualOffset0Based,
|
|
});
|
|
}
|
|
return frames;
|
|
}
|
|
|
|
function parseErrorStack(errorStack?: string): Array<StackFrame> {
|
|
if (errorStack == null) {
|
|
return [];
|
|
}
|
|
|
|
const stacktraceParser = require('stacktrace-parser');
|
|
const parsedStack = Array.isArray(errorStack)
|
|
? errorStack
|
|
: global.HermesInternal
|
|
? convertHermesStack(parseHermesStack(errorStack))
|
|
: stacktraceParser.parse(errorStack).map(frame => ({
|
|
...frame,
|
|
column: frame.column != null ? frame.column - 1 : null,
|
|
}));
|
|
|
|
return parsedStack;
|
|
}
|
|
|
|
module.exports = parseErrorStack;
|