60 lines
1.5 KiB
JavaScript
60 lines
1.5 KiB
JavaScript
/**
|
|
* Copyright (c) 2016-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
import type {Fiber} from 'react-reconciler/src/ReactFiber';
|
|
|
|
var ReactTypeOfWork = require('./ReactTypeOfWork');
|
|
var {
|
|
IndeterminateComponent,
|
|
FunctionalComponent,
|
|
ClassComponent,
|
|
HostComponent,
|
|
} = ReactTypeOfWork;
|
|
var describeComponentFrame = require('./describeComponentFrame');
|
|
var getComponentName = require('./getComponentName');
|
|
|
|
function describeFiber(fiber: Fiber): string {
|
|
switch (fiber.tag) {
|
|
case IndeterminateComponent:
|
|
case FunctionalComponent:
|
|
case ClassComponent:
|
|
case HostComponent:
|
|
var owner = fiber._debugOwner;
|
|
var source = fiber._debugSource;
|
|
var name = getComponentName(fiber);
|
|
var ownerName = null;
|
|
if (owner) {
|
|
ownerName = getComponentName(owner);
|
|
}
|
|
return describeComponentFrame(name, source, ownerName);
|
|
default:
|
|
return '';
|
|
}
|
|
}
|
|
|
|
// This function can only be called with a work-in-progress fiber and
|
|
// only during begin or complete phase. Do not call it under any other
|
|
// circumstances.
|
|
function getStackAddendumByWorkInProgressFiber(workInProgress: Fiber): string {
|
|
var info = '';
|
|
var node = workInProgress;
|
|
do {
|
|
info += describeFiber(node);
|
|
// Otherwise this return pointer might point to the wrong tree:
|
|
node = node.return;
|
|
} while (node);
|
|
return info;
|
|
}
|
|
|
|
module.exports = {
|
|
getStackAddendumByWorkInProgressFiber,
|
|
};
|