Skip to content

Commit 6deaffb

Browse files
committed
Updated react-error-overlay to latest Flow (0.54.0)
1 parent e8b58ed commit 6deaffb

13 files changed

+92
-28
lines changed

packages/react-error-overlay/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"eslint-plugin-import": "2.7.0",
5252
"eslint-plugin-jsx-a11y": "5.1.1",
5353
"eslint-plugin-react": "7.1.0",
54-
"flow-bin": "0.52.0",
54+
"flow-bin": "^0.54.0",
5555
"jest": "20.0.4",
5656
"jest-fetch-mock": "1.2.1"
5757
},

packages/react-error-overlay/src/__tests__/__snapshots__/unmapper.js.snap

+14-7
Original file line numberDiff line numberDiff line change
@@ -46,37 +46,44 @@ Array [
4646
],
4747
"_scriptCode": Array [
4848
ScriptLine {
49-
"content": " },",
49+
"content": " },
50+
",
5051
"highlight": false,
5152
"lineNumber": 41463,
5253
},
5354
ScriptLine {
54-
"content": " [1, 2].map(function (v) {",
55+
"content": " [1, 2].map(function (v) {
56+
",
5557
"highlight": false,
5658
"lineNumber": 41464,
5759
},
5860
ScriptLine {
59-
"content": " return _react2.default.createElement(",
61+
"content": " return _react2.default.createElement(
62+
",
6063
"highlight": false,
6164
"lineNumber": 41465,
6265
},
6366
ScriptLine {
64-
"content": " 'div',",
67+
"content": " 'div',
68+
",
6569
"highlight": true,
6670
"lineNumber": 41466,
6771
},
6872
ScriptLine {
69-
"content": " {",
73+
"content": " {
74+
",
7075
"highlight": false,
7176
"lineNumber": 41467,
7277
},
7378
ScriptLine {
74-
"content": " __source: {",
79+
"content": " __source: {
80+
",
7581
"highlight": false,
7682
"lineNumber": 41468,
7783
},
7884
ScriptLine {
79-
"content": " fileName: _jsxFileName,",
85+
"content": " fileName: _jsxFileName,
86+
",
8087
"highlight": false,
8188
"lineNumber": 41469,
8289
},

packages/react-error-overlay/src/components/Collapsible.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
/* @flow */
1111
import React, { Component } from 'react';
12+
import type { Element } from 'react';
1213
import { black } from '../styles';
1314

1415
const _collapsibleStyle = {
@@ -35,7 +36,15 @@ const collapsibleExpandedStyle = {
3536
marginBottom: '0.6em',
3637
};
3738

38-
class Collapsible extends Component {
39+
type Props = {|
40+
children: Element<any>[]
41+
|};
42+
43+
type State = {|
44+
collapsed: boolean
45+
|};
46+
47+
class Collapsible extends Component<Props, State> {
3948
state = {
4049
collapsed: true,
4150
};

packages/react-error-overlay/src/components/ErrorOverlay.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
/* @flow */
1111
import React, { Component } from 'react';
12+
import type { Node } from 'react';
1213
import { black } from '../styles';
1314

1415
const overlayStyle = {
@@ -31,10 +32,19 @@ const overlayStyle = {
3132
color: black,
3233
};
3334

34-
class ErrorOverlay extends Component {
35+
type Props = {|
36+
children: Node,
37+
shortcutHandler?: (eventKey: string) => void
38+
|};
39+
40+
type State = {|
41+
collapsed: boolean
42+
|};
43+
44+
class ErrorOverlay extends Component<Props, State> {
3545
iframeWindow: window = null;
3646

37-
getIframeWindow = (element: HTMLDivElement) => {
47+
getIframeWindow = (element: ?HTMLDivElement) => {
3848
if (element) {
3949
const document = element.ownerDocument;
4050
this.iframeWindow = document.defaultView;

packages/react-error-overlay/src/containers/CompileErrorContainer.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ import Header from '../components/Header';
1515
import CodeBlock from '../components/CodeBlock';
1616
import generateAnsiHTML from '../utils/generateAnsiHTML';
1717

18-
class CompileErrorContainer extends PureComponent {
18+
type Props = {|
19+
error: string
20+
|};
21+
22+
class CompileErrorContainer extends PureComponent<Props, void> {
1923
render() {
2024
const { error } = this.props;
2125
return (

packages/react-error-overlay/src/containers/RuntimeError.js

+1
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,5 @@ function RuntimeError({ errorRecord, launchEditorEndpoint }: Props) {
6565
);
6666
}
6767

68+
export type { ErrorRecord };
6869
export default RuntimeError;

packages/react-error-overlay/src/containers/RuntimeErrorContainer.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,19 @@ import CloseButton from '../components/CloseButton';
1414
import NavigationBar from '../components/NavigationBar';
1515
import RuntimeError from './RuntimeError';
1616
import Footer from '../components/Footer';
17+
import type { ErrorRecord } from './RuntimeError';
1718

18-
class RuntimeErrorContainer extends PureComponent {
19+
type Props = {|
20+
errorRecords: ErrorRecord[],
21+
close: () => void,
22+
launchEditorEndpoint: ?string
23+
|};
24+
25+
type State = {|
26+
currentIndex: number
27+
|};
28+
29+
class RuntimeErrorContainer extends PureComponent<Props, State> {
1930
state = {
2031
currentIndex: 0,
2132
};

packages/react-error-overlay/src/containers/StackFrame.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import React, { Component } from 'react';
1212
import CodeBlock from './StackFrameCodeBlock';
1313
import { getPrettyURL } from '../utils/getPrettyURL';
1414
import { darkGray } from '../styles';
15+
import type { StackFrame as StackFrameType } from '../utils/stack-frame';
1516

1617
const linkStyle = {
1718
fontSize: '0.9em',
@@ -43,7 +44,19 @@ const toggleStyle = {
4344
lineHeight: '1.5',
4445
};
4546

46-
class StackFrame extends Component {
47+
type Props = {|
48+
frame: StackFrameType,
49+
launchEditorEndpoint: ?string,
50+
contextSize: number,
51+
critical: boolean,
52+
showCode: boolean
53+
|};
54+
55+
type State = {|
56+
compiled: boolean
57+
|};
58+
59+
class StackFrame extends Component<Props, State> {
4760
state = {
4861
compiled: false,
4962
};
@@ -74,7 +87,7 @@ class StackFrame extends Component {
7487
}
7588

7689
openInEditor = () => {
77-
if (!this.canOpenInEditor()) {
90+
if (!this.props.launchEditorEndpoint) {
7891
return;
7992
}
8093
const {
@@ -90,7 +103,7 @@ class StackFrame extends Component {
90103
).then(() => {}, () => {});
91104
};
92105

93-
onKeyDown = (e: SyntheticKeyboardEvent) => {
106+
onKeyDown = (e: SyntheticKeyboardEvent<>) => {
94107
if (e.key === 'Enter') {
95108
this.openInEditor();
96109
}

packages/react-error-overlay/src/containers/StackFrameCodeBlock.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@ import codeFrame from 'babel-code-frame';
2121
type StackFrameCodeBlockPropsType = {|
2222
lines: ScriptLine[],
2323
lineNum: number,
24-
columnNum: number,
24+
columnNum: ?number,
2525
contextSize: number,
2626
main: boolean,
2727
|};
2828

29-
function StackFrameCodeBlock(props: StackFrameCodeBlockPropsType) {
29+
// Exact type workaround for spread operator.
30+
// See: https://github.com/facebook/flow/issues/2405
31+
type Exact<T> = $Shape<T>;
32+
33+
function StackFrameCodeBlock(props: Exact<StackFrameCodeBlockPropsType>) {
3034
const { lines, lineNum, columnNum, contextSize, main } = props;
3135
const sourceCode = [];
3236
let whiteSpace = Infinity;

packages/react-error-overlay/src/containers/StackTrace.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import StackFrame from './StackFrame';
1313
import Collapsible from '../components/Collapsible';
1414
import { isInternalFile } from '../utils/isInternalFile';
1515
import { isBultinErrorName } from '../utils/isBultinErrorName';
16+
import type { StackFrame as StackFrameType } from '../utils/stack-frame';
1617

1718
const traceStyle = {
1819
fontSize: '1em',
@@ -21,7 +22,14 @@ const traceStyle = {
2122
overflow: 'auto',
2223
};
2324

24-
class StackTrace extends Component {
25+
type Props = {|
26+
stackFrames: StackFrameType[],
27+
errorName: string,
28+
contextSize: number,
29+
launchEditorEndpoint: ?string,
30+
|};
31+
32+
class StackTrace extends Component<Props> {
2533
renderFrames() {
2634
const {
2735
stackFrames,

packages/react-error-overlay/src/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
/* @flow */
1111
import React from 'react';
12+
import type { Element } from 'react';
1213
import ReactDOM from 'react-dom';
1314
import CompileErrorContainer from './containers/CompileErrorContainer';
1415
import RuntimeErrorContainer from './containers/RuntimeErrorContainer';
@@ -21,13 +22,12 @@ import type { ErrorRecord } from './listenToRuntimeErrors';
2122
type RuntimeReportingOptions = {|
2223
onError: () => void,
2324
launchEditorEndpoint: string,
24-
filename?: string,
2525
|};
2626

2727
let iframe: null | HTMLIFrameElement = null;
2828
let isLoadingIframe: boolean = false;
2929

30-
let renderedElement: null | React.Element<any> = null;
30+
let renderedElement: null | Element<any> = null;
3131
let currentBuildError: null | string = null;
3232
let currentRuntimeErrorRecords: Array<ErrorRecord> = [];
3333
let currentRuntimeErrorOptions: null | RuntimeReportingOptions = null;
@@ -56,7 +56,7 @@ export function startReportingRuntimeErrors(options: RuntimeReportingOptions) {
5656
} finally {
5757
handleRuntimeError(errorRecord);
5858
}
59-
}, options.filename);
59+
});
6060
}
6161

6262
function handleRuntimeError(errorRecord) {

packages/react-error-overlay/src/listenToRuntimeErrors.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ export type ErrorRecord = {|
3939
stackFrames: StackFrame[],
4040
|};
4141

42-
export function listenToRuntimeErrors(
43-
crash: ErrorRecord => void,
44-
filename: string = '/static/js/bundle.js'
45-
) {
42+
export function listenToRuntimeErrors(crash: ErrorRecord => void) {
4643
function crashWithFrames(error: Error, unhandledRejection = false) {
4744
getStackFrames(error, unhandledRejection, CONTEXT_SIZE)
4845
.then(stackFrames => {
@@ -71,7 +68,7 @@ export function listenToRuntimeErrors(
7168
{
7269
message: data.message,
7370
stack: data.stack,
74-
__unmap_source: filename,
71+
__unmap_source: '/static/js/bundle.js',
7572
},
7673
false
7774
);

packages/react-error-overlay/src/utils/getSourceMap.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class SourceMap {
7777
}
7878
}
7979

80-
function extractSourceMapUrl(fileUri: string, fileContents: string) {
80+
function extractSourceMapUrl(fileUri: string, fileContents: string) : Promise<string> {
8181
const regex = /\/\/[#@] ?sourceMappingURL=([^\s'"]+)\s*$/gm;
8282
let match = null;
8383
for (;;) {

0 commit comments

Comments
 (0)