Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor flow const binding #18037

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,7 @@ suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError

experimental.const_params=true

[version]
^0.66.0
7 changes: 4 additions & 3 deletions IntegrationTests/AsyncStorageTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ function expectEqual(lhs, rhs, testname : string) {
}

function expectAsyncNoError(place, err) {
if (err instanceof Error) {
err = err.message;
let error = err;
if (error instanceof Error) {
error = error.message;
}
expectTrue(err === null, 'Unexpected error in ' + place + ': ' + JSON.stringify(err));
expectTrue(error === null, 'Unexpected error in ' + place + ': ' + JSON.stringify(err));
}

function testSetAndGet() {
Expand Down
16 changes: 8 additions & 8 deletions Libraries/Animated/src/AnimatedImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const spring = function(
configuration: SpringAnimationConfig,
callback?: ?EndCallback,
): void {
callback = _combineCallbacks(callback, configuration);
let mergedCallbacks = _combineCallbacks(callback, configuration);
const singleValue: any = animatedValue;
const singleConfig: any = configuration;
singleValue.stopTracking();
Expand All @@ -138,11 +138,11 @@ const spring = function(
configuration.toValue,
SpringAnimation,
singleConfig,
callback,
mergedCallbacks,
),
);
} else {
singleValue.animate(new SpringAnimation(singleConfig), callback);
singleValue.animate(new SpringAnimation(singleConfig), mergedCallbacks);
}
};
return (
Expand Down Expand Up @@ -180,7 +180,7 @@ const timing = function(
configuration: TimingAnimationConfig,
callback?: ?EndCallback,
): void {
callback = _combineCallbacks(callback, configuration);
let callbacks = _combineCallbacks(callback, configuration);
const singleValue: any = animatedValue;
const singleConfig: any = configuration;
singleValue.stopTracking();
Expand All @@ -191,11 +191,11 @@ const timing = function(
configuration.toValue,
TimingAnimation,
singleConfig,
callback,
callbacks,
),
);
} else {
singleValue.animate(new TimingAnimation(singleConfig), callback);
singleValue.animate(new TimingAnimation(singleConfig), callbacks);
}
};

Expand Down Expand Up @@ -234,11 +234,11 @@ const decay = function(
configuration: DecayAnimationConfig,
callback?: ?EndCallback,
): void {
callback = _combineCallbacks(callback, configuration);
let mergedCallbacks = _combineCallbacks(callback, configuration);
const singleValue: any = animatedValue;
const singleConfig: any = configuration;
singleValue.stopTracking();
singleValue.animate(new DecayAnimation(singleConfig), callback);
singleValue.animate(new DecayAnimation(singleConfig), mergedCallbacks);
};

