@@ -26,39 +26,45 @@ export type { ReactFrame };
26
26
/// TODO: a more comprehensive implementation.
27
27
28
28
const registerReactStack = ( ) => {
29
- // $FlowFixMe
30
- console . reactStack = frames => reactFrameStack . push ( frames ) ;
31
- // $FlowFixMe
32
- console . reactStackEnd = frames => reactFrameStack . pop ( ) ;
29
+ if ( typeof console !== 'undefined' ) {
30
+ // $FlowFixMe
31
+ console . reactStack = frames => reactFrameStack . push ( frames ) ;
32
+ // $FlowFixMe
33
+ console . reactStackEnd = frames => reactFrameStack . pop ( ) ;
34
+ }
33
35
} ;
34
36
35
37
const unregisterReactStack = ( ) => {
36
- // $FlowFixMe
37
- console . reactStack = undefined ;
38
- // $FlowFixMe
39
- console . reactStackEnd = undefined ;
38
+ if ( typeof console !== 'undefined' ) {
39
+ // $FlowFixMe
40
+ console . reactStack = undefined ;
41
+ // $FlowFixMe
42
+ console . reactStackEnd = undefined ;
43
+ }
40
44
} ;
41
45
42
46
type ConsoleProxyCallback = ( message : string , frames : ReactFrame [ ] ) => void ;
43
47
const permanentRegister = function proxyConsole (
44
48
type : string ,
45
49
callback : ConsoleProxyCallback
46
50
) {
47
- const orig = console [ type ] ;
48
- console [ type ] = function __stack_frame_overlay_proxy_console__ ( ) {
49
- try {
50
- const message = arguments [ 0 ] ;
51
- if ( typeof message === 'string' && reactFrameStack . length > 0 ) {
52
- callback ( message , reactFrameStack [ reactFrameStack . length - 1 ] ) ;
51
+ if ( typeof console !== 'undefined' ) {
52
+ const orig = console [ type ] ;
53
+ console [ type ] = function __stack_frame_overlay_proxy_console__ ( ) {
54
+ try {
55
+ const message = arguments [ 0 ] ;
56
+ if ( typeof message === 'string' && reactFrameStack . length > 0 ) {
57
+ callback ( message , reactFrameStack [ reactFrameStack . length - 1 ] ) ;
58
+ }
59
+ } catch ( err ) {
60
+ // Warnings must never crash. Rethrow with a clean stack.
61
+ setTimeout ( function ( ) {
62
+ throw err ;
63
+ } ) ;
53
64
}
54
- } catch ( err ) {
55
- // Warnings must never crash. Rethrow with a clean stack.
56
- setTimeout ( function ( ) {
57
- throw err ;
58
- } ) ;
59
- }
60
- return orig . apply ( this , arguments ) ;
61
- } ;
65
+ return orig . apply ( this , arguments ) ;
66
+ } ;
67
+ }
62
68
} ;
63
69
64
70
export { permanentRegister , registerReactStack , unregisterReactStack } ;
0 commit comments