Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Flow from 0.97 to 0.122 #25204

Merged
merged 4 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"eslint-plugin-react-internal": "link:./scripts/eslint-rules",
"fbjs-scripts": "1.2.0",
"filesize": "^6.0.1",
"flow-bin": "0.97",
"flow-bin": "^0.122",
"glob": "^7.1.6",
"glob-stream": "^6.1.0",
"google-closure-compiler": "^20200517.0.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-react/src/internalAct.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export function act<T>(scope: () => Thenable<T> | T): Thenable<T> {
'This version of `act` requires a special mock build of Scheduler.',
);
}

// $FlowFixMe: _isMockFunction doesn't exist on function
if (setTimeout._isMockFunction !== true) {
throw Error(
"This version of `act` requires Jest's timer mocks " +
Expand Down
1 change: 1 addition & 0 deletions packages/react-debug-tools/src/ReactDebugHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ function handleRenderFunctionError(error: any): void {
// TODO: refactor this if we ever combine the devtools and debug tools packages
wrapperError.name = 'ReactDebugToolsRenderError';
// this stage-4 proposal is not supported by all environments yet.
// $FlowFixMe Flow doesn't have this type yet.
wrapperError.cause = error;
throw wrapperError;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/react-devtools-shared/src/backend/StyleX/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ function getPropertyValueForStyleName(styleName: string): string | null {
]: any): CSSStyleSheet);
// $FlowFixMe Flow doesn't konw about these properties
const rules = styleSheet.rules || styleSheet.cssRules;
// $FlowFixMe `rules` is mixed
for (let ruleIndex = 0; ruleIndex < rules.length; ruleIndex++) {
// $FlowFixMe `rules` is mixed
const rule = rules[ruleIndex];
// $FlowFixMe Flow doesn't konw about these properties
const {cssText, selectorText, style} = rule;
Expand Down
7 changes: 4 additions & 3 deletions packages/react-devtools-shared/src/backend/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ import type {
} from 'react-devtools-shared/src/types';

type getDisplayNameForFiberType = (fiber: Fiber) => string | null;
type getTypeSymbolType = (type: any) => Symbol | number;
type getTypeSymbolType = (type: any) => symbol | number;

type ReactPriorityLevelsType = {|
ImmediatePriority: number,
Expand Down Expand Up @@ -382,13 +382,14 @@ export function getInternalReactConstants(
// End of copied code.
// **********************************************************

function getTypeSymbol(type: any): Symbol | number {
function getTypeSymbol(type: any): symbol | number {
const symbolOrNumber =
typeof type === 'object' && type !== null ? type.$$typeof : type;

// $FlowFixMe Flow doesn't know about typeof "symbol"
return typeof symbolOrNumber === 'symbol'
? symbolOrNumber.toString()
? // $FlowFixMe `toString()` doesn't match the type signature?
symbolOrNumber.toString()
: symbolOrNumber;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/react-devtools-shared/src/backend/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export type GetFiberIDForNative = (
export type FindNativeNodesForFiberID = (id: number) => ?Array<NativeType>;

export type ReactProviderType<T> = {
$$typeof: Symbol | number,
$$typeof: symbol | number,
_context: ReactContext<T>,
...
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default function Button({
...rest
}: Props) {
let button = (
// $FlowFixMe unsafe spread
<button
className={`${styles.Button} ${className}`}
data-testname={testName}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default function AutoSizeInput({
const isEmpty = value === '' || value === '""';

return (
// $FlowFixMe unsafe rest spread
<input
className={[styles.Input, className].join(' ')}
data-testname={testName}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import useThemeStyles from '../../useThemeStyles';
const MenuList = ({children, ...props}: {children: React$Node, ...}) => {
const style = useThemeStyles();
return (
// $FlowFixMe unsafe spread
<ReachMenuList style={style} {...props}>
{children}
</ReachMenuList>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const Tooltip = ({
}) => {
const style = useThemeStyles();
return (
// $FlowFixMe unsafe spread
<ReachTooltip
className={`${tooltipStyles.Tooltip} ${className}`}
style={style}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-devtools-shared/src/hydration.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ export function hydrate(
parent[last] = undefined;
} else {
// Replace the string keys with Symbols so they're non-enumerable.
const replaced: {[key: Symbol]: boolean | string, ...} = {};
const replaced: {[key: symbol]: boolean | string, ...} = {};
replaced[meta.inspectable] = !!value.inspectable;
replaced[meta.inspected] = false;
replaced[meta.name] = value.name;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function registerDevToolsEventLogger(
let metadata = null;
if (event.metadata != null) {
metadata = event.metadata;
// $FlowFixMe: metadata is not writable and nullable
delete event.metadata;
}
loggingIFrame.contentWindow.postMessage(
Expand All @@ -42,7 +43,8 @@ export function registerDevToolsEventLogger(
version: process.env.DEVTOOLS_VERSION,
metadata: metadata !== null ? JSON.stringify(metadata) : '',
...(fetchAdditionalContext != null
? await fetchAdditionalContext()
? // $FlowFixMe
await fetchAdditionalContext()
: {}),
},
},
Expand Down
6 changes: 3 additions & 3 deletions packages/react-devtools-shared/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ const encodedStringCache: LRUCache<string, Array<number>> = new LRU({
});

export function alphaSortKeys(
a: string | number | Symbol,
b: string | number | Symbol,
a: string | number | symbol,
b: string | number | symbol,
): number {
if (a.toString() > b.toString()) {
return 1;
Expand All @@ -81,7 +81,7 @@ export function alphaSortKeys(

export function getAllEnumerableKeys(
obj: Object,
): Set<string | number | Symbol> {
): Set<string | number | symbol> {
const keys = new Set();
let current = obj;
while (current != null) {
Expand Down
31 changes: 24 additions & 7 deletions packages/react-dom/src/events/SyntheticEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ let lastMouseEvent;
function updateMouseMovementPolyfillState(event) {
if (event !== lastMouseEvent) {
if (lastMouseEvent && event.type === 'mousemove') {
// $FlowFixMe assuming this is a number
lastMovementX = event.screenX - lastMouseEvent.screenX;
// $FlowFixMe assuming this is a number
lastMovementY = event.screenY - lastMouseEvent.screenY;
} else {
lastMovementX = 0;
Expand Down Expand Up @@ -367,15 +369,20 @@ function getEventKey(nativeEvent) {

// FireFox implements `key` but returns `MozPrintableKey` for all
// printable characters (normalized to `Unidentified`), ignore it.
const key = normalizeKey[nativeEvent.key] || nativeEvent.key;
const key =
// $FlowFixMe unable to index with a `mixed` value
normalizeKey[nativeEvent.key] || nativeEvent.key;
if (key !== 'Unidentified') {
return key;
}
}

// Browser does not implement `key`, polyfill as much of it as we can.
if (nativeEvent.type === 'keypress') {
const charCode = getEventCharCode(nativeEvent);
const charCode = getEventCharCode(
// $FlowFixMe unable to narrow to `KeyboardEvent`
nativeEvent,
);

// The enter-key is technically both printable and non-printable and can
// thus be captured by `keypress`, no other non-printable key should.
Expand All @@ -384,6 +391,7 @@ function getEventKey(nativeEvent) {
if (nativeEvent.type === 'keydown' || nativeEvent.type === 'keyup') {
// While user keyboard layout determines the actual meaning of each
// `keyCode` value, almost all function keys have a universal value.
// $FlowFixMe unable to index with a `mixed` value
return translateToKey[nativeEvent.keyCode] || 'Unidentified';
}
return '';
Expand Down Expand Up @@ -441,7 +449,10 @@ const KeyboardEventInterface = {
// KeyPress is deprecated, but its replacement is not yet final and not
// implemented in any major browser. Only KeyPress has charCode.
if (event.type === 'keypress') {
return getEventCharCode(event);
return getEventCharCode(
// $FlowFixMe unable to narrow to `KeyboardEvent`
event,
);
}
return 0;
},
Expand All @@ -462,7 +473,10 @@ const KeyboardEventInterface = {
// `which` is an alias for either `keyCode` or `charCode` depending on the
// type of the event.
if (event.type === 'keypress') {
return getEventCharCode(event);
return getEventCharCode(
// $FlowFixMe unable to narrow to `KeyboardEvent`
event,
);
}
if (event.type === 'keydown' || event.type === 'keyup') {
return event.keyCode;
Expand Down Expand Up @@ -538,18 +552,21 @@ const WheelEventInterface = {
? event.deltaX
: // Fallback to `wheelDeltaX` for Webkit and normalize (right is positive).
'wheelDeltaX' in event
? -event.wheelDeltaX
? // $FlowFixMe assuming this is a number
-event.wheelDeltaX
: 0;
},
deltaY(event) {
return 'deltaY' in event
? event.deltaY
: // Fallback to `wheelDeltaY` for Webkit and normalize (down is positive).
'wheelDeltaY' in event
? -event.wheelDeltaY
? // $FlowFixMe assuming this is a number
-event.wheelDeltaY
: // Fallback to `wheelDelta` for IE<9 and normalize (down is positive).
'wheelDelta' in event
? -event.wheelDelta
? // $FlowFixMe assuming this is a number
-event.wheelDelta
: 0;
},
deltaZ: 0,
Expand Down
4 changes: 2 additions & 2 deletions packages/react-dom/src/server/ReactDOMFizzServerBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ function renderToReadableStream(
const stream: ReactDOMServerReadableStream = (new ReadableStream(
{
type: 'bytes',
pull(controller) {
pull(controller): ?Promise<void> {
startFlowing(request, controller);
},
cancel(reason) {
cancel(reason): ?Promise<void> {
abort(request);
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/server/ReactDOMFizzStaticBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function prerender(
const stream = new ReadableStream(
{
type: 'bytes',
pull(controller) {
pull(controller): ?Promise<void> {
startFlowing(request, controller);
},
},
Expand Down
1 change: 1 addition & 0 deletions packages/react-fetch/src/ReactFetchNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function nodeFetch(
// TODO: cherry-pick supported user-passed options.
};
const nodeImpl = protocol === 'https:' ? https : http;
// $FlowFixMe: node flow type has `port` as a number
const request = nodeImpl.request(nodeOptions, response => {
// TODO: support redirects.
onResolve(new Response(response));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ function accumulateInto<T>(
// certain that x is an Array (x could be a string with concat method).
if (isArray(current)) {
if (isArray(next)) {
// $FlowFixMe `isArray` does not ensure array is mutable
current.push.apply(current, next);
return current;
}
// $FlowFixMe `isArray` does not ensure array is mutable
current.push(next);
return current;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-noop-renderer/src/ReactNoopFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const ReactNoopFlightServer = ReactFlightServer({
},
resolveModuleMetaData(
config: void,
reference: {$$typeof: Symbol, value: any},
reference: {$$typeof: symbol, value: any},
) {
return saveModule(reference.value);
},
Expand Down
1 change: 1 addition & 0 deletions packages/react-reconciler/src/ReactChildFiber.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ if (__DEV__) {
);
}

// $FlowFixMe unable to narrow type from mixed to writable object
child._store.validated = true;

const componentName = getComponentNameFromFiber(returnFiber) || 'Component';
Expand Down
1 change: 1 addition & 0 deletions packages/react-reconciler/src/ReactChildFiber.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ if (__DEV__) {
);
}

// $FlowFixMe unable to narrow type from mixed to writable object
child._store.validated = true;

const componentName = getComponentNameFromFiber(returnFiber) || 'Component';
Expand Down
3 changes: 3 additions & 0 deletions packages/react-reconciler/src/ReactFiberCommitWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ function safelyDetachRef(current: Fiber, nearestMountedAncestor: Fiber | null) {
}
}
} else {
// $FlowFixMe unable to narrow type to RefObject
ref.current = null;
}
}
Expand Down Expand Up @@ -1522,6 +1523,7 @@ function commitAttachRef(finishedWork: Fiber) {
}
}

// $FlowFixMe unable to narrow type to the non-function case
ref.current = instanceToUse;
}
}
Expand All @@ -1542,6 +1544,7 @@ function commitDetachRef(current: Fiber) {
currentRef(null);
}
} else {
// $FlowFixMe unable to narrow type to the non-function case
currentRef.current = null;
}
}
Expand Down
3 changes: 3 additions & 0 deletions packages/react-reconciler/src/ReactFiberCommitWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ function safelyDetachRef(current: Fiber, nearestMountedAncestor: Fiber | null) {
}
}
} else {
// $FlowFixMe unable to narrow type to RefObject
ref.current = null;
}
}
Expand Down Expand Up @@ -1522,6 +1523,7 @@ function commitAttachRef(finishedWork: Fiber) {
}
}

// $FlowFixMe unable to narrow type to the non-function case
ref.current = instanceToUse;
}
}
Expand All @@ -1542,6 +1544,7 @@ function commitDetachRef(current: Fiber) {
currentRef(null);
}
} else {
// $FlowFixMe unable to narrow type to the non-function case
currentRef.current = null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export function markFailedErrorBoundaryForHotReloading(fiber: Fiber) {
return;
}
if (failedBoundaries === null) {
// $FlowFixMe Flow got confused by the feature check above.
failedBoundaries = new WeakSet();
}
failedBoundaries.add(fiber);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export function markFailedErrorBoundaryForHotReloading(fiber: Fiber) {
return;
}
if (failedBoundaries === null) {
// $FlowFixMe Flow got confused by the feature check above.
failedBoundaries = new WeakSet();
}
failedBoundaries.add(fiber);
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactTestSelectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if (typeof Symbol === 'function' && Symbol.for) {
TEXT_TYPE = symbolFor('selector.text');
}

type Type = Symbol | number;
type Type = symbol | number;

type ComponentSelector = {|
$$typeof: Type,
Expand Down
Loading