Skip to content

Commit

Permalink
Codemod {...null} to {} in xplat/js
Browse files Browse the repository at this point in the history
Summary:
Now that [exact_empty_objects has been enabled](https://fb.workplace.com/groups/flowlang/posts/1092665251339137), we can codemod `{...null}` to `{}` - they are now equivalent.

1) Run my one-off jscodeshift codemod
2) `scripts/flow/tool update-suppressions .` (as some suppressions move around due to the change)

drop-conflicts

Reviewed By: bradzacher

Differential Revision: D37834078

fbshipit-source-id: 6bf4913910e5597e5dd9d5161cd35deece6a7581
  • Loading branch information
gkz authored and facebook-github-bot committed Jul 15, 2022
1 parent 1e91445 commit f392ba6
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 41 deletions.
8 changes: 2 additions & 6 deletions Libraries/Animated/AnimatedImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,7 @@ const parallel = function (
): CompositeAnimation {
let doneCount = 0;
// Make sure we only call stop() at most once for each animation
const hasEnded = {
...null,
};
const hasEnded = {};
const stopTogether = !(config && config.stopTogether === false);

const result = {
Expand Down Expand Up @@ -463,9 +461,7 @@ type LoopAnimationConfig = {
const loop = function (
animation: CompositeAnimation,
// $FlowFixMe[prop-missing]
{iterations = -1, resetBeforeIteration = true}: LoopAnimationConfig = {
...null,
},
{iterations = -1, resetBeforeIteration = true}: LoopAnimationConfig = {},
): CompositeAnimation {
let isFinished = false;
let iterationsSoFar = 0;
Expand Down
4 changes: 1 addition & 3 deletions Libraries/Animated/AnimatedMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ type LoopAnimationConfig = {
const loop = function (
animation: CompositeAnimation,
// $FlowFixMe[prop-missing]
{iterations = -1}: LoopAnimationConfig = {
...null,
},
{iterations = -1}: LoopAnimationConfig = {},
): CompositeAnimation {
return emptyAnimation;
};
Expand Down
25 changes: 8 additions & 17 deletions Libraries/Animated/NativeAnimatedHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,8 @@ const useSingleOpBatching =
ReactNativeFeatureFlags.animatedShouldUseSingleOp();
let flushQueueTimeout = null;

const eventListenerGetValueCallbacks = {
...null,
};
const eventListenerAnimationFinishedCallbacks = {
...null,
};
const eventListenerGetValueCallbacks = {};
const eventListenerAnimationFinishedCallbacks = {};
let globalEventEmitterGetValueListener: ?EventSubscription = null;
let globalEventEmitterAnimationFinishedListener: ?EventSubscription = null;

Expand Down Expand Up @@ -82,17 +78,12 @@ const nativeOps: ?typeof NativeAnimatedModule = useSingleOpBatching
'addListener', // 20
'removeListener', // 21
];
return apis.reduce(
(acc, functionName, i) => {
// These indices need to be kept in sync with the indices in native (see NativeAnimatedModule in Java, or the equivalent for any other native platform).
// $FlowFixMe[prop-missing]
acc[functionName] = i + 1;
return acc;
},
{
...null,
},
);
return apis.reduce((acc, functionName, i) => {
// These indices need to be kept in sync with the indices in native (see NativeAnimatedModule in Java, or the equivalent for any other native platform).
// $FlowFixMe[prop-missing]
acc[functionName] = i + 1;
return acc;
}, {});
})(): $FlowFixMe)
: NativeAnimatedModule;

Expand Down
2 changes: 1 addition & 1 deletion Libraries/Components/TextInput/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ function InternalTextInput(props: Props): React.Node {
// that the update should be ignored and we should stick with the value
// that we have in JS.
useLayoutEffect(() => {
const nativeUpdate: {text?: string, selection?: Selection} = {...null};
const nativeUpdate: {text?: string, selection?: Selection} = {};

if (lastNativeText !== props.value && typeof props.value === 'string') {
nativeUpdate.text = props.value;
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Core/setUpPerformance.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'use strict';

if (!global.performance) {
global.performance = ({...null}: {now?: () => number});
global.performance = ({}: {now?: () => number});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Utilities/__tests__/stringifySafe-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('stringifySafe', () => {
});

it('stringifySafe stringifies circular objects with toString', () => {
const arg: {arg?: {...}} = {...null};
const arg: {arg?: {...}} = {};
arg.arg = arg;
const result = stringifySafe(arg);
expect(result).toEqual('[object Object]');
Expand Down
2 changes: 1 addition & 1 deletion Libraries/WebSocket/WebSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class WebSocket extends (EventTarget(...WEBSOCKET_EVENTS): any) {
protocols = [protocols];
}

const {headers = {}, ...unrecognized} = options || {...null};
const {headers = {}, ...unrecognized} = options || {};

// Preserve deprecated backwards compatibility for the 'origin' option
// $FlowFixMe[prop-missing]
Expand Down
2 changes: 1 addition & 1 deletion packages/rn-tester/js/components/RNTesterPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class RNTesterPage extends React.Component<Props> {
automaticallyAdjustContentInsets?: boolean,
keyboardShouldPersistTaps?: string,
keyboardDismissMode?: string,
} = {...null};
} = {};
if (this.props.noScroll) {
ContentWrapper = ((View: any): React.ComponentType<any>);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ const BOBBLE_SPOTS = [...Array(NUM_BOBBLES)].map((_, i) => {
class AnExBobble extends React.Component<Object, any> {
constructor(props: Object) {
super(props);
this.state = {
...null,
};
this.state = {};
// $FlowFixMe[prop-missing]
this.state.bobbles = BOBBLE_SPOTS.map((_, i) => {
return new Animated.ValueXY();
Expand Down Expand Up @@ -101,12 +99,7 @@ class AnExBobble extends React.Component<Object, any> {
<View style={styles.bobbleContainer}>
{this.state.bobbles.map((_, i) => {
const j = this.state.bobbles.length - i - 1; // reverse so lead on top
const handlers =
j > 0
? {
...null,
}
: this.state.bobbleResponder.panHandlers;
const handlers = j > 0 ? {} : this.state.bobbleResponder.panHandlers;
return (
<Animated.Image
{...handlers}
Expand Down
2 changes: 1 addition & 1 deletion packages/rn-tester/js/examples/Crash/CrashExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ exports.examples = [
<Button
title="JS crash"
onPress={() => {
const a = {...null};
const a = {};
// $FlowIgnore[prop-missing]
// $FlowIgnore[incompatible-use]
const b = a.w.q; // js crash here
Expand Down

0 comments on commit f392ba6

Please sign in to comment.