2018-03-30 02:45:41 +08:00
|
|
|
/**
|
2018-09-08 06:11:23 +08:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2018-03-30 02:45:41 +08:00
|
|
|
*
|
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
|
*
|
|
|
|
|
* @flow
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
REACT_CONTEXT_TYPE,
|
|
|
|
|
REACT_FORWARD_REF_TYPE,
|
2018-05-11 06:25:32 +08:00
|
|
|
REACT_FRAGMENT_TYPE,
|
|
|
|
|
REACT_PROFILER_TYPE,
|
|
|
|
|
REACT_PROVIDER_TYPE,
|
2020-04-16 10:10:15 +08:00
|
|
|
REACT_DEBUG_TRACING_MODE_TYPE,
|
2018-05-11 06:25:32 +08:00
|
|
|
REACT_STRICT_MODE_TYPE,
|
2018-10-11 00:02:04 +08:00
|
|
|
REACT_SUSPENSE_TYPE,
|
2019-06-20 10:34:28 +08:00
|
|
|
REACT_SUSPENSE_LIST_TYPE,
|
2018-10-21 00:46:23 +08:00
|
|
|
REACT_MEMO_TYPE,
|
2018-10-19 10:57:12 +08:00
|
|
|
REACT_LAZY_TYPE,
|
2019-07-20 05:20:28 +08:00
|
|
|
REACT_FUNDAMENTAL_TYPE,
|
2019-08-29 19:06:51 +08:00
|
|
|
REACT_SCOPE_TYPE,
|
2020-02-21 15:56:40 +08:00
|
|
|
REACT_BLOCK_TYPE,
|
2020-03-24 08:53:45 +08:00
|
|
|
REACT_SERVER_BLOCK_TYPE,
|
2020-05-12 11:02:08 +08:00
|
|
|
REACT_LEGACY_HIDDEN_TYPE,
|
2018-03-30 02:45:41 +08:00
|
|
|
} from 'shared/ReactSymbols';
|
2020-07-16 23:21:21 +08:00
|
|
|
import {enableScopeAPI} from './ReactFeatureFlags';
|
2018-03-30 02:45:41 +08:00
|
|
|
|
|
|
|
|
export default function isValidElementType(type: mixed) {
|
2020-07-09 02:25:24 +08:00
|
|
|
if (typeof type === 'string' || typeof type === 'function') {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Note: typeof might be other than 'symbol' or 'number' (e.g. if it's a polyfill).
|
|
|
|
|
if (
|
2018-03-30 02:45:41 +08:00
|
|
|
type === REACT_FRAGMENT_TYPE ||
|
2018-05-11 06:25:32 +08:00
|
|
|
type === REACT_PROFILER_TYPE ||
|
2020-04-16 10:10:15 +08:00
|
|
|
type === REACT_DEBUG_TRACING_MODE_TYPE ||
|
2018-03-30 02:45:41 +08:00
|
|
|
type === REACT_STRICT_MODE_TYPE ||
|
2018-10-11 00:02:04 +08:00
|
|
|
type === REACT_SUSPENSE_TYPE ||
|
2019-06-20 10:34:28 +08:00
|
|
|
type === REACT_SUSPENSE_LIST_TYPE ||
|
2020-07-16 23:21:21 +08:00
|
|
|
type === REACT_LEGACY_HIDDEN_TYPE ||
|
|
|
|
|
(enableScopeAPI && type === REACT_SCOPE_TYPE)
|
2020-07-09 02:25:24 +08:00
|
|
|
) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof type === 'object' && type !== null) {
|
|
|
|
|
if (
|
|
|
|
|
type.$$typeof === REACT_LAZY_TYPE ||
|
|
|
|
|
type.$$typeof === REACT_MEMO_TYPE ||
|
|
|
|
|
type.$$typeof === REACT_PROVIDER_TYPE ||
|
|
|
|
|
type.$$typeof === REACT_CONTEXT_TYPE ||
|
|
|
|
|
type.$$typeof === REACT_FORWARD_REF_TYPE ||
|
|
|
|
|
type.$$typeof === REACT_FUNDAMENTAL_TYPE ||
|
|
|
|
|
type.$$typeof === REACT_BLOCK_TYPE ||
|
|
|
|
|
type[(0: any)] === REACT_SERVER_BLOCK_TYPE
|
|
|
|
|
) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2018-03-30 02:45:41 +08:00
|
|
|
}
|