@@ -13,6 +13,8 @@ import CodeBlock from './StackFrameCodeBlock';
13
13
import { getPrettyURL } from '../utils/getPrettyURL' ;
14
14
import { darkGray } from '../styles' ;
15
15
16
+ import type { StackFrame as StackFrameType } from '../utils/stack-frame' ;
17
+
16
18
const linkStyle = {
17
19
fontSize : '0.9em' ,
18
20
marginBottom : '0.9em' ,
@@ -43,7 +45,19 @@ const toggleStyle = {
43
45
lineHeight : '1.5' ,
44
46
} ;
45
47
46
- class StackFrame extends Component {
48
+ type Props = { |
49
+ frame : StackFrameType ,
50
+ launchEditorEndpoint : ?string ,
51
+ contextSize : number ,
52
+ critical : boolean ,
53
+ showCode : boolean ,
54
+ | } ;
55
+
56
+ type State = { |
57
+ compiled : boolean ,
58
+ | } ;
59
+
60
+ class StackFrame extends Component < Props , State > {
47
61
state = {
48
62
compiled : false ,
49
63
} ;
@@ -54,43 +68,45 @@ class StackFrame extends Component {
54
68
} ) ) ;
55
69
} ;
56
70
57
- canOpenInEditor ( ) {
71
+ getEndpointUrl ( ) : string | null {
58
72
if ( ! this . props . launchEditorEndpoint ) {
59
- return ;
73
+ return null ;
60
74
}
61
75
const { _originalFileName : sourceFileName } = this . props . frame ;
62
76
// Unknown file
63
77
if ( ! sourceFileName ) {
64
- return false ;
78
+ return null ;
65
79
}
66
80
// e.g. "/path-to-my-app/webpack/bootstrap eaddeb46b67d75e4dfc1"
67
81
const isInternalWebpackBootstrapCode =
68
82
sourceFileName . trim ( ) . indexOf ( ' ' ) !== - 1 ;
69
83
if ( isInternalWebpackBootstrapCode ) {
70
- return false ;
84
+ return null ;
71
85
}
72
86
// Code is in a real file
73
- return true ;
87
+ return this . props . launchEditorEndpoint || null ;
74
88
}
75
89
76
90
openInEditor = ( ) => {
77
- if ( ! this . canOpenInEditor ( ) ) {
91
+ const endpointUrl = this . getEndpointUrl ( ) ;
92
+ if ( endpointUrl === null ) {
78
93
return ;
79
94
}
95
+
80
96
const {
81
97
_originalFileName : sourceFileName ,
82
98
_originalLineNumber : sourceLineNumber ,
83
99
} = this . props . frame ;
84
100
// Keep this in sync with react-error-overlay/middleware.js
85
101
fetch (
86
- `${ this . props . launchEditorEndpoint } ?fileName=` +
102
+ `${ endpointUrl } ?fileName=` +
87
103
window . encodeURIComponent ( sourceFileName ) +
88
104
'&lineNumber=' +
89
105
window . encodeURIComponent ( sourceLineNumber || 1 )
90
106
) . then ( ( ) => { } , ( ) => { } ) ;
91
107
} ;
92
108
93
- onKeyDown = ( e : SyntheticKeyboardEvent ) => {
109
+ onKeyDown = ( e : SyntheticKeyboardEvent < > ) => {
94
110
if ( e . key === 'Enter' ) {
95
111
this . openInEditor ( ) ;
96
112
}
@@ -152,7 +168,7 @@ class StackFrame extends Component {
152
168
}
153
169
}
154
170
155
- const canOpenInEditor = this . canOpenInEditor ( ) ;
171
+ const canOpenInEditor = this . getEndpointUrl ( ) !== null ;
156
172
return (
157
173
< div >
158
174
< div > { functionName } </ div >
0 commit comments