1313'use strict' ;
1414
1515var ReactCurrentOwner = require ( 'ReactCurrentOwner' ) ;
16- var ReactTypeOfWork = require ( 'ReactTypeOfWork' ) ;
1716var {
18- IndeterminateComponent,
19- FunctionalComponent,
20- ClassComponent,
21- HostComponent,
22- } = ReactTypeOfWork ;
23-
24- var getComponentName = require ( 'getComponentName' ) ;
17+ getStackAddendumByWorkInProgressFiber,
18+ describeComponentFrame,
19+ } = require ( 'ReactFiberComponentTreeHook' ) ;
2520var invariant = require ( 'fbjs/lib/invariant' ) ;
2621var warning = require ( 'fbjs/lib/warning' ) ;
22+ var getComponentName = require ( 'getComponentName' ) ;
2723
2824import type { ReactElement , Source } from 'ReactElementType' ;
2925import type { DebugID } from 'ReactInstanceType' ;
@@ -159,17 +155,6 @@ function purgeDeep(id) {
159155 }
160156}
161157
162- function describeComponentFrame ( name , source , ownerName ) {
163- return '\n in ' + ( name || 'Unknown' ) + (
164- source ?
165- ' (at ' + source . fileName . replace ( / ^ .* [ \\ \/ ] / , '' ) + ':' +
166- source . lineNumber + ')' :
167- ownerName ?
168- ' (created by ' + ownerName + ')' :
169- ''
170- ) ;
171- }
172-
173158function getDisplayName ( element : ?ReactElement ) : string {
174159 if ( element == null ) {
175160 return '#empty' ;
@@ -183,10 +168,11 @@ function getDisplayName(element: ?ReactElement): string {
183168}
184169
185170function describeID ( id : DebugID ) : string {
186- var name = ReactComponentTreeHook . getDisplayName ( id ) ;
187- var element = ReactComponentTreeHook . getElement ( id ) ;
188- var ownerID = ReactComponentTreeHook . getOwnerID ( id ) ;
189- var ownerName ;
171+ const name = ReactComponentTreeHook . getDisplayName ( id ) ;
172+ const element = ReactComponentTreeHook . getElement ( id ) ;
173+ const ownerID = ReactComponentTreeHook . getOwnerID ( id ) ;
174+ let ownerName ;
175+
190176 if ( ownerID ) {
191177 ownerName = ReactComponentTreeHook . getDisplayName ( ownerID ) ;
192178 }
@@ -196,26 +182,7 @@ function describeID(id: DebugID): string {
196182 'building stack' ,
197183 id
198184 ) ;
199- return describeComponentFrame ( name , element && element . _source , ownerName ) ;
200- }
201-
202- function describeFiber ( fiber : Fiber ) : string {
203- switch ( fiber . tag ) {
204- case IndeterminateComponent :
205- case FunctionalComponent :
206- case ClassComponent :
207- case HostComponent :
208- var owner = fiber . _debugOwner ;
209- var source = fiber . _debugSource ;
210- var name = getComponentName ( fiber ) ;
211- var ownerName = null ;
212- if ( owner ) {
213- ownerName = getComponentName ( owner ) ;
214- }
215- return describeComponentFrame ( name , source , ownerName ) ;
216- default :
217- return '' ;
218- }
185+ return describeComponentFrame ( name || '' , element && element . _source , ownerName || '' ) ;
219186}
220187
221188var ReactComponentTreeHook = {
@@ -356,7 +323,7 @@ var ReactComponentTreeHook = {
356323 const workInProgress = ( ( currentOwner : any ) : Fiber ) ;
357324 // Safe because if current owner exists, we are reconciling,
358325 // and it is guaranteed to be the work-in-progress version.
359- info += ReactComponentTreeHook . getStackAddendumByWorkInProgressFiber ( workInProgress ) ;
326+ info += getStackAddendumByWorkInProgressFiber ( workInProgress ) ;
360327 } else if ( typeof currentOwner . _debugID === 'number' ) {
361328 info += ReactComponentTreeHook . getStackAddendumByID ( currentOwner . _debugID ) ;
362329 }
@@ -373,20 +340,6 @@ var ReactComponentTreeHook = {
373340 return info ;
374341 } ,
375342
376- // This function can only be called with a work-in-progress fiber and
377- // only during begin or complete phase. Do not call it under any other
378- // circumstances.
379- getStackAddendumByWorkInProgressFiber ( workInProgress : Fiber ) : string {
380- var info = '' ;
381- var node = workInProgress ;
382- do {
383- info += describeFiber ( node ) ;
384- // Otherwise this return pointer might point to the wrong tree:
385- node = node . return ;
386- } while ( node ) ;
387- return info ;
388- } ,
389-
390343 getChildIDs ( id : DebugID ) : Array < DebugID > {
391344 var item = getItem ( id ) ;
392345 return item ? item . childIDs : [ ] ;
0 commit comments