Skip to content

Commit

Permalink
[flow] enable LTI for some directories
Browse files Browse the repository at this point in the history
  • Loading branch information
kassens committed Feb 3, 2023
1 parent 855b77c commit 1f5c2e0
Show file tree
Hide file tree
Showing 32 changed files with 149 additions and 88 deletions.
4 changes: 2 additions & 2 deletions packages/jest-react/src/internalAct.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function act<T>(scope: () => Thenable<T> | T): Thenable<T> {
) {
const thenableResult: Thenable<T> = (result: any);
return {
then(resolve, reject) {
then(resolve: T => mixed, reject: mixed => mixed) {
thenableResult.then(
returnValue => {
flushActWork(
Expand Down Expand Up @@ -108,7 +108,7 @@ export function act<T>(scope: () => Thenable<T> | T): Thenable<T> {
didFlushWork = Scheduler.unstable_flushAllWithoutAsserting();
} while (didFlushWork);
return {
then(resolve, reject) {
then(resolve: T => mixed, reject: mixed => mixed) {
resolve(returnValue);
},
};
Expand Down
4 changes: 2 additions & 2 deletions packages/react-cache/src/ReactCacheOld.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ function identityHashFn(input) {
}

const CACHE_LIMIT = 500;
const lru = createLRU(CACHE_LIMIT);
const lru = createLRU<$FlowFixMe>(CACHE_LIMIT);

const entries: Map<Resource<any, any>, Map<any, any>> = new Map();

const CacheContext = React.createContext(null);
const CacheContext = React.createContext<mixed>(null);

function accessResult<I, K, V>(
resource: any,
Expand Down
11 changes: 5 additions & 6 deletions packages/react-client/src/ReactFlightClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ Chunk.prototype.then = function <T>(
case BLOCKED:
if (resolve) {
if (chunk.value === null) {
chunk.value = [];
chunk.value = ([]: Array<(T) => mixed>);
}
chunk.value.push(resolve);
}
if (reject) {
if (chunk.reason === null) {
chunk.reason = [];
chunk.reason = ([]: Array<(mixed) => mixed>);
}
chunk.reason.push(reject);
}
Expand Down Expand Up @@ -435,7 +435,7 @@ function createModelResolver<T>(
chunk: SomeChunk<T>,
parentObject: Object,
key: string,
) {
): (value: any) => void {
let blocked;
if (initializingChunkBlockedModel) {
blocked = initializingChunkBlockedModel;
Expand All @@ -446,7 +446,6 @@ function createModelResolver<T>(
value: null,
};
}
// $FlowFixMe[missing-local-annot]
return value => {
parentObject[key] = value;
blocked.deps--;
Expand All @@ -465,7 +464,7 @@ function createModelResolver<T>(
};
}

function createModelReject<T>(chunk: SomeChunk<T>) {
function createModelReject<T>(chunk: SomeChunk<T>): (error: mixed) => void {
return (error: mixed) => triggerErrorOnChunk(chunk, error);
}

Expand Down Expand Up @@ -583,7 +582,7 @@ export function resolveModule(
const chunks = response._chunks;
const chunk = chunks.get(id);
const moduleMetaData: ModuleMetaData = parseModel(response, model);
const moduleReference = resolveClientReference(
const moduleReference = resolveClientReference<$FlowFixMe>(
response._bundlerConfig,
moduleMetaData,
);
Expand Down
6 changes: 3 additions & 3 deletions packages/react-debug-tools/src/ReactDebugHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ function getPrimitiveStackCache(): Map<string, Array<any>> {
// This initializes a cache of all primitive hooks so that the top
// most stack frames added by calling the primitive hook can be removed.
if (primitiveStackCache === null) {
const cache = new Map();
const cache = new Map<string, Array<any>>();
let readHookLog;
try {
// Use all hooks here to add them to the hook log.
Dispatcher.useContext(({_currentValue: null}: any));
Dispatcher.useState(null);
Dispatcher.useReducer((s, a) => s, null);
Dispatcher.useReducer((s: mixed, a: mixed) => s, null);
Dispatcher.useRef(null);
if (typeof Dispatcher.useCacheRefresh === 'function') {
// This type check is for Flow only.
Expand Down Expand Up @@ -809,7 +809,7 @@ export function inspectHooksOfFiber(
// Set up the current hook so that we can step through and read the
// current state from them.
currentHook = (fiber.memoizedState: Hook);
const contextMap = new Map();
const contextMap = new Map<ReactContext<$FlowFixMe>, $FlowFixMe>();
try {
setupContexts(contextMap, fiber);
if (fiber.tag === ForwardRef) {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/client/ReactDOMLegacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function legacyCreateRootFromDOMContainer(
};
}

const root = createHydrationContainer(
const root: FiberRoot = createHydrationContainer(
initialChildren,
callback,
container,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/server/ReactDOMFizzServerBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function renderToReadableStream(
return new Promise((resolve, reject) => {
let onFatalError;
let onAllReady;
const allReady = new Promise((res, rej) => {
const allReady = new Promise<void>((res, rej) => {
onAllReady = res;
onFatalError = rej;
});
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/server/ReactDOMFizzServerBun.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function renderToReadableStream(
return new Promise((resolve, reject) => {
let onFatalError;
let onAllReady;
const allReady = new Promise((res, rej) => {
const allReady = new Promise<void>((res, rej) => {
onAllReady = res;
onFatalError = rej;
});
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/server/ReactDOMFizzStaticNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function prerenderToNodeStreams(
const onFatalError = reject;

function onAllReady() {
const readable = new Readable({
const readable: Readable = new Readable({
read() {
startFlowing(request, writable);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function useEvent(

if (useEventHandle === null) {
const setEventHandle = unstable_createEventHandle(event, options);
const clears = new Map();
const clears = new Map<EventTarget, () => void>();
useEventHandle = {
setListener(
target: EventTarget,
Expand Down
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/ReactChildFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ function createChildReconciler(

if (__DEV__) {
// First, validate keys.
let knownKeys = null;
let knownKeys: Set<string> | null = null;
for (let i = 0; i < newChildren.length; i++) {
const child = newChildren[i];
knownKeys = warnOnInvalidKey(child, knownKeys, returnFiber);
Expand Down Expand Up @@ -961,7 +961,7 @@ function createChildReconciler(
// We'll get a different iterator later for the main pass.
const newChildren = iteratorFn.call(newChildrenIterable);
if (newChildren) {
let knownKeys = null;
let knownKeys: Set<string> | null = null;
let step = newChildren.next();
for (; !step.done; step = newChildren.next()) {
const child = step.value;
Expand Down
8 changes: 4 additions & 4 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -1492,7 +1492,7 @@ function updateHostRoot(
if (workInProgress.flags & ForceClientRender) {
// Something errored during a previous attempt to hydrate the shell, so we
// forced a client render.
const recoverableError = createCapturedValueAtFiber(
const recoverableError = createCapturedValueAtFiber<mixed>(
new Error(
'There was an error while hydrating. Because the error happened outside ' +
'of a Suspense boundary, the entire root will switch to ' +
Expand All @@ -1508,7 +1508,7 @@ function updateHostRoot(
recoverableError,
);
} else if (nextChildren !== prevChildren) {
const recoverableError = createCapturedValueAtFiber(
const recoverableError = createCapturedValueAtFiber<mixed>(
new Error(
'This root received an early update, before anything was able ' +
'hydrate. Switched the entire root to client rendering.',
Expand Down Expand Up @@ -2820,7 +2820,7 @@ function updateDehydratedSuspenseComponent(
);
}
(error: any).digest = digest;
const capturedValue = createCapturedValue(error, digest, stack);
const capturedValue = createCapturedValue<mixed>(error, digest, stack);
return retrySuspenseComponentWithoutHydrating(
current,
workInProgress,
Expand Down Expand Up @@ -2955,7 +2955,7 @@ function updateDehydratedSuspenseComponent(
pushPrimaryTreeSuspenseHandler(workInProgress);

workInProgress.flags &= ~ForceClientRender;
const capturedValue = createCapturedValue(
const capturedValue = createCapturedValue<mixed>(
new Error(
'There was an error while hydrating this Suspense boundary. ' +
'Switched to client rendering.',
Expand Down
20 changes: 10 additions & 10 deletions packages/react-reconciler/src/ReactFiberClassComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,16 @@ let didWarnAboutContextTypeAndContextTypes;
let didWarnAboutInvalidateContextType;

if (__DEV__) {
didWarnAboutStateAssignmentForComponent = new Set();
didWarnAboutUninitializedState = new Set();
didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set();
didWarnAboutLegacyLifecyclesAndDerivedState = new Set();
didWarnAboutDirectlyAssigningPropsToState = new Set();
didWarnAboutUndefinedDerivedState = new Set();
didWarnAboutContextTypeAndContextTypes = new Set();
didWarnAboutInvalidateContextType = new Set();

const didWarnOnInvalidCallback = new Set();
didWarnAboutStateAssignmentForComponent = new Set<string>();
didWarnAboutUninitializedState = new Set<string>();
didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set<string>();
didWarnAboutLegacyLifecyclesAndDerivedState = new Set<string>();
didWarnAboutDirectlyAssigningPropsToState = new Set<string>();
didWarnAboutUndefinedDerivedState = new Set<string>();
didWarnAboutContextTypeAndContextTypes = new Set<string>();
didWarnAboutInvalidateContextType = new Set<string>();

const didWarnOnInvalidCallback = new Set<string>();

warnOnInvalidCallback = function (callback: mixed, callerName: string) {
if (callback === null || typeof callback === 'function') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ export function processUpdateQueue<State>(

let newBaseState = null;
let newFirstBaseUpdate = null;
let newLastBaseUpdate = null;
let newLastBaseUpdate: null | Update<State> = null;

let update: Update<State> = firstBaseUpdate;
do {
Expand Down
7 changes: 6 additions & 1 deletion packages/react-reconciler/src/ReactFiberCompleteWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,12 @@ function hadNoMutationsEffects(current: null | Fiber, completedWork: Fiber) {
return true;
}

let appendAllChildren;
let appendAllChildren: (
parent: Instance,
workInProgress: Fiber,
needsVisibilityToggle: boolean,
isHidden: boolean,
) => void;
let updateHostContainer;
let updateHostComponent;
let updateHostText;
Expand Down
6 changes: 3 additions & 3 deletions packages/react-reconciler/src/ReactFiberHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ let didWarnAboutMismatchedHooksForComponent;
let didWarnUncachedGetSnapshot;
let didWarnAboutUseWrappedInTryCatch;
if (__DEV__) {
didWarnAboutMismatchedHooksForComponent = new Set();
didWarnAboutUseWrappedInTryCatch = new Set();
didWarnAboutMismatchedHooksForComponent = new Set<string | null>();
didWarnAboutUseWrappedInTryCatch = new Set<string | null>();
}

export type Hook = {
Expand Down Expand Up @@ -1112,7 +1112,7 @@ function updateReducer<S, I, A>(

let newBaseState = null;
let newBaseQueueFirst = null;
let newBaseQueueLast = null;
let newBaseQueueLast: Update<S, A> | null = null;
let update = first;
do {
// An extra OffscreenLane bit is added to updates that were made to
Expand Down
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/ReactFiberHotReloading.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ function scheduleFibersWithFamiliesRecursively(
fiber: Fiber,
updatedFamilies: Set<Family>,
staleFamilies: Set<Family>,
) {
): void {
if (__DEV__) {
const {alternate, child, sibling, tag, type} = fiber;

Expand Down Expand Up @@ -353,7 +353,7 @@ export const findHostInstancesForRefresh: FindHostInstancesForRefresh = (
families: Array<Family>,
): Set<Instance> => {
if (__DEV__) {
const hostInstances = new Set();
const hostInstances = new Set<Instance>();
const types = new Set(families.map(family => family.current));
findHostInstancesForMatchingFibersRecursively(
root.current,
Expand Down
6 changes: 3 additions & 3 deletions packages/react-reconciler/src/ReactFiberReconciler.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ if (__DEV__) {
obj: Object | Array<any>,
path: Array<string | number>,
index: number,
) => {
): $FlowFixMe => {
const key = path[index];
const updated = isArray(obj) ? obj.slice() : {...obj};
if (index + 1 === path.length) {
Expand Down Expand Up @@ -582,7 +582,7 @@ if (__DEV__) {
oldPath: Array<string | number>,
newPath: Array<string | number>,
index: number,
) => {
): $FlowFixMe => {
const oldKey = oldPath[index];
const updated = isArray(obj) ? obj.slice() : {...obj};
if (index + 1 === oldPath.length) {
Expand Down Expand Up @@ -633,7 +633,7 @@ if (__DEV__) {
path: Array<string | number>,
index: number,
value: any,
) => {
): $FlowFixMe => {
if (index >= path.length) {
return value;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/ReactFiberTreeReflection.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export function findCurrentHostFiber(parent: Fiber): Fiber | null {
: null;
}

function findCurrentHostFiberImpl(node: Fiber) {
function findCurrentHostFiberImpl(node: Fiber): Fiber | null {
// Next we'll drill down this component to find the first HostComponent/Text.
const tag = node.tag;
if (
Expand Down Expand Up @@ -306,7 +306,7 @@ export function findCurrentHostFiberWithNoPortals(parent: Fiber): Fiber | null {
: null;
}

function findCurrentHostFiberWithNoPortalsImpl(node: Fiber) {
function findCurrentHostFiberWithNoPortalsImpl(node: Fiber): Fiber | null {
// Next we'll drill down this component to find the first HostComponent/Text.
const tag = node.tag;
if (
Expand Down
15 changes: 10 additions & 5 deletions packages/react-reconciler/src/ReactFiberWorkLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@ export function addTransitionStartCallbackToPendingTransition(
}

if (currentPendingTransitionCallbacks.transitionStart === null) {
currentPendingTransitionCallbacks.transitionStart = [];
currentPendingTransitionCallbacks.transitionStart =
([]: Array<Transition>);
}

currentPendingTransitionCallbacks.transitionStart.push(transition);
Expand Down Expand Up @@ -537,7 +538,8 @@ export function addTransitionCompleteCallbackToPendingTransition(
}

if (currentPendingTransitionCallbacks.transitionComplete === null) {
currentPendingTransitionCallbacks.transitionComplete = [];
currentPendingTransitionCallbacks.transitionComplete =
([]: Array<Transition>);
}

currentPendingTransitionCallbacks.transitionComplete.push(transition);
Expand Down Expand Up @@ -1000,7 +1002,10 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {

// This is the entry point for every concurrent task, i.e. anything that
// goes through Scheduler.
function performConcurrentWorkOnRoot(root: FiberRoot, didTimeout: boolean) {
function performConcurrentWorkOnRoot(
root: FiberRoot,
didTimeout: boolean,
): $FlowFixMe {
if (enableProfilerTimer && enableProfilerNestedUpdatePhase) {
resetNestedUpdateFlag();
}
Expand Down Expand Up @@ -3329,7 +3334,7 @@ export function attachPingListener(
let threadIDs;
if (pingCache === null) {
pingCache = root.pingCache = new PossiblyWeakMap();
threadIDs = new Set();
threadIDs = new Set<mixed>();
pingCache.set(wakeable, threadIDs);
} else {
threadIDs = pingCache.get(wakeable);
Expand Down Expand Up @@ -3829,7 +3834,7 @@ if (__DEV__ && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
let didWarnAboutUpdateInRender = false;
let didWarnAboutUpdateInRenderForAnotherComponent;
if (__DEV__) {
didWarnAboutUpdateInRenderForAnotherComponent = new Set();
didWarnAboutUpdateInRenderForAnotherComponent = new Set<string>();
}

function warnAboutRenderPhaseUpdatesInDEV(fiber: Fiber) {
Expand Down
1 change: 0 additions & 1 deletion packages/react-reconciler/src/ReactProfilerTimer.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ function stopProfilerTimerIfRunningAndRecordDelta(

if (profilerStartTime >= 0) {
const elapsedTime = now() - profilerStartTime;
// $FlowFixMe[unsafe-addition] addition with possible null/undefined value
fiber.actualDuration += elapsedTime;
if (overrideBaseTime) {
fiber.selfBaseDuration = elapsedTime;
Expand Down
Loading

0 comments on commit 1f5c2e0

Please sign in to comment.