@@ -20,6 +20,12 @@ var warning = require('warning');
20
20
import type { ReactElement , Source } from 'ReactElementType' ;
21
21
import type { DebugID } from 'ReactInstanceType' ;
22
22
23
+ type StackFrame = {
24
+ fileName : string | null ,
25
+ lineNumber : number | null ,
26
+ functionName : string | null ,
27
+ } ;
28
+
23
29
function isNative ( fn ) {
24
30
// Based on isNative() from Lodash
25
31
var funcToString = Function . prototype . toString ;
@@ -402,6 +408,46 @@ var ReactComponentTreeHook = {
402
408
403
409
getRootIDs ,
404
410
getRegisteredIDs : getItemIDs ,
411
+
412
+ pushNonStandardWarningStack ( extraFrame : StackFrame | null ) {
413
+ if ( typeof console . stack !== 'function' ) {
414
+ return ;
415
+ }
416
+
417
+ var stack = [ ] ;
418
+ if ( extraFrame ) {
419
+ stack . push ( extraFrame ) ;
420
+ }
421
+
422
+ var currentOwner = ReactCurrentOwner . current ;
423
+ var id = currentOwner && currentOwner . _debugID ;
424
+
425
+ try {
426
+ while ( id ) {
427
+ var name = ReactComponentTreeHook . getDisplayName ( id ) ;
428
+ var element = ReactComponentTreeHook . getElement ( id ) ;
429
+ var source = element && element . _source ;
430
+ stack . push ( {
431
+ fileName : source ? source . fileName : null ,
432
+ lineNumber : source ? source . lineNumber : null ,
433
+ functionName : name ,
434
+ } ) ;
435
+ id = ReactComponentTreeHook . getParentID ( id ) ;
436
+ }
437
+ } catch ( err ) {
438
+ // Internal state is messed up.
439
+ // Stop building the stack (it's just a nice to have).
440
+ }
441
+
442
+ console . stack ( stack ) ;
443
+ } ,
444
+
445
+ popNonStandardWarningStack ( ) {
446
+ if ( typeof console . stackEnd !== 'function' ) {
447
+ return ;
448
+ }
449
+ console . stackEnd ( ) ;
450
+ } ,
405
451
} ;
406
452
407
453
module . exports = ReactComponentTreeHook ;
0 commit comments