From 40a4feb6818cfd88e1589b5f94dd1b6623652503 Mon Sep 17 00:00:00 2001 From: Panos Vekris Date: Mon, 7 Oct 2024 19:18:14 -0700 Subject: [PATCH] replace '$TEMPORARY$string<>' with 'string' (#46876) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46876 * Used codemods of [this commit](https://www.internalfb.com/intern/commit/cloud/FBS/3a8982d63197fff7bac8b6d448545ec9660f331e) * `js1 flow-runner codemod flow/replaceTempStringWithString` * `js1 flow-runner codemod flow/simplifyUnionsOfString` Changelog: [internal] Reviewed By: SamChou19815 Differential Revision: D63991775 fbshipit-source-id: 5b9d1fdf045405230ca2b0969357ae92479692b5 --- packages/assets/path-support.js | 2 +- .../Keyboard/__tests__/Keyboard-test.js | 10 +---- .../Libraries/Core/setUpBatchedBridge.js | 11 +----- .../Libraries/JSInspector/NetworkAgent.js | 2 +- .../Libraries/LogBox/UI/LogBoxMessage.js | 4 +- .../Libraries/StyleSheet/processTransform.js | 37 ++----------------- .../__snapshots__/public-api-test.js.snap | 2 +- .../Accessibility/AccessibilityExample.js | 16 ++++---- 8 files changed, 19 insertions(+), 65 deletions(-) diff --git a/packages/assets/path-support.js b/packages/assets/path-support.js index 4ea50760fcd..3bcbfedd3f5 100644 --- a/packages/assets/path-support.js +++ b/packages/assets/path-support.js @@ -55,7 +55,7 @@ const drawableFileTypes = new Set([ function getAndroidResourceFolderName( asset: PackagerAsset, scale: number, -): string | $TEMPORARY$string<'raw'> { +): string { if (!drawableFileTypes.has(asset.type)) { return 'raw'; } diff --git a/packages/react-native/Libraries/Components/Keyboard/__tests__/Keyboard-test.js b/packages/react-native/Libraries/Components/Keyboard/__tests__/Keyboard-test.js index d3192afc7c7..d352aed059d 100644 --- a/packages/react-native/Libraries/Components/Keyboard/__tests__/Keyboard-test.js +++ b/packages/react-native/Libraries/Components/Keyboard/__tests__/Keyboard-test.js @@ -29,11 +29,7 @@ describe('Keyboard', () => { describe('scheduling layout animation', () => { const scheduleLayoutAnimation = ( duration: null | number, - easing: - | null - | $TEMPORARY$string<'linear'> - | $TEMPORARY$string<'some-unknown-animation-type'> - | $TEMPORARY$string<'spring'>, + easing: null | string, ): void => // $FlowFixMe[incompatible-call] Keyboard.scheduleLayoutAnimation({duration, easing}); @@ -60,9 +56,7 @@ describe('Keyboard', () => { }); describe('animation update type', () => { - const assertAnimationUpdateType = ( - type: $TEMPORARY$string<'keyboard'> | $TEMPORARY$string<'linear'>, - ) => + const assertAnimationUpdateType = (type: string) => expect(LayoutAnimation.configureNext).toHaveBeenCalledWith( expect.objectContaining({ duration: expect.anything(), diff --git a/packages/react-native/Libraries/Core/setUpBatchedBridge.js b/packages/react-native/Libraries/Core/setUpBatchedBridge.js index abac069677b..704a5feeb69 100644 --- a/packages/react-native/Libraries/Core/setUpBatchedBridge.js +++ b/packages/react-native/Libraries/Core/setUpBatchedBridge.js @@ -16,16 +16,7 @@ if (global.RN$Bridgeless === true && global.RN$registerCallableModule) { } else { const BatchedBridge = require('../BatchedBridge/BatchedBridge'); registerModule = ( - moduleName: - | $TEMPORARY$string<'GlobalPerformanceLogger'> - | $TEMPORARY$string<'HMRClient'> - | $TEMPORARY$string<'HeapCapture'> - | $TEMPORARY$string<'JSTimers'> - | $TEMPORARY$string<'RCTDeviceEventEmitter'> - | $TEMPORARY$string<'RCTLog'> - | $TEMPORARY$string<'RCTNativeAppEventEmitter'> - | $TEMPORARY$string<'SamplingProfiler'> - | $TEMPORARY$string<'Systrace'>, + moduleName: string, /* $FlowFixMe[missing-local-annot] The type annotation(s) required by * Flow's LTI update could not be added via codemod */ factory, diff --git a/packages/react-native/Libraries/JSInspector/NetworkAgent.js b/packages/react-native/Libraries/JSInspector/NetworkAgent.js index 5723af01de9..7a599d64aac 100644 --- a/packages/react-native/Libraries/JSInspector/NetworkAgent.js +++ b/packages/react-native/Libraries/JSInspector/NetworkAgent.js @@ -260,7 +260,7 @@ type EnableArgs = { }; class NetworkAgent extends InspectorAgent { - static DOMAIN: $TEMPORARY$string<'Network'> = 'Network'; + static DOMAIN: string = 'Network'; _sendEvent: EventSender; _interceptor: ?Interceptor; diff --git a/packages/react-native/Libraries/LogBox/UI/LogBoxMessage.js b/packages/react-native/Libraries/LogBox/UI/LogBoxMessage.js index 096960c0e68..1e1fcc24e8e 100644 --- a/packages/react-native/Libraries/LogBox/UI/LogBoxMessage.js +++ b/packages/react-native/Libraries/LogBox/UI/LogBoxMessage.js @@ -59,7 +59,7 @@ function TappableLinks(props: { // URLs were detected. Construct array of Text nodes. - let fragments: Array = []; + const fragments: Array = []; let indexCounter = 0; let startIndex = 0; @@ -115,7 +115,7 @@ function LogBoxMessage(props: Props): React.Node { const elements = []; let length = 0; const createUnderLength = ( - key: string | $TEMPORARY$string<'-1'>, + key: string, message: string, style: void | TextStyleProp, ) => { diff --git a/packages/react-native/Libraries/StyleSheet/processTransform.js b/packages/react-native/Libraries/StyleSheet/processTransform.js index 6310a4b5c77..0d9e72d724a 100644 --- a/packages/react-native/Libraries/StyleSheet/processTransform.js +++ b/packages/react-native/Libraries/StyleSheet/processTransform.js @@ -26,7 +26,7 @@ function processTransform( ): Array | Array { if (typeof transform === 'string') { const regex = new RegExp(/(\w+)\(([^)]+)\)/g); - let transformArray: Array = []; + const transformArray: Array = []; let matches; while ((matches = regex.exec(transform))) { @@ -50,23 +50,7 @@ function processTransform( } const _getKeyAndValueFromCSSTransform: ( - key: - | string - | $TEMPORARY$string<'matrix'> - | $TEMPORARY$string<'perspective'> - | $TEMPORARY$string<'rotate'> - | $TEMPORARY$string<'rotateX'> - | $TEMPORARY$string<'rotateY'> - | $TEMPORARY$string<'rotateZ'> - | $TEMPORARY$string<'scale'> - | $TEMPORARY$string<'scaleX'> - | $TEMPORARY$string<'scaleY'> - | $TEMPORARY$string<'skewX'> - | $TEMPORARY$string<'skewY'> - | $TEMPORARY$string<'translate'> - | $TEMPORARY$string<'translate3d'> - | $TEMPORARY$string<'translateX'> - | $TEMPORARY$string<'translateY'>, + key: string, args: string, ) => {key: string, value?: Array | number | string} = ( key, @@ -169,22 +153,7 @@ function _validateTransforms(transform: Array): void { } function _validateTransform( - key: - | string - | $TEMPORARY$string<'matrix'> - | $TEMPORARY$string<'perspective'> - | $TEMPORARY$string<'rotate'> - | $TEMPORARY$string<'rotateX'> - | $TEMPORARY$string<'rotateY'> - | $TEMPORARY$string<'rotateZ'> - | $TEMPORARY$string<'scale'> - | $TEMPORARY$string<'scaleX'> - | $TEMPORARY$string<'scaleY'> - | $TEMPORARY$string<'skewX'> - | $TEMPORARY$string<'skewY'> - | $TEMPORARY$string<'translate'> - | $TEMPORARY$string<'translateX'> - | $TEMPORARY$string<'translateY'>, + key: string, value: any | number | string, transformation: any, ) { diff --git a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap index 78185d4b309..5a8738f412c 100644 --- a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap +++ b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap @@ -5539,7 +5539,7 @@ type EnableArgs = { ... }; declare class NetworkAgent extends InspectorAgent { - static DOMAIN: $TEMPORARY$string<\\"Network\\">; + static DOMAIN: string; _sendEvent: EventSender; _interceptor: ?Interceptor; enable(EnableArgs): void; diff --git a/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js b/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js index 74394621d06..2848d48c6a4 100644 --- a/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js +++ b/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js @@ -500,7 +500,7 @@ class CheckboxExample extends React.Component< }; _onCheckboxPress = () => { - let checkboxState: boolean | $TEMPORARY$string<'mixed'> = false; + let checkboxState: boolean | string = false; if (this.state.checkboxState === false) { checkboxState = 'mixed'; } else if (this.state.checkboxState === 'mixed') { @@ -510,7 +510,7 @@ class CheckboxExample extends React.Component< } this.setState({ - checkboxState: checkboxState, + checkboxState, }); }; @@ -548,7 +548,7 @@ class SwitchExample extends React.Component< const switchState = !this.state.switchState; this.setState({ - switchState: switchState, + switchState, }); }; @@ -601,7 +601,7 @@ class SelectionExample extends React.Component< if (!isEnabled) { accessibilityHint = 'use the button on the right to enable selection'; } - let buttonTitle = isEnabled ? 'Disable selection' : 'Enable selection'; + const buttonTitle = isEnabled ? 'Disable selection' : 'Enable selection'; const touchableHint = ` (touching the TouchableOpacity will ${ isSelected ? 'disable' : 'enable' } accessibilityState.selected)`; @@ -667,7 +667,7 @@ class ExpandableElementExample extends React.Component< const expandState = !this.state.expandState; this.setState({ - expandState: expandState, + expandState, }); }; @@ -719,7 +719,7 @@ class NestedCheckBox extends React.Component< } setTimeout(() => { this.setState({ - checkbox1: checkbox1, + checkbox1, checkbox2: checkbox1, checkbox3: checkbox1, }); @@ -730,7 +730,7 @@ class NestedCheckBox extends React.Component< const checkbox2 = !this.state.checkbox2; this.setState({ - checkbox2: checkbox2, + checkbox2, checkbox1: checkbox2 && this.state.checkbox3 ? true @@ -744,7 +744,7 @@ class NestedCheckBox extends React.Component< const checkbox3 = !this.state.checkbox3; this.setState({ - checkbox3: checkbox3, + checkbox3, checkbox1: this.state.checkbox2 && checkbox3 ? true