diff --git a/src/shared/utils/ReactFeatureFlags.js b/src/shared/utils/ReactFeatureFlags.js index 30b5f4c7de2e..5b3bb1b457bd 100644 --- a/src/shared/utils/ReactFeatureFlags.js +++ b/src/shared/utils/ReactFeatureFlags.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule ReactFeatureFlags + * @flow */ 'use strict'; diff --git a/src/shared/utils/ReactNodeTypes.js b/src/shared/utils/ReactNodeTypes.js index 7457b92661e5..2b5e40376d7a 100644 --- a/src/shared/utils/ReactNodeTypes.js +++ b/src/shared/utils/ReactNodeTypes.js @@ -7,10 +7,13 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule ReactNodeTypes + * @flow */ 'use strict'; +type ReactNodeType = 0 | 1 | 2; + var ReactElement = require('ReactElement'); var invariant = require('invariant'); @@ -20,7 +23,7 @@ var ReactNodeTypes = { COMPOSITE: 1, EMPTY: 2, - getType: function(node) { + getType: function(node: ReactElement): ReactNodeType { if (node === null || node === false) { return ReactNodeTypes.EMPTY; } else if (ReactElement.isValidElement(node)) { diff --git a/src/shared/utils/flattenChildren.js b/src/shared/utils/flattenChildren.js index b529f25c90ff..afb12d5a4655 100644 --- a/src/shared/utils/flattenChildren.js +++ b/src/shared/utils/flattenChildren.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule flattenChildren + * @flow */ 'use strict'; @@ -22,22 +23,29 @@ var warning = require('warning'); * @param {!string} name String name of key path to child. * @param {number=} selfDebugID Optional debugID of the current internal instance. */ -function flattenSingleChildIntoContext(traverseContext, child, name, selfDebugID) { +function flattenSingleChildIntoContext( + traverseContext: mixed, + child: ReactElement, + name: string, + selfDebugID: number +): void { // We found a component instance. - var result = traverseContext; - var keyUnique = (result[name] === undefined); - if (__DEV__) { - warning( - keyUnique, - 'flattenChildren(...): Encountered two children with the same key, ' + - '`%s`. Child keys must be unique; when two children share a key, only ' + - 'the first child will be used.%s', - KeyEscapeUtils.unescape(name), - ReactComponentTreeDevtool.getStackAddendumByID(selfDebugID) - ); - } - if (keyUnique && child != null) { - result[name] = child; + if (traverseContext && typeof traverseContext === 'object') { + const result = traverseContext; + const keyUnique = (result[name] === undefined); + if (__DEV__) { + warning( + keyUnique, + 'flattenChildren(...): Encountered two children with the same key, ' + + '`%s`. Child keys must be unique; when two children share a key, only ' + + 'the first child will be used.%s', + KeyEscapeUtils.unescape(name), + ReactComponentTreeDevtool.getStackAddendumByID(selfDebugID) + ); + } + if (keyUnique && child != null) { + result[name] = child; + } } } @@ -46,7 +54,7 @@ function flattenSingleChildIntoContext(traverseContext, child, name, selfDebugID * children will not be included in the resulting object. * @return {!object} flattened children keyed by name. */ -function flattenChildren(children, selfDebugID) { +function flattenChildren(children: ReactElement, selfDebugID: number): ?{ [name: string]: ReactElement } { if (children == null) { return children; } diff --git a/src/shared/utils/getIteratorFn.js b/src/shared/utils/getIteratorFn.js index 5da5c4846a0c..4ed780aa204e 100644 --- a/src/shared/utils/getIteratorFn.js +++ b/src/shared/utils/getIteratorFn.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule getIteratorFn + * @flow */ 'use strict'; @@ -29,7 +30,7 @@ var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec. * @param {?object} maybeIterable * @return {?function} */ -function getIteratorFn(maybeIterable) { +function getIteratorFn(maybeIterable: ?any): ?(p: ReactElement) => void { var iteratorFn = maybeIterable && ( (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL]) || maybeIterable[FAUX_ITERATOR_SYMBOL] diff --git a/src/shared/utils/reactProdInvariant.js b/src/shared/utils/reactProdInvariant.js index ca235bbeb9d2..ed61b59585ce 100644 --- a/src/shared/utils/reactProdInvariant.js +++ b/src/shared/utils/reactProdInvariant.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule reactProdInvariant + * @flow */ 'use strict'; @@ -16,7 +17,7 @@ * and will _only_ be required by the corresponding babel pass. * It always throws. */ -function reactProdInvariant(code) { +function reactProdInvariant(code: string): void { var argCount = arguments.length - 1; var message = ( @@ -33,7 +34,7 @@ function reactProdInvariant(code) { ' for full errors and additional helpful warnings.' ); - var error = new Error(message); + var error: Error & { framesToPop?: number } = new Error(message); error.name = 'Invariant Violation'; error.framesToPop = 1; // we don't care about reactProdInvariant's own frame