straightford explicit types (#25253)

This commit is contained in:
Jan Kassens
2022-09-13 17:57:38 -04:00
committed by GitHub
parent b96883c3c6
commit dd23ef3d09
52 changed files with 175 additions and 139 deletions
+1 -1
View File
@@ -783,7 +783,7 @@ export function inspectHooksOfFiber(
fiber: Fiber,
currentDispatcher: ?CurrentDispatcherRef,
includeHooksSource?: boolean = false,
) {
): HooksTree {
// DevTools will pass the current renderer's injected dispatcher.
// Other apps might compile debug hooks as part of their app though.
if (currentDispatcher == null) {
+5 -3
View File
@@ -680,7 +680,7 @@ export function clearContainer(container: Container): void {
export const supportsHydration = true;
export function isHydratableResource(type: string, props: Props) {
export function isHydratableResource(type: string, props: Props): boolean {
return (
type === 'link' &&
typeof (props: any).precedence === 'string' &&
@@ -726,11 +726,13 @@ export function canHydrateSuspenseInstance(
return ((instance: any): SuspenseInstance);
}
export function isSuspenseInstancePending(instance: SuspenseInstance) {
export function isSuspenseInstancePending(instance: SuspenseInstance): boolean {
return instance.data === SUSPENSE_PENDING_START_DATA;
}
export function isSuspenseInstanceFallback(instance: SuspenseInstance) {
export function isSuspenseInstanceFallback(
instance: SuspenseInstance,
): boolean {
return instance.data === SUSPENSE_FALLBACK_START_DATA;
}
+1 -1
View File
@@ -123,7 +123,7 @@ export function track(node: ElementWithValueTracker) {
node._valueTracker = trackValueOnNode(node);
}
export function updateValueIfChanged(node: ElementWithValueTracker) {
export function updateValueIfChanged(node: ElementWithValueTracker): boolean {
if (!node) {
return false;
}
+1 -1
View File
@@ -9,7 +9,7 @@
import {canUseDOM} from 'shared/ExecutionEnvironment';
export let passiveBrowserEventsSupported = false;
export let passiveBrowserEventsSupported: boolean = false;
// Check if browser support events with passive listeners
// https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support
+2 -2
View File
@@ -63,10 +63,10 @@ export type PropertyInfo = {
export const ATTRIBUTE_NAME_START_CHAR =
':A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD';
/* eslint-enable max-len */
export const ATTRIBUTE_NAME_CHAR =
export const ATTRIBUTE_NAME_CHAR: string =
ATTRIBUTE_NAME_START_CHAR + '\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040';
export const VALID_ATTRIBUTE_NAME_REGEX = new RegExp(
export const VALID_ATTRIBUTE_NAME_REGEX: RegExp = new RegExp(
'^[' + ATTRIBUTE_NAME_START_CHAR + '][' + ATTRIBUTE_NAME_CHAR + ']*$',
);
+1 -1
View File
@@ -7,7 +7,7 @@
* @flow
*/
function isCustomComponent(tagName: string, props: Object) {
function isCustomComponent(tagName: string, props: Object): boolean {
if (tagName.indexOf('-') === -1) {
return typeof props.is === 'string';
}
+14 -14
View File
@@ -82,7 +82,7 @@ let hasWarnedAboutDeprecatedIsAsyncMode = false;
let hasWarnedAboutDeprecatedIsConcurrentMode = false;
// AsyncMode should be deprecated
export function isAsyncMode(object: any) {
export function isAsyncMode(object: any): boolean {
if (__DEV__) {
if (!hasWarnedAboutDeprecatedIsAsyncMode) {
hasWarnedAboutDeprecatedIsAsyncMode = true;
@@ -95,7 +95,7 @@ export function isAsyncMode(object: any) {
}
return false;
}
export function isConcurrentMode(object: any) {
export function isConcurrentMode(object: any): boolean {
if (__DEV__) {
if (!hasWarnedAboutDeprecatedIsConcurrentMode) {
hasWarnedAboutDeprecatedIsConcurrentMode = true;
@@ -108,43 +108,43 @@ export function isConcurrentMode(object: any) {
}
return false;
}
export function isContextConsumer(object: any) {
export function isContextConsumer(object: any): boolean {
return typeOf(object) === REACT_CONTEXT_TYPE;
}
export function isContextProvider(object: any) {
export function isContextProvider(object: any): boolean {
return typeOf(object) === REACT_PROVIDER_TYPE;
}
export function isElement(object: any) {
export function isElement(object: any): boolean {
return (
typeof object === 'object' &&
object !== null &&
object.$$typeof === REACT_ELEMENT_TYPE
);
}
export function isForwardRef(object: any) {
export function isForwardRef(object: any): boolean {
return typeOf(object) === REACT_FORWARD_REF_TYPE;
}
export function isFragment(object: any) {
export function isFragment(object: any): boolean {
return typeOf(object) === REACT_FRAGMENT_TYPE;
}
export function isLazy(object: any) {
export function isLazy(object: any): boolean {
return typeOf(object) === REACT_LAZY_TYPE;
}
export function isMemo(object: any) {
export function isMemo(object: any): boolean {
return typeOf(object) === REACT_MEMO_TYPE;
}
export function isPortal(object: any) {
export function isPortal(object: any): boolean {
return typeOf(object) === REACT_PORTAL_TYPE;
}
export function isProfiler(object: any) {
export function isProfiler(object: any): boolean {
return typeOf(object) === REACT_PROFILER_TYPE;
}
export function isStrictMode(object: any) {
export function isStrictMode(object: any): boolean {
return typeOf(object) === REACT_STRICT_MODE_TYPE;
}
export function isSuspense(object: any) {
export function isSuspense(object: any): boolean {
return typeOf(object) === REACT_SUSPENSE_TYPE;
}
export function isSuspenseList(object: any) {
export function isSuspenseList(object: any): boolean {
return typeOf(object) === REACT_SUSPENSE_LIST_TYPE;
}
+1 -1
View File
@@ -73,7 +73,7 @@ export function setIsRendering(rendering: boolean) {
}
}
export function getIsRendering() {
export function getIsRendering(): void | boolean {
if (__DEV__) {
return isRendering;
}
+1 -1
View File
@@ -58,7 +58,7 @@ export function getCurrentUpdatePriority(): EventPriority {
: (getCurrentUpdatePriority_old(): any);
}
export function setCurrentUpdatePriority(priority: EventPriority) {
export function setCurrentUpdatePriority(priority: EventPriority): void {
return enableNewReconciler
? setCurrentUpdatePriority_new((priority: any))
: setCurrentUpdatePriority_old((priority: any));
@@ -225,7 +225,7 @@ function shouldConstruct(Component: Function) {
return !!(prototype && prototype.isReactComponent);
}
export function isSimpleFunctionComponent(type: any) {
export function isSimpleFunctionComponent(type: any): boolean {
return (
typeof type === 'function' &&
!shouldConstruct(type) &&
@@ -355,7 +355,10 @@ export function createWorkInProgress(current: Fiber, pendingProps: any): Fiber {
}
// Used to reuse a Fiber for a second pass.
export function resetWorkInProgress(workInProgress: Fiber, renderLanes: Lanes) {
export function resetWorkInProgress(
workInProgress: Fiber,
renderLanes: Lanes,
): Fiber {
// This resets the Fiber to what createFiber or createWorkInProgress would
// have set the values to before during the first pass. Ideally this wouldn't
// be necessary but unfortunately many code paths reads from the workInProgress
@@ -225,7 +225,7 @@ function shouldConstruct(Component: Function) {
return !!(prototype && prototype.isReactComponent);
}
export function isSimpleFunctionComponent(type: any) {
export function isSimpleFunctionComponent(type: any): boolean {
return (
typeof type === 'function' &&
!shouldConstruct(type) &&
@@ -355,7 +355,10 @@ export function createWorkInProgress(current: Fiber, pendingProps: any): Fiber {
}
// Used to reuse a Fiber for a second pass.
export function resetWorkInProgress(workInProgress: Fiber, renderLanes: Lanes) {
export function resetWorkInProgress(
workInProgress: Fiber,
renderLanes: Lanes,
): Fiber {
// This resets the Fiber to what createFiber or createWorkInProgress would
// have set the values to before during the first pass. Ideally this wouldn't
// be necessary but unfortunately many code paths reads from the workInProgress
@@ -15,7 +15,7 @@ import {warnsIfNotActing} from './ReactFiberHostConfig';
const {ReactCurrentActQueue} = ReactSharedInternals;
export function isLegacyActEnvironment(fiber: Fiber) {
export function isLegacyActEnvironment(fiber: Fiber): boolean {
if (__DEV__) {
// Legacy mode. We preserve the behavior of React 17's act. It assumes an
// act environment whenever `jest` is defined, but you can still turn off
@@ -15,7 +15,7 @@ import {warnsIfNotActing} from './ReactFiberHostConfig';
const {ReactCurrentActQueue} = ReactSharedInternals;
export function isLegacyActEnvironment(fiber: Fiber) {
export function isLegacyActEnvironment(fiber: Fiber): boolean {
if (__DEV__) {
// Legacy mode. We preserve the behavior of React 17's act. It assumes an
// act environment whenever `jest` is defined, but you can still turn off
@@ -281,7 +281,7 @@ let didWarnAboutModulePatternComponent;
let didWarnAboutContextTypeOnFunctionComponent;
let didWarnAboutGetDerivedStateOnFunctionComponent;
let didWarnAboutFunctionRefs;
export let didWarnAboutReassigningProps;
export let didWarnAboutReassigningProps: boolean;
let didWarnAboutRevealOrder;
let didWarnAboutTailOptions;
let didWarnAboutDefaultPropsOnFunctionComponent;
@@ -3479,7 +3479,7 @@ export function markWorkInProgressReceivedUpdate() {
didReceiveUpdate = true;
}
export function checkIfWorkInProgressReceivedUpdate() {
export function checkIfWorkInProgressReceivedUpdate(): boolean {
return didReceiveUpdate;
}
@@ -281,7 +281,7 @@ let didWarnAboutModulePatternComponent;
let didWarnAboutContextTypeOnFunctionComponent;
let didWarnAboutGetDerivedStateOnFunctionComponent;
let didWarnAboutFunctionRefs;
export let didWarnAboutReassigningProps;
export let didWarnAboutReassigningProps: boolean;
let didWarnAboutRevealOrder;
let didWarnAboutTailOptions;
let didWarnAboutDefaultPropsOnFunctionComponent;
@@ -3479,7 +3479,7 @@ export function markWorkInProgressReceivedUpdate() {
didReceiveUpdate = true;
}
export function checkIfWorkInProgressReceivedUpdate() {
export function checkIfWorkInProgressReceivedUpdate(): boolean {
return didReceiveUpdate;
}
@@ -164,7 +164,7 @@ let hasForceUpdate = false;
let didWarnUpdateInsideUpdate;
let currentlyProcessingQueue;
export let resetCurrentlyProcessingQueue;
export let resetCurrentlyProcessingQueue: () => void;
if (__DEV__) {
didWarnUpdateInsideUpdate = false;
currentlyProcessingQueue = null;
@@ -164,7 +164,7 @@ let hasForceUpdate = false;
let didWarnUpdateInsideUpdate;
let currentlyProcessingQueue;
export let resetCurrentlyProcessingQueue;
export let resetCurrentlyProcessingQueue: () => void;
if (__DEV__) {
didWarnUpdateInsideUpdate = false;
currentlyProcessingQueue = null;
@@ -320,7 +320,7 @@ let shouldFireAfterActiveInstanceBlur: boolean = false;
export function commitBeforeMutationEffects(
root: FiberRoot,
firstChild: Fiber,
) {
): boolean {
focusedInstanceHandle = prepareForCommit(root.containerInfo);
nextEffect = firstChild;
@@ -320,7 +320,7 @@ let shouldFireAfterActiveInstanceBlur: boolean = false;
export function commitBeforeMutationEffects(
root: FiberRoot,
firstChild: Fiber,
) {
): boolean {
focusedInstanceHandle = prepareForCommit(root.containerInfo);
nextEffect = firstChild;
@@ -66,6 +66,6 @@ export function popHiddenContext(fiber: Fiber): void {
pop(prevRenderLanesStackCursor, fiber);
}
export function isCurrentTreeHidden() {
export function isCurrentTreeHidden(): boolean {
return currentTreeHiddenStackCursor.current !== null;
}
@@ -66,6 +66,6 @@ export function popHiddenContext(fiber: Fiber): void {
pop(prevRenderLanesStackCursor, fiber);
}
export function isCurrentTreeHidden() {
export function isCurrentTreeHidden(): boolean {
return currentTreeHiddenStackCursor.current !== null;
}
@@ -571,7 +571,7 @@ export function renderWithHooks<Props, SecondArg>(
return children;
}
export function checkDidRenderIdHook() {
export function checkDidRenderIdHook(): boolean {
// This should be called immediately after every renderWithHooks call.
// Conceptually, it's part of the return value of renderWithHooks; it's only a
// separate function to avoid using an array tuple.
@@ -571,7 +571,7 @@ export function renderWithHooks<Props, SecondArg>(
return children;
}
export function checkDidRenderIdHook() {
export function checkDidRenderIdHook(): boolean {
// This should be called immediately after every renderWithHooks call.
// Conceptually, it's part of the return value of renderWithHooks; it's only a
// separate function to avoid using an array tuple.
+15 -8
View File
@@ -7,6 +7,8 @@
* @flow
*/
import type {Fiber} from './ReactInternalTypes';
import type {ReactElement} from '../../shared/ReactElementType';
import type {Instance} from './ReactFiberHostConfig';
import type {FiberRoot} from './ReactInternalTypes';
import type {ReactNodeList} from 'shared/ReactTypes';
@@ -58,9 +60,9 @@ export type FindHostInstancesForRefresh = (
families: Array<Family>,
) => Set<Instance>;
export const setRefreshHandler = enableNewReconciler
? setRefreshHandler_new
: setRefreshHandler_old;
export const setRefreshHandler: (
handler: RefreshHandler | null,
) => void = enableNewReconciler ? setRefreshHandler_new : setRefreshHandler_old;
export const resolveFunctionForHotReloading = enableNewReconciler
? resolveFunctionForHotReloading_new
: resolveFunctionForHotReloading_old;
@@ -70,18 +72,23 @@ export const resolveClassForHotReloading = enableNewReconciler
export const resolveForwardRefForHotReloading = enableNewReconciler
? resolveForwardRefForHotReloading_new
: resolveForwardRefForHotReloading_old;
export const isCompatibleFamilyForHotReloading = enableNewReconciler
export const isCompatibleFamilyForHotReloading: (
fiber: Fiber,
element: ReactElement,
) => boolean = enableNewReconciler
? isCompatibleFamilyForHotReloading_new
: isCompatibleFamilyForHotReloading_old;
export const markFailedErrorBoundaryForHotReloading = enableNewReconciler
export const markFailedErrorBoundaryForHotReloading: (
fiber: Fiber,
) => void = enableNewReconciler
? markFailedErrorBoundaryForHotReloading_new
: markFailedErrorBoundaryForHotReloading_old;
export const scheduleRefresh = enableNewReconciler
export const scheduleRefresh: ScheduleRefresh = enableNewReconciler
? scheduleRefresh_new
: scheduleRefresh_old;
export const scheduleRoot = enableNewReconciler
export const scheduleRoot: ScheduleRoot = enableNewReconciler
? scheduleRoot_new
: scheduleRoot_old;
export const findHostInstancesForRefresh = enableNewReconciler
export const findHostInstancesForRefresh: FindHostInstancesForRefresh = enableNewReconciler
? findHostInstancesForRefresh_new
: findHostInstancesForRefresh_old;
@@ -109,7 +109,7 @@ export function markDidThrowWhileHydratingDEV() {
}
}
export function didSuspendOrErrorWhileHydratingDEV() {
export function didSuspendOrErrorWhileHydratingDEV(): boolean {
if (__DEV__) {
return didSuspendOrErrorDEV;
}
@@ -685,7 +685,7 @@ function popHydrationState(fiber: Fiber): boolean {
return true;
}
function hasUnhydratedTailNodes() {
function hasUnhydratedTailNodes(): boolean {
return isHydrating && nextHydratableInstance !== null;
}
@@ -109,7 +109,7 @@ export function markDidThrowWhileHydratingDEV() {
}
}
export function didSuspendOrErrorWhileHydratingDEV() {
export function didSuspendOrErrorWhileHydratingDEV(): boolean {
if (__DEV__) {
return didSuspendOrErrorDEV;
}
@@ -685,7 +685,7 @@ function popHydrationState(fiber: Fiber): boolean {
return true;
}
function hasUnhydratedTailNodes() {
function hasUnhydratedTailNodes(): boolean {
return isHydrating && nextHydratableInstance !== null;
}
@@ -435,7 +435,7 @@ export function markStarvedLanesAsExpired(
// This returns the highest priority pending lanes regardless of whether they
// are suspended.
export function getHighestPriorityPendingLanes(root: FiberRoot) {
export function getHighestPriorityPendingLanes(root: FiberRoot): Lanes {
return getHighestPriorityLanes(root.pendingLanes);
}
@@ -458,25 +458,25 @@ export function getLanesToRetrySynchronouslyOnError(
return NoLanes;
}
export function includesSyncLane(lanes: Lanes) {
export function includesSyncLane(lanes: Lanes): boolean {
return (lanes & SyncLane) !== NoLanes;
}
export function includesNonIdleWork(lanes: Lanes) {
export function includesNonIdleWork(lanes: Lanes): boolean {
return (lanes & NonIdleLanes) !== NoLanes;
}
export function includesOnlyRetries(lanes: Lanes) {
export function includesOnlyRetries(lanes: Lanes): boolean {
return (lanes & RetryLanes) === lanes;
}
export function includesOnlyNonUrgentLanes(lanes: Lanes) {
export function includesOnlyNonUrgentLanes(lanes: Lanes): boolean {
const UrgentLanes = SyncLane | InputContinuousLane | DefaultLane;
return (lanes & UrgentLanes) === NoLanes;
}
export function includesOnlyTransitions(lanes: Lanes) {
export function includesOnlyTransitions(lanes: Lanes): boolean {
return (lanes & TransitionLanes) === lanes;
}
export function includesBlockingLane(root: FiberRoot, lanes: Lanes) {
export function includesBlockingLane(root: FiberRoot, lanes: Lanes): boolean {
if (
allowConcurrentByDefault &&
(root.current.mode & ConcurrentUpdatesByDefaultMode) !== NoMode
@@ -492,13 +492,13 @@ export function includesBlockingLane(root: FiberRoot, lanes: Lanes) {
return (lanes & SyncDefaultLanes) !== NoLanes;
}
export function includesExpiredLane(root: FiberRoot, lanes: Lanes) {
export function includesExpiredLane(root: FiberRoot, lanes: Lanes): boolean {
// This is a separate check from includesBlockingLane because a lane can
// expire after a render has already started.
return (lanes & root.expiredLanes) !== NoLanes;
}
export function isTransitionLane(lane: Lane) {
export function isTransitionLane(lane: Lane): boolean {
return (lane & TransitionLanes) !== NoLanes;
}
@@ -543,11 +543,11 @@ function laneToIndex(lane: Lane) {
return pickArbitraryLaneIndex(lane);
}
export function includesSomeLane(a: Lanes | Lane, b: Lanes | Lane) {
export function includesSomeLane(a: Lanes | Lane, b: Lanes | Lane): boolean {
return (a & b) !== NoLanes;
}
export function isSubsetOfLanes(set: Lanes, subset: Lanes | Lane) {
export function isSubsetOfLanes(set: Lanes, subset: Lanes | Lane): boolean {
return (set & subset) === subset;
}
@@ -569,7 +569,7 @@ export function laneToLanes(lane: Lane): Lanes {
return lane;
}
export function higherPriorityLane(a: Lane, b: Lane) {
export function higherPriorityLane(a: Lane, b: Lane): Lane {
// This works because the bit ranges decrease in priority as you go left.
return a !== NoLane && a < b ? a : b;
}
@@ -435,7 +435,7 @@ export function markStarvedLanesAsExpired(
// This returns the highest priority pending lanes regardless of whether they
// are suspended.
export function getHighestPriorityPendingLanes(root: FiberRoot) {
export function getHighestPriorityPendingLanes(root: FiberRoot): Lanes {
return getHighestPriorityLanes(root.pendingLanes);
}
@@ -458,25 +458,25 @@ export function getLanesToRetrySynchronouslyOnError(
return NoLanes;
}
export function includesSyncLane(lanes: Lanes) {
export function includesSyncLane(lanes: Lanes): boolean {
return (lanes & SyncLane) !== NoLanes;
}
export function includesNonIdleWork(lanes: Lanes) {
export function includesNonIdleWork(lanes: Lanes): boolean {
return (lanes & NonIdleLanes) !== NoLanes;
}
export function includesOnlyRetries(lanes: Lanes) {
export function includesOnlyRetries(lanes: Lanes): boolean {
return (lanes & RetryLanes) === lanes;
}
export function includesOnlyNonUrgentLanes(lanes: Lanes) {
export function includesOnlyNonUrgentLanes(lanes: Lanes): boolean {
const UrgentLanes = SyncLane | InputContinuousLane | DefaultLane;
return (lanes & UrgentLanes) === NoLanes;
}
export function includesOnlyTransitions(lanes: Lanes) {
export function includesOnlyTransitions(lanes: Lanes): boolean {
return (lanes & TransitionLanes) === lanes;
}
export function includesBlockingLane(root: FiberRoot, lanes: Lanes) {
export function includesBlockingLane(root: FiberRoot, lanes: Lanes): boolean {
if (
allowConcurrentByDefault &&
(root.current.mode & ConcurrentUpdatesByDefaultMode) !== NoMode
@@ -492,13 +492,13 @@ export function includesBlockingLane(root: FiberRoot, lanes: Lanes) {
return (lanes & SyncDefaultLanes) !== NoLanes;
}
export function includesExpiredLane(root: FiberRoot, lanes: Lanes) {
export function includesExpiredLane(root: FiberRoot, lanes: Lanes): boolean {
// This is a separate check from includesBlockingLane because a lane can
// expire after a render has already started.
return (lanes & root.expiredLanes) !== NoLanes;
}
export function isTransitionLane(lane: Lane) {
export function isTransitionLane(lane: Lane): boolean {
return (lane & TransitionLanes) !== NoLanes;
}
@@ -543,11 +543,11 @@ function laneToIndex(lane: Lane) {
return pickArbitraryLaneIndex(lane);
}
export function includesSomeLane(a: Lanes | Lane, b: Lanes | Lane) {
export function includesSomeLane(a: Lanes | Lane, b: Lanes | Lane): boolean {
return (a & b) !== NoLanes;
}
export function isSubsetOfLanes(set: Lanes, subset: Lanes | Lane) {
export function isSubsetOfLanes(set: Lanes, subset: Lanes | Lane): boolean {
return (set & subset) === subset;
}
@@ -569,7 +569,7 @@ export function laneToLanes(lane: Lane): Lanes {
return lane;
}
export function higherPriorityLane(a: Lane, b: Lane) {
export function higherPriorityLane(a: Lane, b: Lane): Lane {
// This works because the bit ranges decrease in priority as you go left.
return a !== NoLane && a < b ? a : b;
}
@@ -598,7 +598,9 @@ function propagateParentContextChanges(
workInProgress.flags |= DidPropagateContext;
}
export function checkIfContextChanged(currentDependencies: Dependencies) {
export function checkIfContextChanged(
currentDependencies: Dependencies,
): boolean {
if (!enableLazyContextPropagation) {
return false;
}
@@ -598,7 +598,9 @@ function propagateParentContextChanges(
workInProgress.flags |= DidPropagateContext;
}
export function checkIfContextChanged(currentDependencies: Dependencies) {
export function checkIfContextChanged(
currentDependencies: Dependencies,
): boolean {
if (!enableLazyContextPropagation) {
return false;
}
+1 -1
View File
@@ -13,7 +13,7 @@ import type {RootState} from './ReactFiberRoot.new';
// This is imported by the event replaying implementation in React DOM. It's
// in a separate file to break a circular dependency between the renderer and
// the reconciler.
export function isRootDehydrated(root: FiberRoot) {
export function isRootDehydrated(root: FiberRoot): boolean {
const currentState: RootState = root.current.memoizedState;
return currentState.isDehydrated;
}
@@ -48,7 +48,7 @@ export function flushSyncCallbacksOnlyInLegacyMode() {
}
}
export function flushSyncCallbacks() {
export function flushSyncCallbacks(): null {
if (!isFlushingSyncQueue && syncQueue !== null) {
// Prevent re-entrance.
isFlushingSyncQueue = true;
@@ -48,7 +48,7 @@ export function flushSyncCallbacksOnlyInLegacyMode() {
}
}
export function flushSyncCallbacks() {
export function flushSyncCallbacks(): null {
if (!isFlushingSyncQueue && syncQueue !== null) {
// Prevent re-entrance.
isFlushingSyncQueue = true;
@@ -24,11 +24,11 @@ let lastUsedThenable: Thenable<any> | null = null;
const MAX_AD_HOC_SUSPEND_COUNT = 50;
export function isTrackingSuspendedThenable() {
export function isTrackingSuspendedThenable(): boolean {
return suspendedThenable !== null;
}
export function suspendedThenableDidResolve() {
export function suspendedThenableDidResolve(): boolean {
if (suspendedThenable !== null) {
const status = suspendedThenable.status;
return status === 'fulfilled' || status === 'rejected';
@@ -24,11 +24,11 @@ let lastUsedThenable: Thenable<any> | null = null;
const MAX_AD_HOC_SUSPEND_COUNT = 50;
export function isTrackingSuspendedThenable() {
export function isTrackingSuspendedThenable(): boolean {
return suspendedThenable !== null;
}
export function suspendedThenableDidResolve() {
export function suspendedThenableDidResolve(): boolean {
if (suspendedThenable !== null) {
const status = suspendedThenable.status;
return status === 'fulfilled' || status === 'rejected';
@@ -357,7 +357,7 @@ let workInProgressRootRenderTargetTime: number = Infinity;
const RENDER_TIMEOUT_MS = 500;
let workInProgressTransitions: Array<Transition> | null = null;
export function getWorkInProgressTransitions() {
export function getWorkInProgressTransitions(): null | Array<Transition> {
return workInProgressTransitions;
}
@@ -814,7 +814,7 @@ export function scheduleInitialHydrationOnRoot(
ensureRootIsScheduled(root, eventTime);
}
export function isUnsafeClassRenderPhaseUpdate(fiber: Fiber) {
export function isUnsafeClassRenderPhaseUpdate(fiber: Fiber): boolean {
// Check if this is a render phase update. Only called by class components,
// which special (deprecated) behavior for UNSAFE_componentWillReceive props.
return (
@@ -1557,7 +1557,7 @@ declare function flushSync<R>(fn: () => R): R;
// eslint-disable-next-line no-redeclare
declare function flushSync(): void;
// eslint-disable-next-line no-redeclare
export function flushSync(fn) {
export function flushSync(fn): void {
// In legacy mode, we flush pending passive effects at the beginning of the
// next event, not at the end of the previous one.
if (
@@ -1596,7 +1596,7 @@ export function flushSync(fn) {
}
}
export function isAlreadyRendering() {
export function isAlreadyRendering(): boolean {
// Used by the renderer to print a warning if certain APIs are called from
// the wrong context.
return (
@@ -357,7 +357,7 @@ let workInProgressRootRenderTargetTime: number = Infinity;
const RENDER_TIMEOUT_MS = 500;
let workInProgressTransitions: Array<Transition> | null = null;
export function getWorkInProgressTransitions() {
export function getWorkInProgressTransitions(): null | Array<Transition> {
return workInProgressTransitions;
}
@@ -814,7 +814,7 @@ export function scheduleInitialHydrationOnRoot(
ensureRootIsScheduled(root, eventTime);
}
export function isUnsafeClassRenderPhaseUpdate(fiber: Fiber) {
export function isUnsafeClassRenderPhaseUpdate(fiber: Fiber): boolean {
// Check if this is a render phase update. Only called by class components,
// which special (deprecated) behavior for UNSAFE_componentWillReceive props.
return (
@@ -1557,7 +1557,7 @@ declare function flushSync<R>(fn: () => R): R;
// eslint-disable-next-line no-redeclare
declare function flushSync(): void;
// eslint-disable-next-line no-redeclare
export function flushSync(fn) {
export function flushSync(fn): void {
// In legacy mode, we flush pending passive effects at the beginning of the
// next event, not at the end of the previous one.
if (
@@ -1596,7 +1596,7 @@ export function flushSync(fn) {
}
}
export function isAlreadyRendering() {
export function isAlreadyRendering(): boolean {
// Used by the renderer to print a warning if certain APIs are called from
// the wrong context.
return (
+3 -1
View File
@@ -9,7 +9,9 @@
// TODO: This is pretty well supported by browsers. Maybe we can drop it.
export const clz32 = Math.clz32 ? Math.clz32 : clz32Fallback;
export const clz32: (x: number) => number = Math.clz32
? Math.clz32
: clz32Fallback;
// Count leading zeros.
// Based on:
+2 -2
View File
@@ -599,13 +599,13 @@ export function injectIntoGlobalHook(globalObject: any): void {
}
}
export function hasUnrecoverableErrors() {
export function hasUnrecoverableErrors(): boolean {
// TODO: delete this after removing dependency in RN.
return false;
}
// Exposed for testing.
export function _getMountedRootCount() {
export function _getMountedRootCount(): number {
if (__DEV__) {
return mountedRoots.size;
} else {
@@ -94,7 +94,7 @@ export async function getSource(
url: string,
context: GetSourceContext,
defaultGetSource: GetSourceFunction,
) {
): Promise<{source: Source}> {
// We stash this in case we end up needing to resolve export * statements later.
stashedGetSource = defaultGetSource;
return defaultGetSource(url, context, defaultGetSource);
@@ -29,7 +29,7 @@ class ClientReferenceDependency extends ModuleDependency {
super(request);
}
get type() {
get type(): string {
return 'client-reference';
}
}
+2 -1
View File
@@ -17,7 +17,8 @@ if (__DEV__) {
warnedAboutMissingGetChildContext = {};
}
export const emptyContextObject = {};
// $FlowFixMe[incompatible-exact]
export const emptyContextObject: {} = {};
if (__DEV__) {
Object.freeze(emptyContextObject);
}
+2 -2
View File
@@ -239,13 +239,13 @@ export function finishHooks(
return children;
}
export function getThenableStateAfterSuspending() {
export function getThenableStateAfterSuspending(): null | ThenableState {
const state = thenableState;
thenableState = null;
return state;
}
export function checkDidRenderIdHook() {
export function checkDidRenderIdHook(): boolean {
// This should be called immediately after every finishHooks call.
// Conceptually, it's part of the return value of finishHooks; it's only a
// separate function to avoid using an array tuple.
+1 -1
View File
@@ -39,7 +39,7 @@ export function prepareToUseHooksForComponent(
thenableState = prevThenableState;
}
export function getThenableStateAfterSuspending() {
export function getThenableStateAfterSuspending(): null | ThenableState {
const state = thenableState;
thenableState = null;
return state;
+1 -1
View File
@@ -6,7 +6,7 @@
* @flow
*/
export let hasBadMapPolyfill;
export let hasBadMapPolyfill: boolean;
if (__DEV__) {
hasBadMapPolyfill = false;
@@ -59,7 +59,7 @@ let currentPriorityLevel_DEPRECATED = NormalPriority;
// `isInputPending` is not available. Since we have no way of knowing if
// there's pending input, always yield at the end of the frame.
export function unstable_shouldYield() {
export function unstable_shouldYield(): boolean {
return getCurrentTime() >= deadline;
}
+12 -6
View File
@@ -73,7 +73,7 @@ function testStringCoercion(value: mixed) {
export function checkAttributeStringCoercion(
value: mixed,
attributeName: string,
) {
): void | string {
if (__DEV__) {
if (willCoercionThrow(value)) {
console.error(
@@ -87,7 +87,7 @@ export function checkAttributeStringCoercion(
}
}
export function checkKeyStringCoercion(value: mixed) {
export function checkKeyStringCoercion(value: mixed): void | string {
if (__DEV__) {
if (willCoercionThrow(value)) {
console.error(
@@ -100,7 +100,10 @@ export function checkKeyStringCoercion(value: mixed) {
}
}
export function checkPropStringCoercion(value: mixed, propName: string) {
export function checkPropStringCoercion(
value: mixed,
propName: string,
): void | string {
if (__DEV__) {
if (willCoercionThrow(value)) {
console.error(
@@ -114,7 +117,10 @@ export function checkPropStringCoercion(value: mixed, propName: string) {
}
}
export function checkCSSPropertyStringCoercion(value: mixed, propName: string) {
export function checkCSSPropertyStringCoercion(
value: mixed,
propName: string,
): void | string {
if (__DEV__) {
if (willCoercionThrow(value)) {
console.error(
@@ -128,7 +134,7 @@ export function checkCSSPropertyStringCoercion(value: mixed, propName: string) {
}
}
export function checkHtmlStringCoercion(value: mixed) {
export function checkHtmlStringCoercion(value: mixed): void | string {
if (__DEV__) {
if (willCoercionThrow(value)) {
console.error(
@@ -141,7 +147,7 @@ export function checkHtmlStringCoercion(value: mixed) {
}
}
export function checkFormFieldValueStringCoercion(value: mixed) {
export function checkFormFieldValueStringCoercion(value: mixed): void | string {
if (__DEV__) {
if (willCoercionThrow(value)) {
console.error(
+1 -1
View File
@@ -105,7 +105,7 @@ export function rethrowCaughtError() {
}
}
export function hasCaughtError() {
export function hasCaughtError(): boolean {
return hasError;
}
+28 -20
View File
@@ -12,28 +12,36 @@
// Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
// The Symbol used to tag the ReactElement-like types.
export const REACT_ELEMENT_TYPE = Symbol.for('react.element');
export const REACT_PORTAL_TYPE = Symbol.for('react.portal');
export const REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
export const REACT_STRICT_MODE_TYPE = Symbol.for('react.strict_mode');
export const REACT_PROFILER_TYPE = Symbol.for('react.profiler');
export const REACT_PROVIDER_TYPE = Symbol.for('react.provider');
export const REACT_CONTEXT_TYPE = Symbol.for('react.context');
export const REACT_SERVER_CONTEXT_TYPE = Symbol.for('react.server_context');
export const REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
export const REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
export const REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
export const REACT_MEMO_TYPE = Symbol.for('react.memo');
export const REACT_LAZY_TYPE = Symbol.for('react.lazy');
export const REACT_SCOPE_TYPE = Symbol.for('react.scope');
export const REACT_DEBUG_TRACING_MODE_TYPE = Symbol.for(
export const REACT_ELEMENT_TYPE: symbol = Symbol.for('react.element');
export const REACT_PORTAL_TYPE: symbol = Symbol.for('react.portal');
export const REACT_FRAGMENT_TYPE: symbol = Symbol.for('react.fragment');
export const REACT_STRICT_MODE_TYPE: symbol = Symbol.for('react.strict_mode');
export const REACT_PROFILER_TYPE: symbol = Symbol.for('react.profiler');
export const REACT_PROVIDER_TYPE: symbol = Symbol.for('react.provider');
export const REACT_CONTEXT_TYPE: symbol = Symbol.for('react.context');
export const REACT_SERVER_CONTEXT_TYPE: symbol = Symbol.for(
'react.server_context',
);
export const REACT_FORWARD_REF_TYPE: symbol = Symbol.for('react.forward_ref');
export const REACT_SUSPENSE_TYPE: symbol = Symbol.for('react.suspense');
export const REACT_SUSPENSE_LIST_TYPE: symbol = Symbol.for(
'react.suspense_list',
);
export const REACT_MEMO_TYPE: symbol = Symbol.for('react.memo');
export const REACT_LAZY_TYPE: symbol = Symbol.for('react.lazy');
export const REACT_SCOPE_TYPE: symbol = Symbol.for('react.scope');
export const REACT_DEBUG_TRACING_MODE_TYPE: symbol = Symbol.for(
'react.debug_trace_mode',
);
export const REACT_OFFSCREEN_TYPE = Symbol.for('react.offscreen');
export const REACT_LEGACY_HIDDEN_TYPE = Symbol.for('react.legacy_hidden');
export const REACT_CACHE_TYPE = Symbol.for('react.cache');
export const REACT_TRACING_MARKER_TYPE = Symbol.for('react.tracing_marker');
export const REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED = Symbol.for(
export const REACT_OFFSCREEN_TYPE: symbol = Symbol.for('react.offscreen');
export const REACT_LEGACY_HIDDEN_TYPE: symbol = Symbol.for(
'react.legacy_hidden',
);
export const REACT_CACHE_TYPE: symbol = Symbol.for('react.cache');
export const REACT_TRACING_MARKER_TYPE: symbol = Symbol.for(
'react.tracing_marker',
);
export const REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED: symbol = Symbol.for(
'react.default_value',
);
@@ -19,7 +19,7 @@ export const enableFilterEmptyStringAttributesDOM = __VARIANT__;
export const enableLegacyFBSupport = __VARIANT__;
export const skipUnmountedBoundaries = __VARIANT__;
export const enableUseRefAccessWarning = __VARIANT__;
export const deletedTreeCleanUpLevel = __VARIANT__ ? 3 : 1;
export const deletedTreeCleanUpLevel: number = __VARIANT__ ? 3 : 1;
export const enableProfilerNestedUpdateScheduledHook = __VARIANT__;
export const disableSchedulerTimeoutInWorkLoop = __VARIANT__;
export const enableLazyContextPropagation = __VARIANT__;
@@ -39,13 +39,13 @@ export const {
// On WWW, __EXPERIMENTAL__ is used for a new modern build.
// It's not used anywhere in production yet.
export const enableStrictEffects =
export const enableStrictEffects: boolean =
__DEV__ && dynamicFeatureFlags.enableStrictEffects;
export const debugRenderPhaseSideEffectsForStrictMode = __DEV__;
export const enableProfilerTimer = __PROFILE__;
export const enableProfilerCommitHooks = __PROFILE__;
export const enableProfilerNestedUpdatePhase = __PROFILE__;
export const enableProfilerNestedUpdateScheduledHook =
export const enableProfilerNestedUpdateScheduledHook: boolean =
__PROFILE__ && dynamicFeatureFlags.enableProfilerNestedUpdateScheduledHook;
export const enableUpdaterTracking = __PROFILE__;
@@ -57,7 +57,7 @@ export const enableUseHook = true;
export const enableUseMemoCacheHook = true;
// Logs additional User Timing API marks for use with an experimental profiling tool.
export const enableSchedulingProfiler =
export const enableSchedulingProfiler: boolean =
__PROFILE__ && dynamicFeatureFlags.enableSchedulingProfiler;
// Note: we'll want to remove this when we to userland implementation.
+1 -1
View File
@@ -35,7 +35,7 @@ import {
const REACT_MODULE_REFERENCE: symbol = Symbol.for('react.module.reference');
export default function isValidElementType(type: mixed) {
export default function isValidElementType(type: mixed): boolean {
if (typeof type === 'string' || typeof type === 'function') {
return true;
}