@@ -26,39 +26,45 @@ export type { ReactFrame };
2626/// TODO: a more comprehensive implementation.
2727
2828const 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+ }
3335} ;
3436
3537const 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+ }
4044} ;
4145
4246type ConsoleProxyCallback = ( message : string , frames : ReactFrame [ ] ) => void ;
4347const permanentRegister = function proxyConsole (
4448 type : string ,
4549 callback : ConsoleProxyCallback
4650) {
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+ } ) ;
5364 }
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+ }
6268} ;
6369
6470export { permanentRegister , registerReactStack , unregisterReactStack } ;
0 commit comments