From 23a160ebf66f6aac306f8db90ff79b945fe76ce2 Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Fri, 6 May 2022 15:53:13 -0700 Subject: [PATCH] Lock down constrain writes in some directories Summary: Changelog: [internal] Reviewed By: gkz Differential Revision: D36214426 fbshipit-source-id: 8498ef0f646d8a38e5d523f4fd2deacf1b649fd2 --- IntegrationTests/AsyncStorageTest.js | 2 +- Libraries/Image/Image.android.js | 6 +++--- Libraries/Image/Image.ios.js | 7 ++++--- Libraries/Lists/VirtualizedList.js | 10 +++++----- Libraries/LogBox/Data/parseLogBoxLog.js | 2 +- Libraries/LogBox/LogBox.js | 2 +- .../Utilities/__tests__/setAndForwardRef-test.js | 4 ++-- .../js/components/RNTesterSettingSwitchRow.js | 15 +++++---------- 8 files changed, 22 insertions(+), 26 deletions(-) diff --git a/IntegrationTests/AsyncStorageTest.js b/IntegrationTests/AsyncStorageTest.js index 63697aedfec..f3aa7ce8052 100644 --- a/IntegrationTests/AsyncStorageTest.js +++ b/IntegrationTests/AsyncStorageTest.js @@ -207,7 +207,7 @@ class AsyncStorageTest extends React.Component<{...}, $FlowFixMeState> { this.setState({done: true}, () => { TestModule.markTestCompleted(); }); - updateMessage = msg => { + updateMessage = (msg: string) => { this.setState({messages: this.state.messages.concat('\n' + msg)}); DEBUG && console.log(msg); }; diff --git a/Libraries/Image/Image.android.js b/Libraries/Image/Image.android.js index bce71527175..64c5fd30c81 100644 --- a/Libraries/Image/Image.android.js +++ b/Libraries/Image/Image.android.js @@ -123,7 +123,7 @@ export type ImageComponentStatics = $ReadOnly<{| * * See https://reactnative.dev/docs/image */ -let Image = (props: ImagePropsType, forwardedRef) => { +const BaseImage = (props: ImagePropsType, forwardedRef) => { let source = resolveAssetSource(props.source); const defaultSource = resolveAssetSource(props.defaultSource); const loadingIndicatorSource = resolveAssetSource( @@ -221,11 +221,11 @@ let Image = (props: ImagePropsType, forwardedRef) => { ); }; -Image = React.forwardRef< +let Image = React.forwardRef< ImagePropsType, | React.ElementRef | React.ElementRef, ->(Image); +>(BaseImage); if (ImageInjection.unstable_createImageComponent != null) { Image = ImageInjection.unstable_createImageComponent(Image); diff --git a/Libraries/Image/Image.ios.js b/Libraries/Image/Image.ios.js index deb54281ef2..b350a0f9414 100644 --- a/Libraries/Image/Image.ios.js +++ b/Libraries/Image/Image.ios.js @@ -102,7 +102,7 @@ export type ImageComponentStatics = $ReadOnly<{| * * See https://reactnative.dev/docs/image */ -let Image = (props: ImagePropsType, forwardedRef) => { +const BaseImage = (props: ImagePropsType, forwardedRef) => { const source = resolveAssetSource(props.source) || { uri: undefined, width: undefined, @@ -158,11 +158,12 @@ let Image = (props: ImagePropsType, forwardedRef) => { ); }; -Image = React.forwardRef< +const ImageForwardRef = React.forwardRef< ImagePropsType, React.ElementRef, ->(Image); +>(BaseImage); +let Image = ImageForwardRef; if (ImageInjection.unstable_createImageComponent != null) { Image = ImageInjection.unstable_createImageComponent(Image); } diff --git a/Libraries/Lists/VirtualizedList.js b/Libraries/Lists/VirtualizedList.js index fdf63b3198d..2043a18ba37 100644 --- a/Libraries/Lists/VirtualizedList.js +++ b/Libraries/Lists/VirtualizedList.js @@ -1875,15 +1875,15 @@ class VirtualizedList extends React.PureComponent { 'Tried to get frame for out of range index ' + index, ); const item = getItem(data, index); - let frame = item && this._frames[this._keyExtractor(item, index)]; + const frame = item && this._frames[this._keyExtractor(item, index)]; if (!frame || frame.index !== index) { if (getItemLayout) { - frame = getItemLayout(data, index); + /* $FlowFixMe[prop-missing] (>=0.63.0 site=react_native_fb) This comment + * suppresses an error found when Flow v0.63 was deployed. To see the error + * delete this comment and run Flow. */ + return getItemLayout(data, index); } } - /* $FlowFixMe[prop-missing] (>=0.63.0 site=react_native_fb) This comment - * suppresses an error found when Flow v0.63 was deployed. To see the error - * delete this comment and run Flow. */ return frame; }; diff --git a/Libraries/LogBox/Data/parseLogBoxLog.js b/Libraries/LogBox/Data/parseLogBoxLog.js index bf7ea56aa81..9771595cde4 100644 --- a/Libraries/LogBox/Data/parseLogBoxLog.js +++ b/Libraries/LogBox/Data/parseLogBoxLog.js @@ -316,7 +316,7 @@ export function parseLogBoxLog(args: $ReadOnlyArray): {| |} { const message = args[0]; let argsWithoutComponentStack = []; - let componentStack = []; + let componentStack: ComponentStack = []; // Extract component stack from warnings like "Some warning%s". if ( diff --git a/Libraries/LogBox/LogBox.js b/Libraries/LogBox/LogBox.js index 8a10f810694..e2af653bf31 100644 --- a/Libraries/LogBox/LogBox.js +++ b/Libraries/LogBox/LogBox.js @@ -39,7 +39,7 @@ if (__DEV__) { let originalConsoleError; let originalConsoleWarn; let consoleErrorImpl; - let consoleWarnImpl; + let consoleWarnImpl: (...args: Array) => void; let isLogBoxInstalled: boolean = false; diff --git a/Libraries/Utilities/__tests__/setAndForwardRef-test.js b/Libraries/Utilities/__tests__/setAndForwardRef-test.js index 882b06889b5..51c493dad3c 100644 --- a/Libraries/Utilities/__tests__/setAndForwardRef-test.js +++ b/Libraries/Utilities/__tests__/setAndForwardRef-test.js @@ -17,8 +17,8 @@ const ReactTestRenderer = require('react-test-renderer'); const setAndForwardRef = require('../setAndForwardRef'); describe('setAndForwardRef', () => { - let innerFuncCalled = false; - let outerFuncCalled = false; + let innerFuncCalled: ?boolean = false; + let outerFuncCalled: ?boolean = false; class ForwardedComponent extends React.Component<{||}> { testFunc() { diff --git a/packages/rn-tester/js/components/RNTesterSettingSwitchRow.js b/packages/rn-tester/js/components/RNTesterSettingSwitchRow.js index 5b84fe71acb..22341cfbf28 100644 --- a/packages/rn-tester/js/components/RNTesterSettingSwitchRow.js +++ b/packages/rn-tester/js/components/RNTesterSettingSwitchRow.js @@ -47,15 +47,10 @@ const styles = StyleSheet.create({ justifyContent: 'space-between', }, }); -/* $FlowFixMe[cannot-reassign-export] (>=0.85.0 site=react_native_fb) This - * comment suppresses an error found when Flow v0.85 was deployed. To see the - * error, delete this comment and run Flow. */ -// $FlowFixMe[cannot-reassign] -RNTesterSettingSwitchRow = RNTesterStatePersister.createContainer( - RNTesterSettingSwitchRow, - { + +const RNTesterSettingSwitchRowContainer: React.ComponentType<$FlowFixMeProps> = + RNTesterStatePersister.createContainer(RNTesterSettingSwitchRow, { cacheKeySuffix: ({label}) => 'Switch:' + label, getInitialState: ({initialValue}) => initialValue, - }, -); -module.exports = RNTesterSettingSwitchRow; + }); +module.exports = RNTesterSettingSwitchRowContainer;