2016-10-30 07:43:34 +08:00
|
|
|
/**
|
2017-09-25 04:48:13 +08:00
|
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
2016-10-30 07:43:34 +08:00
|
|
|
*
|
2017-09-25 04:48:13 +08:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-10-30 07:43:34 +08:00
|
|
|
*
|
2017-04-05 23:47:29 +08:00
|
|
|
* @flow
|
2016-10-30 07:43:34 +08:00
|
|
|
*/
|
|
|
|
|
|
2017-10-25 07:55:00 +08:00
|
|
|
import type {Fiber} from 'react-reconciler/src/ReactFiber';
|
2016-10-30 07:43:34 +08:00
|
|
|
|
2017-12-13 07:04:40 +08:00
|
|
|
import {
|
|
|
|
|
REACT_CALL_TYPE,
|
|
|
|
|
REACT_FRAGMENT_TYPE,
|
|
|
|
|
REACT_RETURN_TYPE,
|
|
|
|
|
REACT_PORTAL_TYPE,
|
|
|
|
|
} from 'shared/ReactSymbols';
|
|
|
|
|
|
2017-10-02 20:43:45 +08:00
|
|
|
function getComponentName(fiber: Fiber): string | null {
|
|
|
|
|
const {type} = fiber;
|
2017-12-13 07:04:40 +08:00
|
|
|
if (typeof type === 'function') {
|
|
|
|
|
return type.displayName || type.name;
|
|
|
|
|
}
|
2017-10-02 20:43:45 +08:00
|
|
|
if (typeof type === 'string') {
|
|
|
|
|
return type;
|
2017-01-24 09:11:10 +08:00
|
|
|
}
|
2017-12-13 07:04:40 +08:00
|
|
|
switch (type) {
|
|
|
|
|
case REACT_FRAGMENT_TYPE:
|
|
|
|
|
return 'ReactFragment';
|
|
|
|
|
case REACT_PORTAL_TYPE:
|
|
|
|
|
return 'ReactPortal';
|
|
|
|
|
case REACT_CALL_TYPE:
|
|
|
|
|
return 'ReactCall';
|
|
|
|
|
case REACT_RETURN_TYPE:
|
|
|
|
|
return 'ReactReturn';
|
2016-10-30 07:43:34 +08:00
|
|
|
}
|
2017-01-25 22:49:19 +08:00
|
|
|
return null;
|
2016-10-30 07:43:34 +08:00
|
|
|
}
|
|
|
|
|
|
2017-11-03 03:50:03 +08:00
|
|
|
export default getComponentName;
|