Update Flow to 0.70 (#12875)
* Update Flow to 0.70 * Remove unnecessary condition * Fix wrong assertion * Strict check
Dan Abramov committed
May 21, 2018 at 17:54 UTC
dd5fad29616f706f484938663e93aaadd2a5e594
16 files changed
+63
-40
package.json
+1
-1
@@ -60,7 +60,7 @@
60
"fbjs": "^0.8.16",
61
"fbjs-scripts": "^0.6.0",
62
"filesize": "^3.5.6",
63
- "flow-bin": "^0.61.0",
63
+ "flow-bin": "^0.72.0",
64
"flow-coverage-report": "^0.4.0",
65
"git-branch": "^0.3.0",
66
"glob": "^6.0.4",
packages/react-dom/src/client/ReactDOM.js
+2
@@ -53,9 +53,11 @@ let didWarnAboutUnstableCreatePortal = false;
53
if (__DEV__) {
54
if (
55
typeof Map !== 'function' ||
56
+ // $FlowIssue Flow incorrectly thinks Map has no prototype
57
Map.prototype == null ||
58
typeof Map.prototype.forEach !== 'function' ||
59
typeof Set !== 'function' ||
60
+ // $FlowIssue Flow incorrectly thinks Set has no prototype
61
Set.prototype == null ||
62
typeof Set.prototype.clear !== 'function' ||
63
typeof Set.prototype.forEach !== 'function'
packages/react-dom/src/client/ReactDOMFiberComponent.js
+10
-2
@@ -432,7 +432,11 @@ export function setInitialProperties(
432
const isCustomComponentTag = isCustomComponent(tag, rawProps);
433
if (__DEV__) {
434
validatePropertiesInDevelopment(tag, rawProps);
435
- if (isCustomComponentTag && !didWarnShadyDOM && domElement.shadyRoot) {
435
+ if (
436
+ isCustomComponentTag &&
437
+ !didWarnShadyDOM &&
438
+ (domElement: any).shadyRoot
439
+ ) {
440
warning(
441
false,
442
'%s is using shady DOM. Using shady DOM with React can ' +
@@ -820,7 +824,11 @@ export function diffHydratedProperties(
824
suppressHydrationWarning = rawProps[SUPPRESS_HYDRATION_WARNING] === true;
825
isCustomComponentTag = isCustomComponent(tag, rawProps);
826
validatePropertiesInDevelopment(tag, rawProps);
823
- if (isCustomComponentTag && !didWarnShadyDOM && domElement.shadyRoot) {
827
+ if (
828
+ isCustomComponentTag &&
829
+ !didWarnShadyDOM &&
830
+ (domElement: any).shadyRoot
831
+ ) {
832
warning(
833
false,
834
'%s is using shady DOM. Using shady DOM with React can ' +
packages/react-dom/src/client/ReactDOMHostConfig.js
+1
@@ -30,6 +30,7 @@ export type Props = {
30
children?: mixed,
31
hidden?: boolean,
32
suppressHydrationWarning?: boolean,
33
+ dangerouslySetInnerHTML?: mixed,
34
};
35
export type Container = Element | Document;
36
export type Instance = Element;
packages/react-dom/src/client/inputValueTracking.js
+4
-3
@@ -63,20 +63,21 @@ function trackValueOnNode(node: any): ?ValueTracker {
63
// (needed for certain tests that spyOn input values and Safari)
64
if (
65
node.hasOwnProperty(valueField) ||
66
+ typeof descriptor === 'undefined' ||
67
typeof descriptor.get !== 'function' ||
68
typeof descriptor.set !== 'function'
69
) {
70
return;
71
}
71
-
72
+ const {get, set} = descriptor;
73
Object.defineProperty(node, valueField, {
74
configurable: true,
75
get: function() {
75
- return descriptor.get.call(this);
76
+ return get.call(this);
77
},
78
set: function(value) {
79
currentValue = '' + value;
79
- descriptor.set.call(this, value);
80
+ set.call(this, value);
81
},
82
});
83
// We could've passed this the first time
packages/react-dom/src/events/TapEventPlugin.js
+5
-4
@@ -119,10 +119,11 @@ const pointerEvents = [
119
TOP_POINTER_UP,
120
];
121
122
-const dependencies = [TOP_MOUSE_DOWN, TOP_MOUSE_MOVE, TOP_MOUSE_UP].concat(
123
- touchEvents,
124
- pointerEvents,
125
-);
122
+const dependencies: Array<TopLevelType> = [
123
+ TOP_MOUSE_DOWN,
124
+ TOP_MOUSE_MOVE,
125
+ TOP_MOUSE_UP,
126
+].concat(touchEvents, pointerEvents);
127
128
const eventTypes = {
129
touchTap: {
packages/react-native-renderer/src/ReactFabric.js
+4
-2
@@ -63,9 +63,11 @@ function findNodeHandle(componentOrHandle: any): ?number {
63
if (hostInstance == null) {
64
return hostInstance;
65
}
66
- if (hostInstance.canonical) {
66
+ // TODO: the code is right but the types here are wrong.
67
+ // https://github.com/facebook/react/pull/12863
68
+ if ((hostInstance: any).canonical) {
69
// Fabric
68
- return (hostInstance.canonical: any)._nativeTag;
70
+ return (hostInstance: any).canonical._nativeTag;
71
}
72
return hostInstance._nativeTag;
73
}
packages/react-native-renderer/src/ReactNativeFrameScheduling.js
+3
-2
@@ -49,12 +49,13 @@ function scheduleDeferredCallback(
49
): number {
50
// We assume only one callback is scheduled at a time b'c that's how Fiber works.
51
scheduledCallback = callback;
52
- return setTimeout(setTimeoutCallback, 1);
52
+ const timeoutId = setTimeout(setTimeoutCallback, 1);
53
+ return (timeoutId: any); // Timeouts are always numbers on RN
54
}
55
56
function cancelDeferredCallback(callbackID: number) {
57
scheduledCallback = null;
57
- clearTimeout(callbackID);
58
+ clearTimeout((callbackID: any)); // Timeouts are always numbers on RN
59
}
60
61
export {now, scheduleDeferredCallback, cancelDeferredCallback};
packages/react-native-renderer/src/ReactNativeRenderer.js
+2
-2
@@ -66,9 +66,9 @@ function findNodeHandle(componentOrHandle: any): ?number {
66
if (hostInstance == null) {
67
return hostInstance;
68
}
69
- if (hostInstance.canonical) {
69
+ if ((hostInstance: any).canonical) {
70
// Fabric
71
- return (hostInstance.canonical: any)._nativeTag;
71
+ return (hostInstance: any).canonical._nativeTag;
72
}
73
return hostInstance._nativeTag;
74
}
packages/react-noop-renderer/src/createReactNoop.js
+1
-1
@@ -23,7 +23,7 @@ import emptyObject from 'fbjs/lib/emptyObject';
23
import expect from 'expect';
24
25
type Container = {rootID: string, children: Array<Instance | TextInstance>};
26
-type Props = {prop: any, hidden?: boolean};
26
+type Props = {prop: any, hidden?: boolean, children?: mixed};
27
type Instance = {|
28
type: string,
29
id: number,
packages/react-reconciler/src/ReactChildFiber.js
+10
-12
@@ -151,6 +151,7 @@ function coerceRef(
151
if (
152
current !== null &&
153
current.ref !== null &&
154
+ typeof current.ref === 'function' &&
155
current.ref._stringRef === stringRef
156
) {
157
return current.ref;
@@ -901,18 +902,15 @@ function ChildReconciler(shouldTrackSideEffects) {
902
903
if (__DEV__) {
904
// Warn about using Maps as children
904
- if (typeof newChildrenIterable.entries === 'function') {
905
- const possibleMap = (newChildrenIterable: any);
906
- if (possibleMap.entries === iteratorFn) {
907
- warning(
908
- didWarnAboutMaps,
909
- 'Using Maps as children is unsupported and will likely yield ' +
910
- 'unexpected results. Convert it to a sequence/iterable of keyed ' +
911
- 'ReactElements instead.%s',
912
- getCurrentFiberStackAddendum(),
913
- );
914
- didWarnAboutMaps = true;
915
- }
905
+ if ((newChildrenIterable: any).entries === iteratorFn) {
906
+ warning(
907
+ didWarnAboutMaps,
908
+ 'Using Maps as children is unsupported and will likely yield ' +
909
+ 'unexpected results. Convert it to a sequence/iterable of keyed ' +
910
+ 'ReactElements instead.%s',
911
+ getCurrentFiberStackAddendum(),
912
+ );
913
+ didWarnAboutMaps = true;
914
}
915
916
// First, validate keys.
packages/react-reconciler/src/ReactFiberContext.js
+1
-1
@@ -137,7 +137,7 @@ function pushTopLevelContextObject(
137
didChange: boolean,
138
): void {
139
invariant(
140
- contextStackCursor.cursor == null,
140
+ contextStackCursor.current === emptyObject,
141
'Unexpected context found on stack. ' +
142
'This error is likely caused by a bug in React. Please file an issue.',
143
);
packages/react-scheduler/src/ReactScheduler.js
+14
-4
@@ -60,14 +60,20 @@ let scheduleWork: (
60
callback: FrameCallbackType,
61
options?: {timeout: number},
62
) => number;
63
-let cancelScheduledWork: (callbackID: number) => void;
63
+let cancelScheduledWork: (callbackId: number) => void;
64
65
if (!ExecutionEnvironment.canUseDOM) {
66
+ let callbackIdCounter = 0;
67
+ // Timeouts are objects in Node.
68
+ // For consistency, we'll use numbers in the public API anyway.
69
+ const timeoutIds: {[number]: TimeoutID} = {};
70
+
71
scheduleWork = function(
72
callback: FrameCallbackType,
73
options?: {timeout: number},
74
): number {
70
- return setTimeout(() => {
75
+ const callbackId = callbackIdCounter++;
76
+ const timeoutId = setTimeout(() => {
77
callback({
78
timeRemaining() {
79
return Infinity;
@@ -75,9 +81,13 @@ if (!ExecutionEnvironment.canUseDOM) {
81
didTimeout: false,
82
});
83
});
84
+ timeoutIds[callbackId] = timeoutId;
85
+ return callbackId;
86
};
79
- cancelScheduledWork = function(timeoutID: number) {
80
- clearTimeout(timeoutID);
87
+ cancelScheduledWork = function(callbackId: number) {
88
+ const timeoutId = timeoutIds[callbackId];
89
+ delete timeoutIds[callbackId];
90
+ clearTimeout(timeoutId);
91
};
92
} else {
93
// We keep callbacks in a queue.
packages/react-test-renderer/src/ReactTestRenderer.js
+1
-1
@@ -414,7 +414,7 @@ const ReactTestRendererFiber = {
414
const entry = {
415
root: undefined, // makes flow happy
416
// we define a 'getter' for 'root' below using 'Object.defineProperty'
417
- toJSON() {
417
+ toJSON(): Array<ReactTestRendererNode> | ReactTestRendererNode | null {
418
if (root == null || root.current == null || container == null) {
419
return null;
420
}
scripts/flow/config/flowconfig
+1
-2
@@ -28,7 +28,6 @@ untyped-type-import=error
28
[options]
29
esproposal.class_static_fields=enable
30
esproposal.class_instance_fields=enable
31
-unsafe.enable_getters_and_setters=true
31
32
# Substituted by createFlowConfig.js:
33
%REACT_RENDERER_FLOW_OPTIONS%
@@ -46,4 +45,4 @@ suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
45
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
46
47
[version]
49
-^0.61.0
\ No newline at end of file
48
+^0.72.0
\ No newline at end of file
yarn.lock
+3
-3
@@ -2420,9 +2420,9 @@ flow-annotation-check@1.3.1:
2420
glob "7.1.1"
2421
load-pkg "^3.0.1"
2422
2423
-flow-bin@^0.61.0:
2424
- version "0.61.0"
2425
- resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.61.0.tgz#d0473a8c35dbbf4de573823f4932124397d32d35"
2423
+flow-bin@^0.72.0:
2424
+ version "0.72.0"
2425
+ resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.72.0.tgz#12051180fb2db7ccb728fefe67c77e955e92a44d"
2426
2427
flow-coverage-report@^0.4.0:
2428
version "0.4.0"