diff --git a/.eslintrc.js b/.eslintrc.js index 51c9395f73c..cd308d281a7 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -19,6 +19,7 @@ module.exports = { 'no-for-of-loops', 'react', 'react-internal', + 'flowtype', ], parser: 'espree', @@ -89,6 +90,7 @@ module.exports = { 'react-internal/no-primitive-constructors': ERROR, 'react-internal/no-to-warn-dev-within-to-throw': ERROR, 'react-internal/warning-and-invariant-args': ERROR, + 'flowtype/no-types-missing-file-annotation': ERROR, }, overrides: [ diff --git a/packages/events/EventPropagators.js b/packages/events/EventPropagators.js index 5163c2b7a3f..a53d33c7005 100644 --- a/packages/events/EventPropagators.js +++ b/packages/events/EventPropagators.js @@ -3,8 +3,15 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. + * + * @flow */ +import type {Fiber} from 'react-reconciler/src/ReactFiber'; +import type { + ReactSyntheticEvent, + DispatchConfig, +} from './ReactSyntheticEventType'; import { getParentInstance, traverseTwoPhase, @@ -106,24 +113,33 @@ function accumulateDispatches(inst, ignoredDirection, event) { * `dispatchMarker`. * @param {SyntheticEvent} event */ -function accumulateDirectDispatchesSingle(event) { +function accumulateDirectDispatchesSingle(event: ReactSyntheticEvent) { if (event && event.dispatchConfig.registrationName) { accumulateDispatches(event._targetInst, null, event); } } -export function accumulateTwoPhaseDispatches(events) { +export function accumulateTwoPhaseDispatches( + events: Array, +) { forEachAccumulated(events, accumulateTwoPhaseDispatchesSingle); } -export function accumulateTwoPhaseDispatchesSkipTarget(events) { +export function accumulateTwoPhaseDispatchesSkipTarget( + events: Array, +) { forEachAccumulated(events, accumulateTwoPhaseDispatchesSingleSkipTarget); } -export function accumulateEnterLeaveDispatches(leave, enter, from, to) { +export function accumulateEnterLeaveDispatches( + leave: DispatchConfig, + enter: DispatchConfig, + from: Fiber, + to: Fiber, +) { traverseEnterLeave(from, to, accumulateDispatches, leave, enter); } -export function accumulateDirectDispatches(events) { +export function accumulateDirectDispatches(events: Array) { forEachAccumulated(events, accumulateDirectDispatchesSingle); } diff --git a/packages/events/ReactSyntheticEventType.js b/packages/events/ReactSyntheticEventType.js index 07ddf270f2e..849dcb9b3e5 100644 --- a/packages/events/ReactSyntheticEventType.js +++ b/packages/events/ReactSyntheticEventType.js @@ -30,4 +30,7 @@ export type ReactSyntheticEvent = { nativeEventTarget: EventTarget, ) => ReactSyntheticEvent, isPersistent: () => boolean, + _targetInst: Fiber, + _dispatchListeners: ReactSyntheticEvent | Array, + _dispatchInstances: Fiber | Array, } & SyntheticEvent<>; diff --git a/packages/react-art/src/ReactARTHostConfig.js b/packages/react-art/src/ReactARTHostConfig.js index 034b2d7290a..5bc78277f8b 100644 --- a/packages/react-art/src/ReactARTHostConfig.js +++ b/packages/react-art/src/ReactARTHostConfig.js @@ -421,6 +421,6 @@ export function unhideInstance(instance, props) { } } -export function unhideTextInstance(textInstance, text): void { +export function unhideTextInstance(textInstance, text) { // Noop } diff --git a/packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js b/packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js index 8879bca9987..f876196d049 100644 --- a/packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js +++ b/packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @emails react-core + * @flow */ 'use strict'; diff --git a/packages/react-dom/src/__tests__/ReactCompositeComponent-test.js b/packages/react-dom/src/__tests__/ReactCompositeComponent-test.js index 43ac793cf59..69451536629 100644 --- a/packages/react-dom/src/__tests__/ReactCompositeComponent-test.js +++ b/packages/react-dom/src/__tests__/ReactCompositeComponent-test.js @@ -9,6 +9,8 @@ 'use strict'; +import shallowEqual from 'shared/shallowEqual'; + let ChildUpdates; let MorphingComponent; let React; @@ -19,41 +21,6 @@ let ReactTestUtils; let PropTypes; describe('ReactCompositeComponent', () => { - const hasOwnProperty = Object.prototype.hasOwnProperty; - - /** - * Performs equality by iterating through keys on an object and returning false - * when any key has values which are not strictly equal between the arguments. - * Returns true when the values of all keys are strictly equal. - */ - function shallowEqual(objA: mixed, objB: mixed): boolean { - if (Object.is(objA, objB)) { - return true; - } - if ( - typeof objA !== 'object' || - objA === null || - typeof objB !== 'object' || - objB === null - ) { - return false; - } - const keysA = Object.keys(objA); - const keysB = Object.keys(objB); - if (keysA.length !== keysB.length) { - return false; - } - for (let i = 0; i < keysA.length; i++) { - if ( - !hasOwnProperty.call(objB, keysA[i]) || - !Object.is(objA[keysA[i]], objB[keysA[i]]) - ) { - return false; - } - } - return true; - } - function shallowCompare(instance, nextProps, nextState) { return ( !shallowEqual(instance.props, nextProps) || diff --git a/packages/react-dom/src/events/BeforeInputEventPlugin.js b/packages/react-dom/src/events/BeforeInputEventPlugin.js index 6895e0dc625..d7105bc47a5 100644 --- a/packages/react-dom/src/events/BeforeInputEventPlugin.js +++ b/packages/react-dom/src/events/BeforeInputEventPlugin.js @@ -3,6 +3,8 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. + * + * @flow */ import type {TopLevelType} from 'events/TopLevelEventTypes'; diff --git a/packages/react-dom/src/shared/DOMNamespaces.js b/packages/react-dom/src/shared/DOMNamespaces.js index ca0e8fb3770..f19aa6e1ff8 100644 --- a/packages/react-dom/src/shared/DOMNamespaces.js +++ b/packages/react-dom/src/shared/DOMNamespaces.js @@ -3,6 +3,8 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. + * + * @flow */ const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml'; diff --git a/packages/react-dom/src/shared/assertValidProps.js b/packages/react-dom/src/shared/assertValidProps.js index 9fe255b58da..59045e80e36 100644 --- a/packages/react-dom/src/shared/assertValidProps.js +++ b/packages/react-dom/src/shared/assertValidProps.js @@ -3,6 +3,8 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. + * + * @flow */ import invariant from 'shared/invariant'; @@ -31,7 +33,7 @@ function assertValidProps(tag: string, props: ?Object) { '%s is a void element tag and must neither have `children` nor ' + 'use `dangerouslySetInnerHTML`.%s', tag, - __DEV__ ? ReactDebugCurrentFrame.getStackAddendum() : '', + __DEV__ && ReactDebugCurrentFrame ? ReactDebugCurrentFrame.getStackAddendum() : '', ); } if (props.dangerouslySetInnerHTML != null) { @@ -63,7 +65,7 @@ function assertValidProps(tag: string, props: ?Object) { 'The `style` prop expects a mapping from style properties to values, ' + "not a string. For example, style={{marginRight: spacing + 'em'}} when " + 'using JSX.%s', - __DEV__ ? ReactDebugCurrentFrame.getStackAddendum() : '', + __DEV__ && ReactDebugCurrentFrame ? ReactDebugCurrentFrame.getStackAddendum() : '', ); } diff --git a/packages/react-native-renderer/src/__mocks__/deepDiffer.js b/packages/react-native-renderer/src/__mocks__/deepDiffer.js index a4ede524658..88111330ed4 100644 --- a/packages/react-native-renderer/src/__mocks__/deepDiffer.js +++ b/packages/react-native-renderer/src/__mocks__/deepDiffer.js @@ -3,6 +3,8 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. + * + * @flow */ 'use strict'; diff --git a/packages/react/src/ReactLazy.js b/packages/react/src/ReactLazy.js index 28415fcf265..4b8eb08df29 100644 --- a/packages/react/src/ReactLazy.js +++ b/packages/react/src/ReactLazy.js @@ -3,13 +3,17 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. + * + * @flow */ import type {LazyComponent, Thenable} from 'shared/ReactLazyComponent'; import {REACT_LAZY_TYPE} from 'shared/ReactSymbols'; -export function lazy(ctor: () => Thenable): LazyComponent { +export function lazy( + ctor: () => Thenable<{default: T}, mixed>, +): LazyComponent { return { $$typeof: REACT_LAZY_TYPE, _ctor: ctor, diff --git a/packages/react/src/forwardRef.js b/packages/react/src/forwardRef.js index c2617e4eef9..63fd7ae495c 100644 --- a/packages/react/src/forwardRef.js +++ b/packages/react/src/forwardRef.js @@ -3,6 +3,8 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. + * + * @flow */ import {REACT_FORWARD_REF_TYPE, REACT_MEMO_TYPE} from 'shared/ReactSymbols'; diff --git a/packages/react/src/memo.js b/packages/react/src/memo.js index 0fda3a8f67e..83f02e77462 100644 --- a/packages/react/src/memo.js +++ b/packages/react/src/memo.js @@ -3,6 +3,8 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. + * + * @flow */ import {REACT_MEMO_TYPE} from 'shared/ReactSymbols'; diff --git a/packages/scheduler/src/Scheduler.js b/packages/scheduler/src/Scheduler.js index c815d0071bd..f080a503839 100644 --- a/packages/scheduler/src/Scheduler.js +++ b/packages/scheduler/src/Scheduler.js @@ -98,7 +98,7 @@ function flushFirstCallback() { // A callback may return a continuation. The continuation should be scheduled // with the same priority and expiration as the just-finished callback. if (typeof continuationCallback === 'function') { - var continuationNode: CallbackNode = { + var continuationNode = { callback: continuationCallback, priorityLevel, expirationTime, diff --git a/packages/scheduler/src/__tests__/SchedulerDOM-test.js b/packages/scheduler/src/__tests__/SchedulerDOM-test.js index 562113f65bb..9c7b1b37547 100644 --- a/packages/scheduler/src/__tests__/SchedulerDOM-test.js +++ b/packages/scheduler/src/__tests__/SchedulerDOM-test.js @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @emails react-core + * @flow */ 'use strict'; diff --git a/packages/shared/ReactLazyComponent.js b/packages/shared/ReactLazyComponent.js index f3042ab11ae..2033a7fad9e 100644 --- a/packages/shared/ReactLazyComponent.js +++ b/packages/shared/ReactLazyComponent.js @@ -14,7 +14,7 @@ export type Thenable = { export type LazyComponent = { $$typeof: Symbol | number, _ctor: () => Thenable<{default: T}, mixed>, - _status: 0 | 1 | 2, + _status: -1 | 0 | 1 | 2, // TODO: what status is -1? _result: any, }; diff --git a/packages/shared/forks/invokeGuardedCallbackImpl.www.js b/packages/shared/forks/invokeGuardedCallbackImpl.www.js index c624679a8a7..2a0452e6065 100644 --- a/packages/shared/forks/invokeGuardedCallbackImpl.www.js +++ b/packages/shared/forks/invokeGuardedCallbackImpl.www.js @@ -3,11 +3,14 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. + * + * @flow */ import invariant from 'shared/invariant'; // Provided by www +// $FlowIssue const ReactFbErrorUtils = require('ReactFbErrorUtils'); invariant( typeof ReactFbErrorUtils.invokeGuardedCallback === 'function',