179 lines
5.4 KiB
React
179 lines
5.4 KiB
React
// Metro module 1141 (f1142).
|
|
import * as _classCallCheck from "./_classCallCheck";
|
|
import * as __createClass from "./_createClass";
|
|
import * as _possibleConstructorReturn from "./_possibleConstructorReturn";
|
|
import * as _getPrototypeOf from "./_getPrototypeOf";
|
|
import * as __inherits from "./_inherits";
|
|
import { Component, isValidElement, memo } from "react";
|
|
import { getClient, showReportDialog, withScope } from "./Module1024";
|
|
import { captureReactException } from "./captureReactException";
|
|
import { DEBUG_BUILD } from "./Module1142";
|
|
import { debug } from "./Module817";
|
|
import { hoistNonReactStatics } from "./getStatics";
|
|
let c948_7, c948_8, Component2;
|
|
let ErrorBoundary;
|
|
let env948 = {};
|
|
env948[5] = function _isNativeReflectConstruct() {
|
|
let c12831_0;
|
|
try {
|
|
c12831_0 = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
} catch ($e) {}
|
|
const _isNativeReflectConstruct2 = function _isNativeReflectConstruct() {
|
|
return !!c12831_0;
|
|
};
|
|
env948[5] = _isNativeReflectConstruct2;
|
|
return _isNativeReflectConstruct2();
|
|
};
|
|
Object.defineProperty(exports, Symbol.toStringTag, {
|
|
value: "Module"
|
|
});
|
|
c948_7 = "unknown";
|
|
c948_8 = {
|
|
componentStack: null,
|
|
error: null,
|
|
eventId: null
|
|
};
|
|
ErrorBoundary = function ErrorBoundary(a0) {
|
|
"use strict";
|
|
let c24232_0 = a0;
|
|
_classCallCheck(this, ErrorBoundary);
|
|
const r12 = [a0];
|
|
const r11 = _getPrototypeOf(ErrorBoundary);
|
|
const r23 = _possibleConstructorReturn(this, (0, env948[5])() ? Reflect.construct(r11, r12, _getPrototypeOf(this).constructor) : r11.apply(this, r12));
|
|
r23.state = c948_8;
|
|
r23._openFallbackReportDialog = true;
|
|
const client = getClient();
|
|
if (client && a0.showDialog) {
|
|
r23._openFallbackReportDialog = false;
|
|
r23._cleanupHook = client.on("afterSendEvent", (a0) => {
|
|
const type = a0.type;
|
|
if ((type ? !type : this._lastEventId) && a0.event_id === this._lastEventId) {
|
|
showReportDialog({
|
|
...c24232_0.dialogOptions,
|
|
eventId: this._lastEventId
|
|
});
|
|
}
|
|
});
|
|
}
|
|
return r23;
|
|
};
|
|
__inherits(ErrorBoundary, Component);
|
|
Component2 = __createClass(ErrorBoundary, [{
|
|
key: "componentDidCatch",
|
|
value: function componentDidCatch(error, a1) {
|
|
"use strict";
|
|
let c24233_2 = a1;
|
|
const componentStack = a1.componentStack;
|
|
const props = this.props;
|
|
const { beforeCapture, onError, showDialog, dialogOptions } = props;
|
|
withScope((a0) => {
|
|
if (beforeCapture) {
|
|
beforeCapture(a0, error, componentStack);
|
|
}
|
|
const _lastEventId = captureReactException(error, c24233_2, {
|
|
mechanism: {
|
|
handled: this.props.handled != null ? this.props.handled : !!this.props.fallback,
|
|
type: "auto.function.react.error_boundary"
|
|
}
|
|
});
|
|
if (onError) {
|
|
onError(error, componentStack, _lastEventId);
|
|
}
|
|
if (showDialog) {
|
|
this._lastEventId = _lastEventId;
|
|
if (this._openFallbackReportDialog) {
|
|
showReportDialog({
|
|
...dialogOptions,
|
|
eventId: _lastEventId
|
|
});
|
|
}
|
|
}
|
|
this.setState({
|
|
error,
|
|
componentStack,
|
|
eventId: _lastEventId
|
|
});
|
|
});
|
|
}
|
|
}, {
|
|
key: "componentDidMount",
|
|
value: function componentDidMount() {
|
|
"use strict";
|
|
const onMount = this.props.onMount;
|
|
if (onMount) {
|
|
onMount();
|
|
}
|
|
}
|
|
}, {
|
|
key: "componentWillUnmount",
|
|
value: function componentWillUnmount() {
|
|
"use strict";
|
|
const state = this.state;
|
|
const { error: error2, componentStack: componentStack2, eventId } = state;
|
|
const onUnmount = this.props.onUnmount;
|
|
if (onUnmount) {
|
|
if (this.state === c948_8) {
|
|
onUnmount(null, null, null);
|
|
} else {
|
|
onUnmount(error2, componentStack2, eventId);
|
|
}
|
|
}
|
|
if (this._cleanupHook) {
|
|
this._cleanupHook();
|
|
this._cleanupHook = void 0;
|
|
}
|
|
}
|
|
}, {
|
|
key: "resetErrorBoundary",
|
|
value: function resetErrorBoundary() {
|
|
"use strict";
|
|
const onReset = this.props.onReset;
|
|
const state = this.state;
|
|
const { error: error2, componentStack: componentStack2, eventId } = state;
|
|
if (onReset) {
|
|
onReset(error2, componentStack2, eventId);
|
|
}
|
|
this.setState(c948_8);
|
|
}
|
|
}, {
|
|
key: "render",
|
|
value: function render() {
|
|
"use strict";
|
|
const props = this.props;
|
|
let Fallback = props.fallback;
|
|
const children = props.children;
|
|
const state = this.state;
|
|
if (state.componentStack === null) {
|
|
let r34 = children;
|
|
if (typeof r34 === "function") {
|
|
r34 = children();
|
|
}
|
|
return r34;
|
|
}
|
|
let r14 = typeof Fallback === "function" ? <Fallback error={state.error} componentStack={state.componentStack} resetError={() => this.resetErrorBoundary()} eventId={state.eventId} /> : Fallback;
|
|
if (!isValidElement(r14)) {
|
|
if (Fallback) {
|
|
Fallback = DEBUG_BUILD;
|
|
}
|
|
r14 = null;
|
|
if (Fallback) {
|
|
debug.warn("fallback did not produce a valid ReactElement");
|
|
r14 = null;
|
|
}
|
|
}
|
|
return r14;
|
|
}
|
|
}]);
|
|
export { Component2 as ErrorBoundary };
|
|
export const UNKNOWN_COMPONENT = "unknown";
|
|
export function withErrorBoundary(a0, c12832_1) {
|
|
let Component3 = a0;
|
|
const r7 = a0.displayName || a0.name || c948_7;
|
|
const r10 = memo((a0) => <Component2 {...c12832_1}>
|
|
<Component3 {...a0} />
|
|
</Component2>);
|
|
r10.displayName = `errorBoundary(${r7})`;
|
|
hoistNonReactStatics(r10, a0);
|
|
return r10;
|
|
}
|