Skip to content

Commit 6ddcbd4

Browse files
authored
[flow] enable LTI inference mode (#26104)
This is the next generation inference mode for Flow.
1 parent 53b1f69 commit 6ddcbd4

File tree

110 files changed

+378
-283
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+378
-283
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"eslint-plugin-react-internal": "link:./scripts/eslint-rules",
6262
"fbjs-scripts": "^3.0.1",
6363
"filesize": "^6.0.1",
64-
"flow-bin": "^0.199.0",
64+
"flow-bin": "^0.199.1",
6565
"flow-remove-types": "^2.198.2",
6666
"glob": "^7.1.6",
6767
"glob-stream": "^6.1.0",

packages/jest-react/src/internalAct.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export function act<T>(scope: () => Thenable<T> | T): Thenable<T> {
7777
) {
7878
const thenableResult: Thenable<T> = (result: any);
7979
return {
80-
then(resolve, reject) {
80+
then(resolve: T => mixed, reject: mixed => mixed) {
8181
thenableResult.then(
8282
returnValue => {
8383
flushActWork(
@@ -108,7 +108,7 @@ export function act<T>(scope: () => Thenable<T> | T): Thenable<T> {
108108
didFlushWork = Scheduler.unstable_flushAllWithoutAsserting();
109109
} while (didFlushWork);
110110
return {
111-
then(resolve, reject) {
111+
then(resolve: T => mixed, reject: mixed => mixed) {
112112
resolve(returnValue);
113113
},
114114
};

packages/react-cache/src/ReactCacheOld.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ function identityHashFn(input) {
8585
}
8686

8787
const CACHE_LIMIT = 500;
88-
const lru = createLRU(CACHE_LIMIT);
88+
const lru = createLRU<$FlowFixMe>(CACHE_LIMIT);
8989

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

92-
const CacheContext = React.createContext(null);
92+
const CacheContext = React.createContext<mixed>(null);
9393

9494
function accessResult<I, K, V>(
9595
resource: any,

packages/react-client/src/ReactFlightClient.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ Chunk.prototype.then = function <T>(
129129
case BLOCKED:
130130
if (resolve) {
131131
if (chunk.value === null) {
132-
chunk.value = [];
132+
chunk.value = ([]: Array<(T) => mixed>);
133133
}
134134
chunk.value.push(resolve);
135135
}
136136
if (reject) {
137137
if (chunk.reason === null) {
138-
chunk.reason = [];
138+
chunk.reason = ([]: Array<(mixed) => mixed>);
139139
}
140140
chunk.reason.push(reject);
141141
}
@@ -435,7 +435,7 @@ function createModelResolver<T>(
435435
chunk: SomeChunk<T>,
436436
parentObject: Object,
437437
key: string,
438-
) {
438+
): (value: any) => void {
439439
let blocked;
440440
if (initializingChunkBlockedModel) {
441441
blocked = initializingChunkBlockedModel;
@@ -446,7 +446,6 @@ function createModelResolver<T>(
446446
value: null,
447447
};
448448
}
449-
// $FlowFixMe[missing-local-annot]
450449
return value => {
451450
parentObject[key] = value;
452451
blocked.deps--;
@@ -465,7 +464,7 @@ function createModelResolver<T>(
465464
};
466465
}
467466

468-
function createModelReject<T>(chunk: SomeChunk<T>) {
467+
function createModelReject<T>(chunk: SomeChunk<T>): (error: mixed) => void {
469468
return (error: mixed) => triggerErrorOnChunk(chunk, error);
470469
}
471470

@@ -583,7 +582,7 @@ export function resolveModule(
583582
const chunks = response._chunks;
584583
const chunk = chunks.get(id);
585584
const moduleMetaData: ModuleMetaData = parseModel(response, model);
586-
const moduleReference = resolveClientReference(
585+
const moduleReference = resolveClientReference<$FlowFixMe>(
587586
response._bundlerConfig,
588587
moduleMetaData,
589588
);

packages/react-debug-tools/src/ReactDebugHooks.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ function getPrimitiveStackCache(): Map<string, Array<any>> {
6060
// This initializes a cache of all primitive hooks so that the top
6161
// most stack frames added by calling the primitive hook can be removed.
6262
if (primitiveStackCache === null) {
63-
const cache = new Map();
63+
const cache = new Map<string, Array<any>>();
6464
let readHookLog;
6565
try {
6666
// Use all hooks here to add them to the hook log.
6767
Dispatcher.useContext(({_currentValue: null}: any));
6868
Dispatcher.useState(null);
69-
Dispatcher.useReducer((s, a) => s, null);
69+
Dispatcher.useReducer((s: mixed, a: mixed) => s, null);
7070
Dispatcher.useRef(null);
7171
if (typeof Dispatcher.useCacheRefresh === 'function') {
7272
// This type check is for Flow only.
@@ -809,7 +809,7 @@ export function inspectHooksOfFiber(
809809
// Set up the current hook so that we can step through and read the
810810
// current state from them.
811811
currentHook = (fiber.memoizedState: Hook);
812-
const contextMap = new Map();
812+
const contextMap = new Map<ReactContext<$FlowFixMe>, $FlowFixMe>();
813813
try {
814814
setupContexts(contextMap, fiber);
815815
if (fiber.tag === ForwardRef) {

packages/react-devtools-core/src/backend.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export function connectToDevTools(options: ?ConnectOptions) {
6767
useHttps = false,
6868
port = 8097,
6969
websocket,
70-
resolveRNStyle = null,
70+
resolveRNStyle = (null: $FlowFixMe),
7171
retryConnectionDelay = 2000,
7272
isAppActive = () => true,
7373
devToolsSettingsManager,
@@ -230,7 +230,7 @@ export function connectToDevTools(options: ?ConnectOptions) {
230230
get() {
231231
return lazyResolveRNStyle;
232232
},
233-
set(value) {
233+
set(value: $FlowFixMe) {
234234
lazyResolveRNStyle = value;
235235
initAfterTick();
236236
},
@@ -246,7 +246,7 @@ export function connectToDevTools(options: ?ConnectOptions) {
246246
get() {
247247
return lazyNativeStyleEditorValidAttributes;
248248
},
249-
set(value) {
249+
set(value: $FlowFixMe) {
250250
lazyNativeStyleEditorValidAttributes = value;
251251
initAfterTick();
252252
},

packages/react-devtools-core/src/editor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export function launchEditor(
188188
}
189189
childProcess.on('error', function () {});
190190
// $FlowFixMe[incompatible-use] found when upgrading Flow
191-
childProcess.on('exit', function (errorCode) {
191+
childProcess.on('exit', function () {
192192
childProcess = null;
193193
});
194194
}

packages/react-devtools-core/src/standalone.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ function onDisconnected() {
168168
}
169169

170170
// $FlowFixMe[missing-local-annot]
171-
function onError({code, message}) {
171+
function onError({code, message}: $FlowFixMe) {
172172
safeUnmount();
173173

174174
if (code === 'EADDRINUSE') {
@@ -335,13 +335,13 @@ function startServer(
335335
initialize(socket);
336336
});
337337

338-
server.on('error', event => {
338+
server.on('error', (event: $FlowFixMe) => {
339339
onError(event);
340340
log.error('Failed to start the DevTools server', event);
341341
startServerTimeoutID = setTimeout(() => startServer(port), 1000);
342342
});
343343

344-
httpServer.on('request', (request, response) => {
344+
httpServer.on('request', (request: $FlowFixMe, response: $FlowFixMe) => {
345345
// Serve a file that immediately sets up the connection.
346346
const backendFile = readFileSync(join(__dirname, 'backend.js'));
347347

@@ -377,7 +377,7 @@ function startServer(
377377
);
378378
});
379379

380-
httpServer.on('error', event => {
380+
httpServer.on('error', (event: $FlowFixMe) => {
381381
onError(event);
382382
statusListener('Failed to start the server.', 'error');
383383
startServerTimeoutID = setTimeout(() => startServer(port), 1000);

packages/react-devtools-extensions/src/backend.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
let welcomeHasInitialized = false;
1010

1111
// $FlowFixMe[missing-local-annot]
12-
function welcome(event) {
12+
function welcome(event: $FlowFixMe) {
1313
if (
1414
event.source !== window ||
1515
event.data.source !== 'react-devtools-content-script'
@@ -56,8 +56,7 @@ function setup(hook: any) {
5656

5757
const bridge = new Bridge({
5858
listen(fn) {
59-
// $FlowFixMe[missing-local-annot]
60-
const listener = event => {
59+
const listener = (event: $FlowFixMe) => {
6160
if (
6261
event.source !== window ||
6362
!event.data ||

packages/react-devtools-inline/src/backend.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import type {BackendBridge} from 'react-devtools-shared/src/bridge';
1010
import type {Wall} from 'react-devtools-shared/src/types';
1111

1212
function startActivation(contentWindow: any, bridge: BackendBridge) {
13-
// $FlowFixMe[missing-local-annot]
14-
const onSavedPreferences = data => {
13+
const onSavedPreferences = (data: $FlowFixMe) => {
1514
// This is the only message we're listening for,
1615
// so it's safe to cleanup after we've received it.
1716
bridge.removeListener('savedPreferences', onSavedPreferences);
@@ -102,8 +101,7 @@ export function createBridge(contentWindow: any, wall?: Wall): BackendBridge {
102101
if (wall == null) {
103102
wall = {
104103
listen(fn) {
105-
// $FlowFixMe[missing-local-annot]
106-
const onMessage = ({data}) => {
104+
const onMessage = ({data}: $FlowFixMe) => {
107105
fn(data);
108106
};
109107
contentWindow.addEventListener('message', onMessage);

packages/react-devtools-shared/src/backend/DevToolsComponentStackFrame.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ let reentry = false;
5454
let componentFrameCache;
5555
if (__DEV__) {
5656
const PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
57-
componentFrameCache = new PossiblyWeakMap();
57+
componentFrameCache = new PossiblyWeakMap<$FlowFixMe, string>();
5858
}
5959

6060
export function describeNativeComponentFrame(

packages/react-devtools-shared/src/backend/StyleX/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import isArray from 'react-devtools-shared/src/isArray';
1313
const cachedStyleNameToValueMap: Map<string, string> = new Map();
1414

1515
export function getStyleXData(data: any): StyleXPlugin {
16-
const sources = new Set();
16+
const sources = new Set<string>();
1717
const resolvedStyles = {};
1818

1919
crawlData(data, sources, resolvedStyles);

packages/react-devtools-shared/src/backend/legacy/renderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ export function attach(
503503
const numUnmountIDs =
504504
pendingUnmountedIDs.length + (pendingUnmountedRootID === null ? 0 : 1);
505505

506-
const operations = new Array(
506+
const operations = new Array<number>(
507507
// Identify which renderer this update is coming from.
508508
2 + // [rendererID, rootFiberID]
509509
// How big is the string table?

packages/react-devtools-shared/src/backend/profilingHooks.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1818
import type {Wakeable} from 'shared/ReactTypes';
1919
import type {
2020
BatchUID,
21+
InternalModuleSourceToRanges,
2122
LaneToLabelMap,
2223
ReactComponentMeasure,
24+
ReactLane,
2325
ReactMeasure,
2426
ReactMeasureType,
25-
TimelineData,
26-
SuspenseEvent,
27-
SchedulingEvent,
2827
ReactScheduleStateUpdateEvent,
28+
SchedulingEvent,
29+
SuspenseEvent,
30+
TimelineData,
2931
} from 'react-devtools-timeline/src/types';
3032

3133
import isArray from 'shared/isArray';
@@ -837,7 +839,8 @@ export function createProfilingHooks({
837839
isProfiling = value;
838840

839841
if (isProfiling) {
840-
const internalModuleSourceToRanges = new Map();
842+
const internalModuleSourceToRanges: InternalModuleSourceToRanges =
843+
new Map();
841844

842845
if (supportsUserTimingV3) {
843846
const ranges = getInternalModuleRanges();
@@ -856,7 +859,7 @@ export function createProfilingHooks({
856859
}
857860
}
858861

859-
const laneToReactMeasureMap = new Map();
862+
const laneToReactMeasureMap = new Map<ReactLane, ReactMeasure[]>();
860863
let lane = 1;
861864
for (let index = 0; index < REACT_TOTAL_NUM_LANES; index++) {
862865
laneToReactMeasureMap.set(lane, []);

packages/react-devtools-shared/src/backend/renderer.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ export function getInternalReactConstants(version: string): {
415415
TracingMarkerComponent,
416416
} = ReactTypeOfWork;
417417

418-
function resolveFiberType(type: any) {
418+
function resolveFiberType(type: any): $FlowFixMe {
419419
const typeSymbol = getTypeSymbol(type);
420420
switch (typeSymbol) {
421421
case MEMO_NUMBER:
@@ -1627,7 +1627,7 @@ export function attach(
16271627
}
16281628
}
16291629

1630-
let flushPendingErrorsAndWarningsAfterDelayTimeoutID = null;
1630+
let flushPendingErrorsAndWarningsAfterDelayTimeoutID: null | TimeoutID = null;
16311631

16321632
function clearPendingErrorsAndWarningsAfterDelay() {
16331633
if (flushPendingErrorsAndWarningsAfterDelayTimeoutID !== null) {
@@ -1790,7 +1790,7 @@ export function attach(
17901790
pendingSimulatedUnmountedIDs.length +
17911791
(pendingUnmountedRootID === null ? 0 : 1);
17921792

1793-
const operations = new Array(
1793+
const operations = new Array<number>(
17941794
// Identify which renderer this update is coming from.
17951795
2 + // [rendererID, rootFiberID]
17961796
// How big is the string table?
@@ -4144,7 +4144,7 @@ export function attach(
41444144

41454145
// Map of id and its force error status: true (error), false (toggled off),
41464146
// null (do nothing)
4147-
const forceErrorForFiberIDs = new Map();
4147+
const forceErrorForFiberIDs = new Map<number | null, $FlowFixMe>();
41484148

41494149
function shouldErrorFiberAccordingToMap(fiber: any) {
41504150
if (typeof setErrorHandler !== 'function') {
@@ -4209,7 +4209,7 @@ export function attach(
42094209
return false;
42104210
}
42114211

4212-
const forceFallbackForSuspenseIDs = new Set();
4212+
const forceFallbackForSuspenseIDs = new Set<number>();
42134213

42144214
function shouldSuspendFiberAccordingToSet(fiber: any) {
42154215
const maybeID = getFiberIDUnsafe(((fiber: any): Fiber));

packages/react-devtools-shared/src/backend/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export function getEffectDurations(root: Object): {
144144
}
145145

146146
export function serializeToString(data: any): string {
147-
const cache = new Set();
147+
const cache = new Set<mixed>();
148148
// Use a custom replacer function to protect against circular references.
149149
return JSON.stringify(data, (key, value) => {
150150
if (typeof value === 'object' && value !== null) {

packages/react-devtools-shared/src/backend/views/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export function getNestedBoundingClientRect(
8383
): Rect {
8484
const ownerIframe = getOwnerIframe(node);
8585
if (ownerIframe && ownerIframe !== boundaryWindow) {
86-
const rects = [node.getBoundingClientRect()];
86+
const rects: Array<Rect | ClientRect> = [node.getBoundingClientRect()];
8787
let currentIframe: null | HTMLElement = ownerIframe;
8888
let onlyOneMore = false;
8989
while (currentIframe) {

packages/react-devtools-shared/src/devtools/ProfilerStore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ export default class ProfilerStore extends EventEmitter<{
308308
// Record snapshot of tree at the time profiling is started.
309309
// This info is required to handle cases of e.g. nodes being removed during profiling.
310310
this._store.roots.forEach(rootID => {
311-
const profilingSnapshots = new Map();
311+
const profilingSnapshots = new Map<number, SnapshotNode>();
312312
this._initialSnapshotsByRootID.set(rootID, profilingSnapshots);
313313
this._takeProfilingSnapshotRecursive(rootID, profilingSnapshots);
314314
});

packages/react-devtools-shared/src/devtools/store.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ export default class Store extends EventEmitter<{
642642
}
643643

644644
getOwnersListForElement(ownerID: number): Array<Element> {
645-
const list = [];
645+
const list: Array<Element> = [];
646646
const element = this._idToElement.get(ownerID);
647647
if (element != null) {
648648
list.push({
@@ -900,7 +900,7 @@ export default class Store extends EventEmitter<{
900900
let i = 2;
901901

902902
// Reassemble the string table.
903-
const stringTable = [
903+
const stringTable: Array<string | null> = [
904904
null, // ID = 0 corresponds to the null string.
905905
];
906906
const stringTableSize = operations[i++];

packages/react-devtools-shared/src/devtools/views/Components/EditableName.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default function EditableName({
4343
const [isValid, setIsValid] = useState(false);
4444

4545
const handleChange = useCallback(
46-
({target}) => {
46+
({target}: $FlowFixMe) => {
4747
let value = target.value;
4848
if (!allowWhiteSpace) {
4949
value = value.trim();
@@ -61,7 +61,7 @@ export default function EditableName({
6161
);
6262

6363
const handleKeyDown = useCallback(
64-
event => {
64+
(event: $FlowFixMe) => {
6565
// Prevent keydown events from e.g. change selected element in the tree
6666
event.stopPropagation();
6767

0 commit comments

Comments
 (0)