return (
Expand Down
28 changes: 15 additions & 13 deletions Libraries/Animated/src/Easing.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,11 @@ class Easing {
* - http://tiny.cc/back_default (s = 1.70158, default)
*/
static back(s: number): (t: number) => number {
if (s === undefined) {
s = 1.70158;
let ss = s;
if (ss === undefined) {
ss = 1.70158;
}
return (t) => t * t * ((s + 1) * t - s);
return (t) => t * t * ((ss + 1) * t - ss);
}

/**
Expand All @@ -187,22 +188,23 @@ class Easing {
* http://easings.net/#easeInBounce
*/
static bounce(t: number): number {
if (t < 1 / 2.75) {
return 7.5625 * t * t;
let tt = t;
if (tt < 1 / 2.75) {
return 7.5625 * tt * tt;
}

if (t < 2 / 2.75) {
t -= 1.5 / 2.75;
return 7.5625 * t * t + 0.75;
if (tt < 2 / 2.75) {
tt -= 1.5 / 2.75;
return 7.5625 * tt * tt + 0.75;
}

if (t < 2.5 / 2.75) {
t -= 2.25 / 2.75;
return 7.5625 * t * t + 0.9375;
if (tt < 2.5 / 2.75) {
tt -= 2.25 / 2.75;
return 7.5625 * tt * tt + 0.9375;
}

t -= 2.625 / 2.75;
return 7.5625 * t * t + 0.984375;
tt -= 2.625 / 2.75;
return 7.5625 * tt * tt + 0.984375;
}

/**
Expand Down
11 changes: 6 additions & 5 deletions Libraries/Animated/src/nodes/AnimatedProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ class AnimatedProps extends AnimatedNode {

constructor(props: Object, callback: () => void) {
super();
if (props.style) {
props = {
...props,
style: new AnimatedStyle(props.style),
let propsTmp = props;
if (propsTmp.style) {
propsTmp = {
...propsTmp,
style: new AnimatedStyle(propsTmp.style),
};
}
this._props = props;
this._props = propsTmp;
this._callback = callback;
this.__attach();
}
Expand Down
12 changes: 6 additions & 6 deletions Libraries/Animated/src/nodes/AnimatedStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ class AnimatedStyle extends AnimatedWithChildren {

constructor(style: any) {
super();
style = flattenStyle(style) || {};
if (style.transform) {
style = {
...style,
transform: new AnimatedTransform(style.transform),
let styleTmp = flattenStyle(style) || {};
if (styleTmp.transform) {
styleTmp = {
...styleTmp,
transform: new AnimatedTransform(styleTmp.transform),
};
}
this._style = style;
this._style = styleTmp;
}

// Recursively get values for nested styles (like iOS's shadowOffset)
Expand Down
4 changes: 2 additions & 2 deletions Libraries/BatchedBridge/NativeModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ function genMethod(moduleID: number, methodID: number, type: MethodType) {
const onSuccess = hasSuccessCallback ? lastArg : null;
const onFail = hasErrorCallback ? secondLastArg : null;
const callbackCount = hasSuccessCallback + hasErrorCallback;
args = args.slice(0, args.length - callbackCount);
BatchedBridge.enqueueNativeCall(moduleID, methodID, args, onFail, onSuccess);
let argsArray = args.slice(0, args.length - callbackCount);
BatchedBridge.enqueueNativeCall(moduleID, methodID, argsArray, onFail, onSuccess);
};
}
fn.type = type;
Expand Down
20 changes: 11 additions & 9 deletions Libraries/Blob/Blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,21 @@ class Blob {
slice(start?: number, end?: number): Blob {
const BlobManager = require('BlobManager');
let {offset, size} = this.data;
let startVal = start;
let endVal = end;

if (typeof start === 'number') {
if (start > size) {
start = size;
if (typeof startVal === 'number') {
if (startVal > size) {
startVal = size;
}
offset += start;
size -= start;
offset += startVal;
size -= startVal;

if (typeof end === 'number') {
if (end < 0) {
end = this.size + end;
if (typeof endVal === 'number') {
if (endVal < 0) {
endVal = this.size + endVal;
}
size = end - start;
size = endVal - startVal;
}
}
return BlobManager.createFromOptions({
Expand Down
8 changes: 4 additions & 4 deletions Libraries/CameraRoll/ImagePickerIOS.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ var ImagePickerIOS = {
return RCTImagePicker.canUseCamera(callback);
},
openCameraDialog: function(config: Object, successCallback: Function, cancelCallback: Function) {
config = {
let configTmp = {
videoMode: false,
...config,
};
return RCTImagePicker.openCameraDialog(config, successCallback, cancelCallback);
return RCTImagePicker.openCameraDialog(configTmp, successCallback, cancelCallback);
},
openSelectDialog: function(config: Object, successCallback: Function, cancelCallback: Function) {
config = {
let configTmp = {
showImages: true,
showVideos: false,
...config,
};
return RCTImagePicker.openSelectDialog(config, successCallback, cancelCallback);
return RCTImagePicker.openSelectDialog(configTmp, successCallback, cancelCallback);
},
};

Expand Down
7 changes: 4 additions & 3 deletions Libraries/Components/Navigation/NavigatorIOS.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -732,11 +732,12 @@ var NavigatorIOS = createReactClass({
*/
replaceAtIndex: function(route: Route, index: number) {
invariant(!!route, 'Must supply route to replace');
if (index < 0) {
index += this.state.routeStack.length;
let idx = index;
if (idx < 0) {
idx += this.state.routeStack.length;
}

if (this.state.routeStack.length <= index) {
if (this.state.routeStack.length <= idx) {
return;
}

Expand Down
19 changes: 13 additions & 6 deletions Libraries/Components/ScrollResponder.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,15 +414,21 @@ const ScrollResponderMixin = {
y?: number,
animated?: boolean
) {
let params = {};
if (typeof x === 'number') {
console.warn('`scrollResponderScrollTo(x, y, animated)` is deprecated. Use `scrollResponderScrollTo({x: 5, y: 5, animated: true})` instead.');
} else {
({x, y, animated} = x || {});
params.x = x || 0;
params.y = y || 0;
params.animated = animated !== false;
} else if(typeof x === 'object') {
params.x = x.x || 0;
params.y = x.y || 0;
params.animated = x.animated !== false;
}
UIManager.dispatchViewManagerCommand(
nullthrows(this.scrollResponderGetScrollableNode()),
UIManager.RCTScrollView.Commands.scrollTo,
[x || 0, y || 0, animated !== false],
[params.x, params.y, params.animated],
);
},

Expand Down Expand Up @@ -465,13 +471,14 @@ const ScrollResponderMixin = {
animated?: boolean // deprecated, put this inside the rect argument instead
) {
invariant(ScrollViewManager && ScrollViewManager.zoomToRect, 'zoomToRect is not implemented');
let isAnimated = animated;
if ('animated' in rect) {
animated = rect.animated;
isAnimated = rect.animated;
delete rect.animated;
} else if (typeof animated !== 'undefined') {
} else if (typeof isAnimated !== 'undefined') {
console.warn('`scrollResponderZoomTo` `animated` argument is deprecated. Use `options.animated` instead');
}
ScrollViewManager.zoomToRect(this.scrollResponderGetScrollableNode(), rect, animated !== false);
ScrollViewManager.zoomToRect(this.scrollResponderGetScrollableNode(), rect, isAnimated !== false);
},

/**
Expand Down
16 changes: 11 additions & 5 deletions Libraries/Components/ScrollView/ScrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,15 +567,21 @@ const ScrollView = createReactClass({
x?: number,
animated?: boolean
) {
let params = {};
// animation is enabled by default
if (typeof y === 'number') {
console.warn('`scrollTo(y, x, animated)` is deprecated. Use `scrollTo({x: 5, y: 5, ' +
'animated: true})` instead.');
} else {
({x, y, animated} = y || {});
params.x = x || 0;
params.y = y || 0;
params.animated = animated !== false;
}
this.getScrollResponder().scrollResponderScrollTo(
{x: x || 0, y: y || 0, animated: animated !== false}
);
else if(typeof y === 'object') {
params.x = y.x || 0;
params.y = y.y || 0;
params.animated = y.animated !== false;
}
this.getScrollResponder().scrollResponderScrollTo(params);
},

/**
Expand Down
12 changes: 6 additions & 6 deletions Libraries/Components/StatusBar/StatusBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ class StatusBar extends React.Component<{
* changing the status bar hidden property.
*/
static setHidden(hidden: boolean, animation?: StatusBarAnimation) {
animation = animation || 'none';
let isAnimation = animation || 'none';
StatusBar._defaultProps.hidden.value = hidden;
if (Platform.OS === 'ios') {
StatusBarManager.setHidden(hidden, animation);
StatusBarManager.setHidden(hidden, isAnimation);
} else if (Platform.OS === 'android') {
StatusBarManager.setHidden(hidden);
}
Expand All @@ -208,10 +208,10 @@ class StatusBar extends React.Component<{
* @param animated Animate the style change.
*/
static setBarStyle(style: StatusBarStyle, animated?: boolean) {
animated = animated || false;
let isAnimated = animated || false;
StatusBar._defaultProps.barStyle.value = style;
if (Platform.OS === 'ios') {
StatusBarManager.setStyle(style, animated);
StatusBarManager.setStyle(style, isAnimated);
} else if (Platform.OS === 'android') {
StatusBarManager.setStyle(style);
}
Expand Down Expand Up @@ -242,9 +242,9 @@ class StatusBar extends React.Component<{
console.warn('`setBackgroundColor` is only available on Android');
return;
}
animated = animated || false;
let isAnimated = animated || false;
StatusBar._defaultProps.backgroundColor.value = color;
StatusBarManager.setColor(processColor(color), animated);
StatusBarManager.setColor(processColor(color), isAnimated);
}

/**
Expand Down
11 changes: 6 additions & 5 deletions Libraries/Core/ExceptionsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@ function handleException(e: Error, isFatal: boolean) {
// Unfortunately there is no way to figure out the stacktrace in this
// case, so if you ended up here trying to trace an error, look for
// `throw '<error message>'` somewhere in your codebase.
if (!e.message) {
e = new Error(e);
let error = e;
if (!error.message) {
error = new Error(error);
}
if (console._errorOriginal) {
console._errorOriginal(e.message);
console._errorOriginal(error.message);
} else {
console.error(e.message);
console.error(error.message);
}
reportException(e, isFatal);
reportException(error, isFatal);
}

function reactConsoleErrorHandler() {
Expand Down
Loading