diff --git a/Libraries/ART/ARTSerializablePath.js b/Libraries/ART/ARTSerializablePath.js index 08c453022..de02f9498 100644 --- a/Libraries/ART/ARTSerializablePath.js +++ b/Libraries/ART/ARTSerializablePath.js @@ -9,16 +9,16 @@ // TODO: Move this into an ART mode called "serialized" or something -var Class = require('art/core/class.js'); -var Path = require('art/core/path.js'); +const Class = require('art/core/class.js'); +const Path = require('art/core/path.js'); -var MOVE_TO = 0; -var CLOSE = 1; -var LINE_TO = 2; -var CURVE_TO = 3; -var ARC = 4; +const MOVE_TO = 0; +const CLOSE = 1; +const LINE_TO = 2; +const CURVE_TO = 3; +const ARC = 4; -var SerializablePath = Class(Path, { +const SerializablePath = Class(Path, { initialize: function(path) { this.reset(); diff --git a/Libraries/ART/ReactNativeART.js b/Libraries/ART/ReactNativeART.js index 9b0a725cd..0f32fa2da 100644 --- a/Libraries/ART/ReactNativeART.js +++ b/Libraries/ART/ReactNativeART.js @@ -7,17 +7,17 @@ */ 'use strict'; -var Color = require('art/core/color'); -var Path = require('ARTSerializablePath'); -var Transform = require('art/core/transform'); +const Color = require('art/core/color'); +const Path = require('ARTSerializablePath'); +const Transform = require('art/core/transform'); -var React = require('React'); -var PropTypes = require('prop-types'); -var ReactNativeViewAttributes = require('ReactNativeViewAttributes'); +const React = require('React'); +const PropTypes = require('prop-types'); +const ReactNativeViewAttributes = require('ReactNativeViewAttributes'); -var createReactNativeComponentClass = require('createReactNativeComponentClass'); -var merge = require('merge'); -var invariant = require('fbjs/lib/invariant'); +const createReactNativeComponentClass = require('createReactNativeComponentClass'); +const merge = require('merge'); +const invariant = require('fbjs/lib/invariant'); // Diff Helpers @@ -28,7 +28,7 @@ function arrayDiffer(a, b) { if (a.length !== b.length) { return true; } - for (var i = 0; i < a.length; i++) { + for (let i = 0; i < a.length; i++) { if (a[i] !== b[i]) { return true; } @@ -62,22 +62,22 @@ function fontAndLinesDiffer(a, b) { // Native Attributes -var SurfaceViewAttributes = merge(ReactNativeViewAttributes.UIView, { +const SurfaceViewAttributes = merge(ReactNativeViewAttributes.UIView, { // This should contain pixel information such as width, height and // resolution to know what kind of buffer needs to be allocated. // Currently we rely on UIViews and style to figure that out. }); -var NodeAttributes = { +const NodeAttributes = { transform: { diff: arrayDiffer }, opacity: true, }; -var GroupAttributes = merge(NodeAttributes, { +const GroupAttributes = merge(NodeAttributes, { clipping: { diff: arrayDiffer } }); -var RenderableAttributes = merge(NodeAttributes, { +const RenderableAttributes = merge(NodeAttributes, { fill: { diff: arrayDiffer }, stroke: { diff: arrayDiffer }, strokeWidth: true, @@ -86,11 +86,11 @@ var RenderableAttributes = merge(NodeAttributes, { strokeDash: { diff: arrayDiffer }, }); -var ShapeAttributes = merge(RenderableAttributes, { +const ShapeAttributes = merge(RenderableAttributes, { d: { diff: arrayDiffer }, }); -var TextAttributes = merge(RenderableAttributes, { +const TextAttributes = merge(RenderableAttributes, { alignment: true, frame: { diff: fontAndLinesDiffer }, path: { diff: arrayDiffer } @@ -98,25 +98,25 @@ var TextAttributes = merge(RenderableAttributes, { // Native Components -var NativeSurfaceView = createReactNativeComponentClass('ARTSurfaceView', +const NativeSurfaceView = createReactNativeComponentClass('ARTSurfaceView', () => ({ validAttributes: SurfaceViewAttributes, uiViewClassName: 'ARTSurfaceView', })); -var NativeGroup = createReactNativeComponentClass('ARTGroup', +const NativeGroup = createReactNativeComponentClass('ARTGroup', () => ({ validAttributes: GroupAttributes, uiViewClassName: 'ARTGroup', })); -var NativeShape = createReactNativeComponentClass('ARTShape', +const NativeShape = createReactNativeComponentClass('ARTShape', () => ({ validAttributes: ShapeAttributes, uiViewClassName: 'ARTShape', })); -var NativeText = createReactNativeComponentClass('ARTText', +const NativeText = createReactNativeComponentClass('ARTText', () => ({ validAttributes: TextAttributes, uiViewClassName: 'ARTText', @@ -149,9 +149,9 @@ class Surface extends React.Component { } render() { - var props = this.props; - var w = extractNumber(props.width, 0); - var h = extractNumber(props.height, 0); + const props = this.props; + const w = extractNumber(props.width, 0); + const h = extractNumber(props.height, 0); return ( {this.props.children} @@ -172,12 +172,12 @@ function extractNumber(value, defaultValue) { return +value; } -var pooledTransform = new Transform(); +const pooledTransform = new Transform(); function extractTransform(props) { - var scaleX = props.scaleX != null ? props.scaleX : + const scaleX = props.scaleX != null ? props.scaleX : props.scale != null ? props.scale : 1; - var scaleY = props.scaleY != null ? props.scaleY : + const scaleY = props.scaleY != null ? props.scaleY : props.scale != null ? props.scale : 1; pooledTransform @@ -219,7 +219,7 @@ class Group extends React.Component { }; render() { - var props = this.props; + const props = this.props; invariant( this.context.isInSurface, 'ART: must be a child of a ' @@ -236,14 +236,14 @@ class Group extends React.Component { class ClippingRectangle extends React.Component { render() { - var props = this.props; - var x = extractNumber(props.x, 0); - var y = extractNumber(props.y, 0); - var w = extractNumber(props.width, 0); - var h = extractNumber(props.height, 0); - var clipping = [x, y, w, h]; + const props = this.props; + const x = extractNumber(props.x, 0); + const y = extractNumber(props.y, 0); + const w = extractNumber(props.width, 0); + const h = extractNumber(props.height, 0); + const clipping = [x, y, w, h]; // The current clipping API requires x and y to be ignored in the transform - var propsExcludingXAndY = merge(props); + const propsExcludingXAndY = merge(props); delete propsExcludingXAndY.x; delete propsExcludingXAndY.y; return ( @@ -259,13 +259,13 @@ class ClippingRectangle extends React.Component { // Renderables -var SOLID_COLOR = 0; -var LINEAR_GRADIENT = 1; -var RADIAL_GRADIENT = 2; -var PATTERN = 3; +const SOLID_COLOR = 0; +const LINEAR_GRADIENT = 1; +const RADIAL_GRADIENT = 2; +const PATTERN = 3; function insertColorIntoArray(color, targetArray, atIndex) { - var c = new Color(color); + const c = new Color(color); targetArray[atIndex + 0] = c.red / 255; targetArray[atIndex + 1] = c.green / 255; targetArray[atIndex + 2] = c.blue / 255; @@ -273,14 +273,14 @@ function insertColorIntoArray(color, targetArray, atIndex) { } function insertColorsIntoArray(stops, targetArray, atIndex) { - var i = 0; + let i = 0; if ('length' in stops) { while (i < stops.length) { insertColorIntoArray(stops[i], targetArray, atIndex + i * 4); i++; } } else { - for (var offset in stops) { + for (const offset in stops) { insertColorIntoArray(stops[offset], targetArray, atIndex + i * 4); i++; } @@ -289,8 +289,8 @@ function insertColorsIntoArray(stops, targetArray, atIndex) { } function insertOffsetsIntoArray(stops, targetArray, atIndex, multi, reverse) { - var offsetNumber; - var i = 0; + let offsetNumber; + let i = 0; if ('length' in stops) { while (i < stops.length) { offsetNumber = i / (stops.length - 1) * multi; @@ -298,7 +298,7 @@ function insertOffsetsIntoArray(stops, targetArray, atIndex, multi, reverse) { i++; } } else { - for (var offsetString in stops) { + for (const offsetString in stops) { offsetNumber = (+offsetString) * multi; targetArray[atIndex + i] = reverse ? 1 - offsetNumber : offsetNumber; i++; @@ -308,21 +308,21 @@ function insertOffsetsIntoArray(stops, targetArray, atIndex, multi, reverse) { } function insertColorStopsIntoArray(stops, targetArray, atIndex) { - var lastIndex = insertColorsIntoArray(stops, targetArray, atIndex); + const lastIndex = insertColorsIntoArray(stops, targetArray, atIndex); insertOffsetsIntoArray(stops, targetArray, lastIndex, 1, false); } function insertDoubleColorStopsIntoArray(stops, targetArray, atIndex) { - var lastIndex = insertColorsIntoArray(stops, targetArray, atIndex); + let lastIndex = insertColorsIntoArray(stops, targetArray, atIndex); lastIndex = insertColorsIntoArray(stops, targetArray, lastIndex); lastIndex = insertOffsetsIntoArray(stops, targetArray, lastIndex, 0.5, false); insertOffsetsIntoArray(stops, targetArray, lastIndex, 0.5, true); } function applyBoundingBoxToBrushData(brushData, props) { - var type = brushData[0]; - var width = +props.width; - var height = +props.height; + const type = brushData[0]; + const width = +props.width; + const height = +props.height; if (type === LINEAR_GRADIENT) { brushData[1] *= width; brushData[2] *= height; @@ -356,7 +356,7 @@ function extractBrush(colorOrBrush, props) { } return colorOrBrush._brush; } - var c = new Color(colorOrBrush); + const c = new Color(colorOrBrush); return [SOLID_COLOR, c.red / 255, c.green / 255, c.blue / 255, c.alpha]; } @@ -364,7 +364,7 @@ function extractColor(color) { if (color == null) { return null; } - var c = new Color(color); + const c = new Color(color); return [c.red / 255, c.green / 255, c.blue / 255, c.alpha]; } @@ -391,9 +391,9 @@ function extractStrokeJoin(strokeJoin) { class Shape extends React.Component { render() { - var props = this.props; - var path = props.d || childrenAsString(props.children); - var d = (path instanceof Path ? path : new Path(path)).toJSON(); + const props = this.props; + const path = props.d || childrenAsString(props.children); + const d = (path instanceof Path ? path : new Path(path)).toJSON(); return ( { - var cb = callbacks[id]; + const cb = callbacks[id]; cb && cb(value); }); } diff --git a/Libraries/Alert/RCTAlertManager.android.js b/Libraries/Alert/RCTAlertManager.android.js index 25297171c..57bd4740e 100644 --- a/Libraries/Alert/RCTAlertManager.android.js +++ b/Libraries/Alert/RCTAlertManager.android.js @@ -7,7 +7,7 @@ */ 'use strict'; -var NativeModules = require('NativeModules'); +const NativeModules = require('NativeModules'); function emptyCallback() {} diff --git a/Libraries/Alert/RCTAlertManager.ios.js b/Libraries/Alert/RCTAlertManager.ios.js index 220b72c3d..d64bce5b4 100644 --- a/Libraries/Alert/RCTAlertManager.ios.js +++ b/Libraries/Alert/RCTAlertManager.ios.js @@ -8,6 +8,6 @@ */ 'use strict'; -var RCTAlertManager = require('NativeModules').AlertManager; +const RCTAlertManager = require('NativeModules').AlertManager; module.exports = RCTAlertManager; diff --git a/Libraries/Animated/src/AnimatedWeb.js b/Libraries/Animated/src/AnimatedWeb.js index a22bd075e..5538eb9b6 100644 --- a/Libraries/Animated/src/AnimatedWeb.js +++ b/Libraries/Animated/src/AnimatedWeb.js @@ -8,7 +8,7 @@ */ 'use strict'; -var AnimatedImplementation = require('AnimatedImplementation'); +const AnimatedImplementation = require('AnimatedImplementation'); module.exports = { ...AnimatedImplementation, diff --git a/Libraries/Animated/src/NativeAnimatedHelper.js b/Libraries/Animated/src/NativeAnimatedHelper.js index 61b2bde64..3142ea24c 100644 --- a/Libraries/Animated/src/NativeAnimatedHelper.js +++ b/Libraries/Animated/src/NativeAnimatedHelper.js @@ -208,7 +208,7 @@ function validateTransform(configs: Array): void { } function validateStyles(styles: Object): void { - for (var key in styles) { + for (const key in styles) { if (!STYLES_WHITELIST.hasOwnProperty(key)) { throw new Error( `Style property '${key}' is not supported by native animated module`, @@ -218,7 +218,7 @@ function validateStyles(styles: Object): void { } function validateInterpolation(config: Object): void { - for (var key in config) { + for (const key in config) { if (!SUPPORTED_INTERPOLATION_PARAMS.hasOwnProperty(key)) { throw new Error( `Interpolation property '${key}' is not supported by native animated module`, diff --git a/Libraries/Animated/src/SpringConfig.js b/Libraries/Animated/src/SpringConfig.js index 6227c2830..b71fda2ea 100644 --- a/Libraries/Animated/src/SpringConfig.js +++ b/Libraries/Animated/src/SpringConfig.js @@ -77,11 +77,11 @@ function fromBouncinessAndSpeed( } } - var b = normalize(bounciness / 1.7, 0, 20); + let b = normalize(bounciness / 1.7, 0, 20); b = projectNormal(b, 0, 0.8); - var s = normalize(speed / 1.7, 0, 20); - var bouncyTension = projectNormal(s, 0.5, 200); - var bouncyFriction = quadraticOutInterpolation( + const s = normalize(speed / 1.7, 0, 20); + const bouncyTension = projectNormal(s, 0.5, 200); + const bouncyFriction = quadraticOutInterpolation( b, b3Nobounce(bouncyTension), 0.01 diff --git a/Libraries/Animated/src/__tests__/Animated-test.js b/Libraries/Animated/src/__tests__/Animated-test.js index d6409d7f8..36b4d2a40 100644 --- a/Libraries/Animated/src/__tests__/Animated-test.js +++ b/Libraries/Animated/src/__tests__/Animated-test.js @@ -8,7 +8,7 @@ */ 'use strict'; -var Animated = require('Animated'); +let Animated = require('Animated'); describe('Animated tests', () => { beforeEach(() => { jest.resetModules(); @@ -17,11 +17,11 @@ describe('Animated tests', () => { describe('Animated', () => { it('works end to end', () => { - var anim = new Animated.Value(0); + const anim = new Animated.Value(0); - var callback = jest.fn(); + const callback = jest.fn(); - var node = new Animated.__PropsOnlyForTests({ + const node = new Animated.__PropsOnlyForTests({ style: { backgroundColor: 'red', opacity: anim, @@ -83,10 +83,10 @@ describe('Animated tests', () => { }); it('does not detach on updates', () => { - var anim = new Animated.Value(0); + const anim = new Animated.Value(0); anim.__detach = jest.fn(); - var c = new Animated.View(); + const c = new Animated.View(); c.props = { style: { opacity: anim, @@ -109,10 +109,10 @@ describe('Animated tests', () => { it('stops animation when detached', () => { - var anim = new Animated.Value(0); - var callback = jest.fn(); + const anim = new Animated.Value(0); + const callback = jest.fn(); - var c = new Animated.View(); + const c = new Animated.View(); c.props = { style: { opacity: anim, @@ -129,31 +129,31 @@ describe('Animated tests', () => { }); it('triggers callback when spring is at rest', () => { - var anim = new Animated.Value(0); - var callback = jest.fn(); + const anim = new Animated.Value(0); + const callback = jest.fn(); Animated.spring(anim, {toValue: 0, velocity: 0}).start(callback); expect(callback).toBeCalled(); }); it('send toValue when an underdamped spring stops', () => { - var anim = new Animated.Value(0); - var listener = jest.fn(); + const anim = new Animated.Value(0); + const listener = jest.fn(); anim.addListener(listener); Animated.spring(anim, {toValue: 15}).start(); jest.runAllTimers(); - var lastValue = listener.mock.calls[listener.mock.calls.length - 2][0].value; + const lastValue = listener.mock.calls[listener.mock.calls.length - 2][0].value; expect(lastValue).not.toBe(15); expect(lastValue).toBeCloseTo(15); expect(anim.__getValue()).toBe(15); }); it('send toValue when a critically damped spring stops', () => { - var anim = new Animated.Value(0); - var listener = jest.fn(); + const anim = new Animated.Value(0); + const listener = jest.fn(); anim.addListener(listener); Animated.spring(anim, {stiffness: 8000, damping: 2000, toValue: 15}).start(); jest.runAllTimers(); - var lastValue = listener.mock.calls[listener.mock.calls.length - 2][0].value; + const lastValue = listener.mock.calls[listener.mock.calls.length - 2][0].value; expect(lastValue).not.toBe(15); expect(lastValue).toBeCloseTo(15); expect(anim.__getValue()).toBe(15); @@ -168,17 +168,17 @@ describe('Animated tests', () => { describe('Animated Sequence', () => { it('works with an empty sequence', () => { - var cb = jest.fn(); + const cb = jest.fn(); Animated.sequence([]).start(cb); expect(cb).toBeCalledWith({finished: true}); }); it('sequences well', () => { - var anim1 = {start: jest.fn()}; - var anim2 = {start: jest.fn()}; - var cb = jest.fn(); + const anim1 = {start: jest.fn()}; + const anim2 = {start: jest.fn()}; + const cb = jest.fn(); - var seq = Animated.sequence([anim1, anim2]); + const seq = Animated.sequence([anim1, anim2]); expect(anim1.start).not.toBeCalled(); expect(anim2.start).not.toBeCalled(); @@ -199,9 +199,9 @@ describe('Animated tests', () => { }); it('supports interrupting sequence', () => { - var anim1 = {start: jest.fn()}; - var anim2 = {start: jest.fn()}; - var cb = jest.fn(); + const anim1 = {start: jest.fn()}; + const anim2 = {start: jest.fn()}; + const cb = jest.fn(); Animated.sequence([anim1, anim2]).start(cb); @@ -213,11 +213,11 @@ describe('Animated tests', () => { }); it('supports stopping sequence', () => { - var anim1 = {start: jest.fn(), stop: jest.fn()}; - var anim2 = {start: jest.fn(), stop: jest.fn()}; - var cb = jest.fn(); + const anim1 = {start: jest.fn(), stop: jest.fn()}; + const anim2 = {start: jest.fn(), stop: jest.fn()}; + const cb = jest.fn(); - var seq = Animated.sequence([anim1, anim2]); + const seq = Animated.sequence([anim1, anim2]); seq.start(cb); seq.stop(); @@ -234,10 +234,10 @@ describe('Animated tests', () => { describe('Animated Loop', () => { it('loops indefinitely if config not specified', () => { - var animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false}; - var cb = jest.fn(); + const animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false}; + const cb = jest.fn(); - var loop = Animated.loop(animation); + const loop = Animated.loop(animation); expect(animation.start).not.toBeCalled(); @@ -261,10 +261,10 @@ describe('Animated tests', () => { }); it('loops indefinitely if iterations is -1', () => { - var animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false}; - var cb = jest.fn(); + const animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false}; + const cb = jest.fn(); - var loop = Animated.loop(animation, { iterations: -1 }); + const loop = Animated.loop(animation, { iterations: -1 }); expect(animation.start).not.toBeCalled(); @@ -288,10 +288,10 @@ describe('Animated tests', () => { }); it('loops indefinitely if iterations not specified', () => { - var animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false}; - var cb = jest.fn(); + const animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false}; + const cb = jest.fn(); - var loop = Animated.loop(animation, { anotherKey: 'value' }); + const loop = Animated.loop(animation, { anotherKey: 'value' }); expect(animation.start).not.toBeCalled(); @@ -315,10 +315,10 @@ describe('Animated tests', () => { }); it('loops three times if iterations is 3', () => { - var animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false}; - var cb = jest.fn(); + const animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false}; + const cb = jest.fn(); - var loop = Animated.loop(animation, { iterations: 3 }); + const loop = Animated.loop(animation, { iterations: 3 }); expect(animation.start).not.toBeCalled(); @@ -342,10 +342,10 @@ describe('Animated tests', () => { }); it('does not loop if iterations is 1', () => { - var animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false}; - var cb = jest.fn(); + const animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false}; + const cb = jest.fn(); - var loop = Animated.loop(animation, { iterations: 1 }); + const loop = Animated.loop(animation, { iterations: 1 }); expect(animation.start).not.toBeCalled(); @@ -359,10 +359,10 @@ describe('Animated tests', () => { }); it('does not animate if iterations is 0', () => { - var animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false}; - var cb = jest.fn(); + const animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false}; + const cb = jest.fn(); - var loop = Animated.loop(animation, { iterations: 0 }); + const loop = Animated.loop(animation, { iterations: 0 }); expect(animation.start).not.toBeCalled(); @@ -373,8 +373,8 @@ describe('Animated tests', () => { }); it('supports interrupting an indefinite loop', () => { - var animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false}; - var cb = jest.fn(); + const animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false}; + const cb = jest.fn(); Animated.loop(animation).start(cb); expect(animation.start).toBeCalled(); @@ -391,10 +391,10 @@ describe('Animated tests', () => { }); it('supports stopping loop', () => { - var animation = {start: jest.fn(), stop: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false}; - var cb = jest.fn(); + const animation = {start: jest.fn(), stop: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false}; + const cb = jest.fn(); - var loop = Animated.loop(animation); + const loop = Animated.loop(animation); loop.start(cb); loop.stop(); @@ -411,14 +411,14 @@ describe('Animated tests', () => { describe('Animated Parallel', () => { it('works with an empty parallel', () => { - var cb = jest.fn(); + const cb = jest.fn(); Animated.parallel([]).start(cb); expect(cb).toBeCalledWith({finished: true}); }); it('works with an empty element in array', () => { - var anim1 = {start: jest.fn()}; - var cb = jest.fn(); + const anim1 = {start: jest.fn()}; + const cb = jest.fn(); Animated.parallel([null, anim1]).start(cb); expect(anim1.start).toBeCalled(); @@ -428,11 +428,11 @@ describe('Animated tests', () => { }); it('parellelizes well', () => { - var anim1 = {start: jest.fn()}; - var anim2 = {start: jest.fn()}; - var cb = jest.fn(); + const anim1 = {start: jest.fn()}; + const anim2 = {start: jest.fn()}; + const cb = jest.fn(); - var par = Animated.parallel([anim1, anim2]); + const par = Animated.parallel([anim1, anim2]); expect(anim1.start).not.toBeCalled(); expect(anim2.start).not.toBeCalled(); @@ -451,11 +451,11 @@ describe('Animated tests', () => { }); it('supports stopping parallel', () => { - var anim1 = {start: jest.fn(), stop: jest.fn()}; - var anim2 = {start: jest.fn(), stop: jest.fn()}; - var cb = jest.fn(); + const anim1 = {start: jest.fn(), stop: jest.fn()}; + const anim2 = {start: jest.fn(), stop: jest.fn()}; + const cb = jest.fn(); - var seq = Animated.parallel([anim1, anim2]); + const seq = Animated.parallel([anim1, anim2]); seq.start(cb); seq.stop(); @@ -472,12 +472,12 @@ describe('Animated tests', () => { it('does not call stop more than once when stopping', () => { - var anim1 = {start: jest.fn(), stop: jest.fn()}; - var anim2 = {start: jest.fn(), stop: jest.fn()}; - var anim3 = {start: jest.fn(), stop: jest.fn()}; - var cb = jest.fn(); + const anim1 = {start: jest.fn(), stop: jest.fn()}; + const anim2 = {start: jest.fn(), stop: jest.fn()}; + const anim3 = {start: jest.fn(), stop: jest.fn()}; + const cb = jest.fn(); - var seq = Animated.parallel([anim1, anim2, anim3]); + const seq = Animated.parallel([anim1, anim2, anim3]); seq.start(cb); anim1.start.mock.calls[0][0]({finished: false}); @@ -502,8 +502,8 @@ describe('Animated tests', () => { describe('Animated delays', () => { it('should call anim after delay in sequence', () => { - var anim = {start: jest.fn(), stop: jest.fn()}; - var cb = jest.fn(); + const anim = {start: jest.fn(), stop: jest.fn()}; + const cb = jest.fn(); Animated.sequence([ Animated.delay(1000), anim, @@ -515,7 +515,7 @@ describe('Animated tests', () => { expect(cb).toBeCalledWith({finished: true}); }); it('should run stagger to end', () => { - var cb = jest.fn(); + const cb = jest.fn(); Animated.stagger(1000, [ Animated.delay(1000), Animated.delay(1000), @@ -528,17 +528,17 @@ describe('Animated tests', () => { describe('Animated Events', () => { it('should map events', () => { - var value = new Animated.Value(0); - var handler = Animated.event( + const value = new Animated.Value(0); + const handler = Animated.event( [null, {state: {foo: value}}], ); handler({bar: 'ignoreBar'}, {state: {baz: 'ignoreBaz', foo: 42}}); expect(value.__getValue()).toBe(42); }); it('should call listeners', () => { - var value = new Animated.Value(0); - var listener = jest.fn(); - var handler = Animated.event( + const value = new Animated.Value(0); + const listener = jest.fn(); + const handler = Animated.event( [{foo: value}], {listener}, ); @@ -548,14 +548,14 @@ describe('Animated tests', () => { expect(listener).toBeCalledWith({foo: 42}); }); it('should call forked event listeners', () => { - var value = new Animated.Value(0); - var listener = jest.fn(); - var handler = Animated.event( + const value = new Animated.Value(0); + const listener = jest.fn(); + const handler = Animated.event( [{foo: value}], {listener}, ); - var listener2 = jest.fn(); - var forkedHandler = Animated.forkEvent(handler, listener2); + const listener2 = jest.fn(); + const forkedHandler = Animated.forkEvent(handler, listener2); forkedHandler({foo: 42}); expect(value.__getValue()).toBe(42); expect(listener.mock.calls.length).toBe(1); @@ -567,9 +567,9 @@ describe('Animated tests', () => { describe('Animated Interactions', () => { /*eslint-disable no-shadow*/ - var Animated; + let Animated; /*eslint-enable*/ - var InteractionManager; + let InteractionManager; beforeEach(() => { jest.mock('InteractionManager'); @@ -584,8 +584,8 @@ describe('Animated tests', () => { it('registers an interaction by default', () => { InteractionManager.createInteractionHandle.mockReturnValue(777); - var value = new Animated.Value(0); - var callback = jest.fn(); + const value = new Animated.Value(0); + const callback = jest.fn(); Animated.timing(value, { toValue: 100, duration: 100, @@ -598,8 +598,8 @@ describe('Animated tests', () => { }); it('does not register an interaction when specified', () => { - var value = new Animated.Value(0); - var callback = jest.fn(); + const value = new Animated.Value(0); + const callback = jest.fn(); Animated.timing(value, { toValue: 100, duration: 100, @@ -615,8 +615,8 @@ describe('Animated tests', () => { describe('Animated Tracking', () => { it('should track values', () => { - var value1 = new Animated.Value(0); - var value2 = new Animated.Value(0); + const value1 = new Animated.Value(0); + const value2 = new Animated.Value(0); Animated.timing(value2, { toValue: value1, duration: 0, @@ -628,8 +628,8 @@ describe('Animated tests', () => { }); it('should track interpolated values', () => { - var value1 = new Animated.Value(0); - var value2 = new Animated.Value(0); + const value1 = new Animated.Value(0); + const value2 = new Animated.Value(0); Animated.timing(value2, { toValue: value1.interpolate({ inputRange: [0, 2], @@ -642,8 +642,8 @@ describe('Animated tests', () => { }); it('should stop tracking when animated', () => { - var value1 = new Animated.Value(0); - var value2 = new Animated.Value(0); + const value1 = new Animated.Value(0); + const value2 = new Animated.Value(0); Animated.timing(value2, { toValue: value1, duration: 0, @@ -661,11 +661,11 @@ describe('Animated tests', () => { describe('Animated Vectors', () => { it('should animate vectors', () => { - var vec = new Animated.ValueXY(); + const vec = new Animated.ValueXY(); - var callback = jest.fn(); + const callback = jest.fn(); - var node = new Animated.__PropsOnlyForTests({ + const node = new Animated.__PropsOnlyForTests({ style: { opacity: vec.x.interpolate({ inputRange: [0, 42], @@ -711,8 +711,8 @@ describe('Animated tests', () => { }); it('should track vectors', () => { - var value1 = new Animated.ValueXY(); - var value2 = new Animated.ValueXY(); + const value1 = new Animated.ValueXY(); + const value2 = new Animated.ValueXY(); Animated.timing(value2, { toValue: value1, duration: 0, @@ -727,8 +727,8 @@ describe('Animated tests', () => { }); it('should track with springs', () => { - var value1 = new Animated.ValueXY(); - var value2 = new Animated.ValueXY(); + const value1 = new Animated.ValueXY(); + const value2 = new Animated.ValueXY(); Animated.spring(value2, { toValue: value1, tension: 3000, // faster spring for faster test @@ -747,9 +747,9 @@ describe('Animated tests', () => { describe('Animated Listeners', () => { it('should get updates', () => { - var value1 = new Animated.Value(0); - var listener = jest.fn(); - var id = value1.addListener(listener); + const value1 = new Animated.Value(0); + const listener = jest.fn(); + const id = value1.addListener(listener); value1.setValue(42); expect(listener.mock.calls.length).toBe(1); expect(listener).toBeCalledWith({value: 42}); @@ -765,8 +765,8 @@ describe('Animated tests', () => { }); it('should removeAll', () => { - var value1 = new Animated.Value(0); - var listener = jest.fn(); + const value1 = new Animated.Value(0); + const listener = jest.fn(); [1,2,3,4].forEach(() => value1.addListener(listener)); value1.setValue(42); expect(listener.mock.calls.length).toBe(4); diff --git a/Libraries/Animated/src/__tests__/Easing-test.js b/Libraries/Animated/src/__tests__/Easing-test.js index 14f18aacd..ae6cd3368 100644 --- a/Libraries/Animated/src/__tests__/Easing-test.js +++ b/Libraries/Animated/src/__tests__/Easing-test.js @@ -8,10 +8,10 @@ */ 'use strict'; -var Easing = require('Easing'); +const Easing = require('Easing'); describe('Easing', () => { it('should work with linear', () => { - var easing = Easing.linear; + const easing = Easing.linear; expect(easing(0)).toBe(0); expect(easing(0.5)).toBe(0.5); @@ -20,7 +20,7 @@ describe('Easing', () => { }); it('should work with ease in linear', () => { - var easing = Easing.in(Easing.linear); + const easing = Easing.in(Easing.linear); expect(easing(0)).toBe(0); expect(easing(0.5)).toBe(0.5); expect(easing(0.8)).toBe(0.8); @@ -28,7 +28,7 @@ describe('Easing', () => { }); it('should work with easy out linear', () => { - var easing = Easing.out(Easing.linear); + const easing = Easing.out(Easing.linear); expect(easing(0)).toBe(0); expect(easing(0.5)).toBe(0.5); expect(easing(0.6)).toBe(0.6); @@ -39,8 +39,8 @@ describe('Easing', () => { function easeInQuad(t) { return t * t; } - var easing = Easing.in(Easing.quad); - for (var t = -0.5; t < 1.5; t += 0.1) { + const easing = Easing.in(Easing.quad); + for (let t = -0.5; t < 1.5; t += 0.1) { expect(easing(t)).toBe(easeInQuad(t)); } }); @@ -49,8 +49,8 @@ describe('Easing', () => { function easeOutQuad(t) { return -t * (t - 2); } - var easing = Easing.out(Easing.quad); - for (var t = 0; t <= 1; t += 0.1) { + const easing = Easing.out(Easing.quad); + for (let t = 0; t <= 1; t += 0.1) { expect(easing(1)).toBe(easeOutQuad(1)); } }); @@ -63,31 +63,31 @@ describe('Easing', () => { } return -((t - 1) * (t - 3) - 1) / 2; } - var easing = Easing.inOut(Easing.quad); - for (var t = -0.5; t < 1.5; t += 0.1) { + const easing = Easing.inOut(Easing.quad); + for (let t = -0.5; t < 1.5; t += 0.1) { expect(easing(t)).toBeCloseTo(easeInOutQuad(t), 4); } }); it('should satisfy boundary conditions with elastic', () => { - for (var b = 0; b < 4; b += 0.3) { - var easing = Easing.elastic(b); + for (let b = 0; b < 4; b += 0.3) { + const easing = Easing.elastic(b); expect(easing(0)).toBe(0); expect(easing(1)).toBe(1); } }); function sampleEasingFunction(easing) { - var DURATION = 300; - var tickCount = Math.round(DURATION * 60 / 1000); - var samples = []; - for (var i = 0; i <= tickCount; i++) { + const DURATION = 300; + const tickCount = Math.round(DURATION * 60 / 1000); + const samples = []; + for (let i = 0; i <= tickCount; i++) { samples.push(easing(i / tickCount)); } return samples; } - var Samples = { + const Samples = { in_quad: [0,0.0030864197530864196,0.012345679012345678,0.027777777777777776,0.04938271604938271,0.0771604938271605,0.1111111111111111,0.15123456790123457,0.19753086419753085,0.25,0.308641975308642,0.37345679012345684,0.4444444444444444,0.5216049382716049,0.6049382716049383,0.6944444444444445,0.7901234567901234,0.8919753086419753,1], out_quad: [0,0.10802469135802469,0.20987654320987653,0.3055555555555555,0.3950617283950617,0.47839506172839513,0.5555555555555556,0.6265432098765432,0.691358024691358,0.75,0.8024691358024691,0.8487654320987654,0.888888888888889,0.9228395061728394,0.9506172839506174,0.9722222222222221,0.9876543209876543,0.9969135802469136,1], inOut_quad: [0,0.006172839506172839,0.024691358024691357,0.05555555555555555,0.09876543209876543,0.154320987654321,0.2222222222222222,0.30246913580246915,0.3950617283950617,0.5,0.6049382716049383,0.697530864197531,0.7777777777777777,0.845679012345679,0.9012345679012346,0.9444444444444444,0.9753086419753086,0.9938271604938271,1], @@ -109,13 +109,13 @@ describe('Easing', () => { Object.keys(Samples).forEach(function(type) { it('should ease ' + type, function() { - var [modeName, easingName, isFunction] = type.split('_'); - var easing = Easing[easingName]; + const [modeName, easingName, isFunction] = type.split('_'); + let easing = Easing[easingName]; if (isFunction !== undefined) { easing = easing(); } - var computed = sampleEasingFunction(Easing[modeName](easing)); - var samples = Samples[type]; + const computed = sampleEasingFunction(Easing[modeName](easing)); + const samples = Samples[type]; computed.forEach((value, key) => { expect(value).toBeCloseTo(samples[key], 2); diff --git a/Libraries/Animated/src/__tests__/Interpolation-test.js b/Libraries/Animated/src/__tests__/Interpolation-test.js index 27f4438ab..c2b832bcf 100644 --- a/Libraries/Animated/src/__tests__/Interpolation-test.js +++ b/Libraries/Animated/src/__tests__/Interpolation-test.js @@ -8,12 +8,12 @@ */ 'use strict'; -var AnimatedInterpolation = require('../nodes/AnimatedInterpolation'); -var Easing = require('Easing'); +const AnimatedInterpolation = require('../nodes/AnimatedInterpolation'); +const Easing = require('Easing'); describe('Interpolation', () => { it('should work with defaults', () => { - var interpolation = AnimatedInterpolation.__createInterpolation({ + const interpolation = AnimatedInterpolation.__createInterpolation({ inputRange: [0, 1], outputRange: [0, 1], }); @@ -25,7 +25,7 @@ describe('Interpolation', () => { }); it('should work with output range', () => { - var interpolation = AnimatedInterpolation.__createInterpolation({ + const interpolation = AnimatedInterpolation.__createInterpolation({ inputRange: [0, 1], outputRange: [100, 200], }); @@ -37,7 +37,7 @@ describe('Interpolation', () => { }); it('should work with input range', () => { - var interpolation = AnimatedInterpolation.__createInterpolation({ + const interpolation = AnimatedInterpolation.__createInterpolation({ inputRange: [100, 200], outputRange: [0, 1], }); @@ -65,7 +65,7 @@ describe('Interpolation', () => { }); it('should work with empty input range', () => { - var interpolation = AnimatedInterpolation.__createInterpolation({ + const interpolation = AnimatedInterpolation.__createInterpolation({ inputRange: [0, 10, 10], outputRange: [1, 2, 3], extrapolate: 'extend', @@ -79,7 +79,7 @@ describe('Interpolation', () => { }); it('should work with empty output range', () => { - var interpolation = AnimatedInterpolation.__createInterpolation({ + const interpolation = AnimatedInterpolation.__createInterpolation({ inputRange: [1, 2, 3], outputRange: [0, 10, 10], extrapolate: 'extend', @@ -94,7 +94,7 @@ describe('Interpolation', () => { }); it('should work with easing', () => { - var interpolation = AnimatedInterpolation.__createInterpolation({ + const interpolation = AnimatedInterpolation.__createInterpolation({ inputRange: [0, 1], outputRange: [0, 1], easing: Easing.quad, @@ -107,7 +107,7 @@ describe('Interpolation', () => { }); it('should work with extrapolate', () => { - var interpolation = AnimatedInterpolation.__createInterpolation({ + let interpolation = AnimatedInterpolation.__createInterpolation({ inputRange: [0, 1], outputRange: [0, 1], extrapolate: 'extend', @@ -139,7 +139,7 @@ describe('Interpolation', () => { }); it('should work with keyframes with extrapolate', () => { - var interpolation = AnimatedInterpolation.__createInterpolation({ + const interpolation = AnimatedInterpolation.__createInterpolation({ inputRange: [0, 10, 100, 1000], outputRange: [0, 5, 50, 500], extrapolate: true, @@ -157,7 +157,7 @@ describe('Interpolation', () => { }); it('should work with keyframes without extrapolate', () => { - var interpolation = AnimatedInterpolation.__createInterpolation({ + const interpolation = AnimatedInterpolation.__createInterpolation({ inputRange: [0, 1, 2], outputRange: [0.2, 1, 0.2], extrapolate: 'clamp', @@ -183,7 +183,7 @@ describe('Interpolation', () => { }); it('should work with negative infinite', () => { - var interpolation = AnimatedInterpolation.__createInterpolation({ + const interpolation = AnimatedInterpolation.__createInterpolation({ inputRange: [-Infinity, 0], outputRange: [-Infinity, 0], easing: Easing.quad, @@ -199,7 +199,7 @@ describe('Interpolation', () => { }); it('should work with positive infinite', () => { - var interpolation = AnimatedInterpolation.__createInterpolation({ + const interpolation = AnimatedInterpolation.__createInterpolation({ inputRange: [5, Infinity], outputRange: [5, Infinity], easing: Easing.quad, @@ -217,7 +217,7 @@ describe('Interpolation', () => { }); it('should work with output ranges as string', () => { - var interpolation = AnimatedInterpolation.__createInterpolation({ + const interpolation = AnimatedInterpolation.__createInterpolation({ inputRange: [0, 1], outputRange: ['rgba(0, 100, 200, 0)', 'rgba(50, 150, 250, 0.4)'], }); @@ -228,7 +228,7 @@ describe('Interpolation', () => { }); it('should work with output ranges as short hex string', () => { - var interpolation = AnimatedInterpolation.__createInterpolation({ + const interpolation = AnimatedInterpolation.__createInterpolation({ inputRange: [0, 1], outputRange: ['#024', '#9BF'], }); @@ -239,7 +239,7 @@ describe('Interpolation', () => { }); it('should work with output ranges as long hex string', () => { - var interpolation = AnimatedInterpolation.__createInterpolation({ + const interpolation = AnimatedInterpolation.__createInterpolation({ inputRange: [0, 1], outputRange: ['#FF9500', '#87FC70'], }); @@ -250,7 +250,7 @@ describe('Interpolation', () => { }); it('should work with output ranges with mixed hex and rgba strings', () => { - var interpolation = AnimatedInterpolation.__createInterpolation({ + const interpolation = AnimatedInterpolation.__createInterpolation({ inputRange: [0, 1], outputRange: ['rgba(100, 120, 140, .4)', '#87FC70'], }); @@ -261,7 +261,7 @@ describe('Interpolation', () => { }); it('should work with negative and decimal values in string ranges', () => { - var interpolation = AnimatedInterpolation.__createInterpolation({ + const interpolation = AnimatedInterpolation.__createInterpolation({ inputRange: [0, 1], outputRange: ['-100.5deg', '100deg'], }); @@ -272,7 +272,7 @@ describe('Interpolation', () => { }); it('should crash when chaining an interpolation that returns a string', () => { - var interpolation = AnimatedInterpolation.__createInterpolation({ + const interpolation = AnimatedInterpolation.__createInterpolation({ inputRange: [0, 1], outputRange: [0, 1], }); @@ -282,7 +282,7 @@ describe('Interpolation', () => { }); it('should support a mix of color patterns', () => { - var interpolation = AnimatedInterpolation.__createInterpolation({ + const interpolation = AnimatedInterpolation.__createInterpolation({ inputRange: [0, 1, 2], outputRange: ['rgba(0, 100, 200, 0)', 'rgb(50, 150, 250)', 'red'], }); @@ -303,7 +303,7 @@ describe('Interpolation', () => { }); it('should round the alpha channel of a color to the nearest thousandth', () => { - var interpolation = AnimatedInterpolation.__createInterpolation({ + const interpolation = AnimatedInterpolation.__createInterpolation({ inputRange: [0, 1], outputRange: ['rgba(0, 0, 0, 0)', 'rgba(0, 0, 0, 1)'], }); diff --git a/Libraries/Animated/src/__tests__/bezier-test.js b/Libraries/Animated/src/__tests__/bezier-test.js index 3f1070a48..16b7acc0f 100644 --- a/Libraries/Animated/src/__tests__/bezier-test.js +++ b/Libraries/Animated/src/__tests__/bezier-test.js @@ -10,9 +10,9 @@ 'use strict'; -var bezier = require('bezier'); +const bezier = require('bezier'); -var identity = function(x) { +const identity = function(x) { return x; }; @@ -30,15 +30,15 @@ function allEquals(be1, be2, samples, assertion) { if (!assertion) { assertion = assertClose; } - for (var i = 0; i <= samples; ++i) { - var x = i / samples; + for (let i = 0; i <= samples; ++i) { + const x = i / samples; assertion(be1(x), be2(x)); } } function repeat(n) { return function(f) { - for (var i = 0; i < n; ++i) { + for (let i = 0; i < n; ++i) { f(i); } }; @@ -74,11 +74,8 @@ describe('bezier', function() { describe('common properties', function() { it('should be the right value at extremes', function() { repeat(10)(function() { - var a = Math.random(), - b = 2 * Math.random() - 0.5, - c = Math.random(), - d = 2 * Math.random() - 0.5; - var easing = bezier(a, b, c, d); + const a = Math.random(), b = 2 * Math.random() - 0.5, c = Math.random(), d = 2 * Math.random() - 0.5; + const easing = bezier(a, b, c, d); expect(easing(0)).toBe(0); expect(easing(1)).toBe(1); }); @@ -86,13 +83,10 @@ describe('bezier', function() { it('should approach the projected value of its x=y projected curve', function() { repeat(10)(function() { - var a = Math.random(), - b = Math.random(), - c = Math.random(), - d = Math.random(); - var easing = bezier(a, b, c, d); - var projected = bezier(b, a, d, c); - var composed = function(x) { + const a = Math.random(), b = Math.random(), c = Math.random(), d = Math.random(); + const easing = bezier(a, b, c, d); + const projected = bezier(b, a, d, c); + const composed = function(x) { return projected(easing(x)); }; allEquals(identity, composed, 100, makeAssertCloseWithPrecision(2)); @@ -102,10 +96,7 @@ describe('bezier', function() { describe('two same instances', function() { it('should be strictly equals', function() { repeat(10)(function() { - var a = Math.random(), - b = 2 * Math.random() - 0.5, - c = Math.random(), - d = 2 * Math.random() - 0.5; + const a = Math.random(), b = 2 * Math.random() - 0.5, c = Math.random(), d = 2 * Math.random() - 0.5; allEquals(bezier(a, b, c, d), bezier(a, b, c, d), 100, 0); }); }); @@ -113,22 +104,16 @@ describe('bezier', function() { describe('symetric curves', function() { it('should have a central value y~=0.5 at x=0.5', function() { repeat(10)(function() { - var a = Math.random(), - b = 2 * Math.random() - 0.5, - c = 1 - a, - d = 1 - b; - var easing = bezier(a, b, c, d); + const a = Math.random(), b = 2 * Math.random() - 0.5, c = 1 - a, d = 1 - b; + const easing = bezier(a, b, c, d); assertClose(easing(0.5), 0.5, 2); }); }); it('should be symmetrical', function() { repeat(10)(function() { - var a = Math.random(), - b = 2 * Math.random() - 0.5, - c = 1 - a, - d = 1 - b; - var easing = bezier(a, b, c, d); - var sym = function(x) { + const a = Math.random(), b = 2 * Math.random() - 0.5, c = 1 - a, d = 1 - b; + const easing = bezier(a, b, c, d); + const sym = function(x) { return 1 - easing(1 - x); }; allEquals(easing, sym, 100, makeAssertCloseWithPrecision(2)); diff --git a/Libraries/Animated/src/bezier.js b/Libraries/Animated/src/bezier.js index 9aa777a12..f38ecef8c 100644 --- a/Libraries/Animated/src/bezier.js +++ b/Libraries/Animated/src/bezier.js @@ -8,15 +8,15 @@ 'use strict'; // These values are established by empiricism with tests (tradeoff: performance VS precision) - var NEWTON_ITERATIONS = 4; - var NEWTON_MIN_SLOPE = 0.001; - var SUBDIVISION_PRECISION = 0.0000001; - var SUBDIVISION_MAX_ITERATIONS = 10; + const NEWTON_ITERATIONS = 4; + const NEWTON_MIN_SLOPE = 0.001; + const SUBDIVISION_PRECISION = 0.0000001; + const SUBDIVISION_MAX_ITERATIONS = 10; - var kSplineTableSize = 11; - var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0); + const kSplineTableSize = 11; + const kSampleStepSize = 1.0 / (kSplineTableSize - 1.0); - var float32ArraySupported = typeof Float32Array === 'function'; + const float32ArraySupported = typeof Float32Array === 'function'; function A (aA1, aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1; } function B (aA1, aA2) { return 3.0 * aA2 - 6.0 * aA1; } @@ -29,7 +29,7 @@ function getSlope (aT, aA1, aA2) { return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1); } function binarySubdivide (aX, aA, aB, mX1, mX2) { - var currentX, currentT, i = 0; + let currentX, currentT, i = 0; do { currentT = aA + (aB - aA) / 2.0; currentX = calcBezier(currentT, mX1, mX2) - aX; @@ -43,12 +43,12 @@ } function newtonRaphsonIterate (aX, aGuessT, mX1, mX2) { - for (var i = 0; i < NEWTON_ITERATIONS; ++i) { - var currentSlope = getSlope(aGuessT, mX1, mX2); + for (let i = 0; i < NEWTON_ITERATIONS; ++i) { + const currentSlope = getSlope(aGuessT, mX1, mX2); if (currentSlope === 0.0) { return aGuessT; } - var currentX = calcBezier(aGuessT, mX1, mX2) - aX; + const currentX = calcBezier(aGuessT, mX1, mX2) - aX; aGuessT -= currentX / currentSlope; } return aGuessT; @@ -60,17 +60,17 @@ } // Precompute samples table - var sampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize); + const sampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize); if (mX1 !== mY1 || mX2 !== mY2) { - for (var i = 0; i < kSplineTableSize; ++i) { + for (let i = 0; i < kSplineTableSize; ++i) { sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2); } } function getTForX (aX) { - var intervalStart = 0.0; - var currentSample = 1; - var lastSample = kSplineTableSize - 1; + let intervalStart = 0.0; + let currentSample = 1; + const lastSample = kSplineTableSize - 1; for (; currentSample !== lastSample && sampleValues[currentSample] <= aX; ++currentSample) { intervalStart += kSampleStepSize; @@ -78,10 +78,10 @@ --currentSample; // Interpolate to provide an initial guess for t - var dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]); - var guessForT = intervalStart + dist * kSampleStepSize; + const dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]); + const guessForT = intervalStart + dist * kSampleStepSize; - var initialSlope = getSlope(guessForT, mX1, mX2); + const initialSlope = getSlope(guessForT, mX1, mX2); if (initialSlope >= NEWTON_MIN_SLOPE) { return newtonRaphsonIterate(aX, guessForT, mX1, mX2); } else if (initialSlope === 0.0) { diff --git a/Libraries/BatchedBridge/__mocks__/MessageQueueTestConfig.js b/Libraries/BatchedBridge/__mocks__/MessageQueueTestConfig.js index 40ad81f5f..2fa722fb3 100644 --- a/Libraries/BatchedBridge/__mocks__/MessageQueueTestConfig.js +++ b/Libraries/BatchedBridge/__mocks__/MessageQueueTestConfig.js @@ -7,12 +7,12 @@ * These don't actually exist anywhere in the code. */ 'use strict'; -var remoteModulesConfig = [ +const remoteModulesConfig = [ ['RemoteModule1',null,['remoteMethod','promiseMethod'],[]], ['RemoteModule2',null,['remoteMethod','promiseMethod'],[]], ]; -var MessageQueueTestConfig = { +const MessageQueueTestConfig = { remoteModuleConfig: remoteModulesConfig, }; diff --git a/Libraries/BatchedBridge/__mocks__/MessageQueueTestModule.js b/Libraries/BatchedBridge/__mocks__/MessageQueueTestModule.js index 8c4f7d3c0..7d4f5f1a5 100644 --- a/Libraries/BatchedBridge/__mocks__/MessageQueueTestModule.js +++ b/Libraries/BatchedBridge/__mocks__/MessageQueueTestModule.js @@ -12,7 +12,7 @@ * correctly dispatches to commonJS modules. The `testHook` is overriden by test * cases. */ -var MessageQueueTestModule = { +const MessageQueueTestModule = { testHook1: function() { }, testHook2: function() { diff --git a/Libraries/Blob/__tests__/Blob-test.js b/Libraries/Blob/__tests__/Blob-test.js index 8d3791572..47bf5fee7 100644 --- a/Libraries/Blob/__tests__/Blob-test.js +++ b/Libraries/Blob/__tests__/Blob-test.js @@ -13,7 +13,7 @@ jest.setMock('NativeModules', { BlobModule: require('../__mocks__/BlobModule'), }); -var Blob = require('Blob'); +const Blob = require('Blob'); describe('Blob', function() { it('should create empty blob', () => { diff --git a/Libraries/Blob/__tests__/BlobManager-test.js b/Libraries/Blob/__tests__/BlobManager-test.js index 2ed118b44..c141d42f1 100644 --- a/Libraries/Blob/__tests__/BlobManager-test.js +++ b/Libraries/Blob/__tests__/BlobManager-test.js @@ -13,8 +13,8 @@ jest.setMock('NativeModules', { BlobModule: require('../__mocks__/BlobModule'), }); -var Blob = require('Blob'); -var BlobManager = require('BlobManager'); +const Blob = require('Blob'); +const BlobManager = require('BlobManager'); describe('BlobManager', function() { it('should create blob from parts', () => { diff --git a/Libraries/Blob/__tests__/FileReader-test.js b/Libraries/Blob/__tests__/FileReader-test.js index a278a4918..b2237550b 100644 --- a/Libraries/Blob/__tests__/FileReader-test.js +++ b/Libraries/Blob/__tests__/FileReader-test.js @@ -14,8 +14,8 @@ jest.unmock('event-target-shim').setMock('NativeModules', { FileReaderModule: require('../__mocks__/FileReaderModule'), }); -var Blob = require('Blob'); -var FileReader = require('FileReader'); +const Blob = require('Blob'); +const FileReader = require('FileReader'); describe('FileReader', function() { it('should read blob as text', async () => { diff --git a/Libraries/BugReporting/getReactData.js b/Libraries/BugReporting/getReactData.js index 3f7a1a903..f995e8f41 100644 --- a/Libraries/BugReporting/getReactData.js +++ b/Libraries/BugReporting/getReactData.js @@ -15,16 +15,16 @@ * https://github.com/facebook/react-devtools/blob/master/backend/getData.js */ function getData(element: Object): Object { - var children = null; - var props = null; - var state = null; - var context = null; - var updater = null; - var name = null; - var type = null; - var text = null; - var publicInstance = null; - var nodeType = 'Native'; + let children = null; + let props = null; + let state = null; + let context = null; + let updater = null; + let name = null; + let type = null; + let text = null; + let publicInstance = null; + let nodeType = 'Native'; // If the parent is a native node without rendered children, but with // multiple string children, then the `element` that gets passed in here is // a plain value -- a string or number. @@ -80,7 +80,7 @@ function getData(element: Object): Object { } if (element._instance) { - var inst = element._instance; + const inst = element._instance; updater = { setState: inst.setState && inst.setState.bind(inst), forceUpdate: inst.forceUpdate && inst.forceUpdate.bind(inst), @@ -113,7 +113,7 @@ function getData(element: Object): Object { } function setInProps(internalInst, path: Array, value: any) { - var element = internalInst._currentElement; + const element = internalInst._currentElement; internalInst._currentElement = { ...element, props: copyWithSet(element.props, path, value), @@ -132,16 +132,16 @@ function setInContext(inst, path: Array, value: any) { } function setIn(obj: Object, path: Array, value: any) { - var last = path.pop(); - var parent = path.reduce((obj_, attr) => obj_ ? obj_[attr] : null, obj); + const last = path.pop(); + const parent = path.reduce((obj_, attr) => obj_ ? obj_[attr] : null, obj); if (parent) { parent[last] = value; } } function childrenList(children) { - var res = []; - for (var name in children) { + const res = []; + for (const name in children) { res.push(children[name]); } return res; @@ -151,8 +151,8 @@ function copyWithSetImpl(obj, path, idx, value) { if (idx >= path.length) { return value; } - var key = path[idx]; - var updated = Array.isArray(obj) ? obj.slice() : {...obj}; + const key = path[idx]; + const updated = Array.isArray(obj) ? obj.slice() : {...obj}; // $FlowFixMe number or string is fine here updated[key] = copyWithSetImpl(obj[key], path, idx + 1, value); return updated; diff --git a/Libraries/CameraRoll/ImagePickerIOS.js b/Libraries/CameraRoll/ImagePickerIOS.js index fe50825da..b653c1109 100644 --- a/Libraries/CameraRoll/ImagePickerIOS.js +++ b/Libraries/CameraRoll/ImagePickerIOS.js @@ -8,9 +8,9 @@ */ 'use strict'; -var RCTImagePicker = require('NativeModules').ImagePickerIOS; +const RCTImagePicker = require('NativeModules').ImagePickerIOS; -var ImagePickerIOS = { +const ImagePickerIOS = { canRecordVideos: function(callback: Function) { return RCTImagePicker.canRecordVideos(callback); }, diff --git a/Libraries/Color/normalizeColor.js b/Libraries/Color/normalizeColor.js index de62e68da..59b3eb33b 100755 --- a/Libraries/Color/normalizeColor.js +++ b/Libraries/Color/normalizeColor.js @@ -10,7 +10,7 @@ 'use strict'; function normalizeColor(color: string | number): ?number { - var match; + let match; if (typeof color === 'number') { if (color >>> 0 === color && color >= 0 && color <= 0xffffffff) { @@ -31,18 +31,18 @@ function normalizeColor(color: string | number): ?number { if ((match = matchers.rgb.exec(color))) { return ( (// b - parse255(match[1]) << 24 | // r + (parse255(match[1]) << 24 | // r parse255(match[2]) << 16 | // g - parse255(match[3]) << 8 | 0x000000ff) // a + parse255(match[3]) << 8 | 0x000000ff)) // a ) >>> 0; } if ((match = matchers.rgba.exec(color))) { return ( (// b - parse255(match[1]) << 24 | // r + (parse255(match[1]) << 24 | // r parse255(match[2]) << 16 | // g - parse255(match[3]) << 8 | parse1(match[4])) // a + parse255(match[3]) << 8 | parse1(match[4]))) // a ) >>> 0; } @@ -114,11 +114,11 @@ function hue2rgb(p: number, q: number, t: number): number { } function hslToRgb(h: number, s: number, l: number): number { - var q = l < 0.5 ? l * (1 + s) : l + s - l * s; - var p = 2 * l - q; - var r = hue2rgb(p, q, h + 1 / 3); - var g = hue2rgb(p, q, h); - var b = hue2rgb(p, q, h - 1 / 3); + const q = l < 0.5 ? l * (1 + s) : l + s - l * s; + const p = 2 * l - q; + const r = hue2rgb(p, q, h + 1 / 3); + const g = hue2rgb(p, q, h); + const b = hue2rgb(p, q, h - 1 / 3); return ( Math.round(r * 255) << 24 | @@ -128,14 +128,14 @@ function hslToRgb(h: number, s: number, l: number): number { } // var INTEGER = '[-+]?\\d+'; -var NUMBER = '[-+]?\\d*\\.?\\d+'; -var PERCENTAGE = NUMBER + '%'; +const NUMBER = '[-+]?\\d*\\.?\\d+'; +const PERCENTAGE = NUMBER + '%'; function call(...args) { return '\\(\\s*(' + args.join(')\\s*,\\s*(') + ')\\s*\\)'; } -var matchers = { +const matchers = { rgb: new RegExp('rgb' + call(NUMBER, NUMBER, NUMBER)), rgba: new RegExp('rgba' + call(NUMBER, NUMBER, NUMBER, NUMBER)), hsl: new RegExp('hsl' + call(NUMBER, PERCENTAGE, PERCENTAGE)), @@ -147,7 +147,7 @@ var matchers = { }; function parse255(str: string): number { - var int = parseInt(str, 10); + const int = parseInt(str, 10); if (int < 0) { return 0; } @@ -158,12 +158,12 @@ function parse255(str: string): number { } function parse360(str: string): number { - var int = parseFloat(str); + const int = parseFloat(str); return (((int % 360) + 360) % 360) / 360; } function parse1(str: string): number { - var num = parseFloat(str); + const num = parseFloat(str); if (num < 0) { return 0; } @@ -175,7 +175,7 @@ function parse1(str: string): number { function parsePercentage(str: string): number { // parseFloat conveniently ignores the final % - var int = parseFloat(str); + const int = parseFloat(str); if (int < 0) { return 0; } @@ -185,7 +185,7 @@ function parsePercentage(str: string): number { return int / 100; } -var names = { +const names = { transparent: 0x00000000, // http://www.w3.org/TR/css3-color/#svg-color diff --git a/Libraries/Core/Devtools/__tests__/parseErrorStack-test.js b/Libraries/Core/Devtools/__tests__/parseErrorStack-test.js index beaa629d7..7726a6117 100644 --- a/Libraries/Core/Devtools/__tests__/parseErrorStack-test.js +++ b/Libraries/Core/Devtools/__tests__/parseErrorStack-test.js @@ -9,7 +9,7 @@ 'use strict'; -var parseErrorStack = require('parseErrorStack'); +const parseErrorStack = require('parseErrorStack'); function getFakeError() { return new Error('Happy Cat'); @@ -18,24 +18,24 @@ function getFakeError() { describe('parseErrorStack', function() { it('parses error stack', function() { - var stack = parseErrorStack(getFakeError()); + const stack = parseErrorStack(getFakeError()); expect(stack.length).toBeGreaterThan(0); - var firstFrame = stack[0]; + const firstFrame = stack[0]; expect(firstFrame.methodName).toEqual('getFakeError'); expect(firstFrame.file).toMatch(/parseErrorStack-test\.js$/); }); it('supports framesToPop', function() { function getWrappedError() { - var error = getFakeError(); + const error = getFakeError(); error.framesToPop = 1; return error; } // Make sure framesToPop == 1 causes it to ignore getFakeError // stack frame - var stack = parseErrorStack(getWrappedError()); + const stack = parseErrorStack(getWrappedError()); expect(stack[0].methodName).toEqual('getWrappedError'); }); diff --git a/Libraries/Core/__mocks__/ErrorUtils.js b/Libraries/Core/__mocks__/ErrorUtils.js index 2ab128040..6b2282672 100644 --- a/Libraries/Core/__mocks__/ErrorUtils.js +++ b/Libraries/Core/__mocks__/ErrorUtils.js @@ -19,7 +19,7 @@ function reportError(error) { throw error; } -var ErrorUtils = { +const ErrorUtils = { apply: jest.fn(execute), applyWithGuard: jest.fn(execute), guard: jest.fn(callback => callback), diff --git a/Libraries/Experimental/IncrementalExample.js b/Libraries/Experimental/IncrementalExample.js index e46510b5e..7f006d38b 100644 --- a/Libraries/Experimental/IncrementalExample.js +++ b/Libraries/Experimental/IncrementalExample.js @@ -153,7 +153,7 @@ function burnCPU(milliseconds) { while (performanceNow() < (start + milliseconds)) {} } -var styles = StyleSheet.create({ +const styles = StyleSheet.create({ scrollView: { margin: 10, backgroundColor: 'white', diff --git a/Libraries/Geolocation/Geolocation.js b/Libraries/Geolocation/Geolocation.js index 29bb0aa13..8bdc21263 100644 --- a/Libraries/Geolocation/Geolocation.js +++ b/Libraries/Geolocation/Geolocation.js @@ -23,8 +23,8 @@ const LocationEventEmitter = new NativeEventEmitter(RCTLocationObserver); const Platform = require('Platform'); const PermissionsAndroid = require('PermissionsAndroid'); -var subscriptions = []; -var updatesEnabled = false; +let subscriptions = []; +let updatesEnabled = false; type GeoConfiguration = { skipPermissionRequests: bool; @@ -44,7 +44,7 @@ type GeoOptions = { * * See https://facebook.github.io/react-native/docs/geolocation.html */ -var Geolocation = { +const Geolocation = { /* * Sets configuration options that will be used in all location requests. @@ -116,7 +116,7 @@ var Geolocation = { RCTLocationObserver.startObserving(options || {}); updatesEnabled = true; } - var watchID = subscriptions.length; + const watchID = subscriptions.length; subscriptions.push([ LocationEventEmitter.addListener( 'geolocationDidChange', @@ -131,7 +131,7 @@ var Geolocation = { }, clearWatch: function(watchID: number) { - var sub = subscriptions[watchID]; + const sub = subscriptions[watchID]; if (!sub) { // Silently exit when the watchID is invalid or already cleared // This is consistent with timers @@ -140,10 +140,10 @@ var Geolocation = { sub[0].remove(); // array element refinements not yet enabled in Flow - var sub1 = sub[1]; sub1 && sub1.remove(); + const sub1 = sub[1]; sub1 && sub1.remove(); subscriptions[watchID] = undefined; - var noWatchers = true; - for (var ii = 0; ii < subscriptions.length; ii++) { + let noWatchers = true; + for (let ii = 0; ii < subscriptions.length; ii++) { if (subscriptions[ii]) { noWatchers = false; // still valid subscriptions } @@ -157,13 +157,13 @@ var Geolocation = { if (updatesEnabled) { RCTLocationObserver.stopObserving(); updatesEnabled = false; - for (var ii = 0; ii < subscriptions.length; ii++) { - var sub = subscriptions[ii]; + for (let ii = 0; ii < subscriptions.length; ii++) { + const sub = subscriptions[ii]; if (sub) { warning(false, 'Called stopObserving with existing subscriptions.'); sub[0].remove(); // array element refinements not yet enabled in Flow - var sub1 = sub[1]; sub1 && sub1.remove(); + const sub1 = sub[1]; sub1 && sub1.remove(); } } subscriptions = []; diff --git a/Libraries/Image/AssetRegistry.js b/Libraries/Image/AssetRegistry.js index 5f5f0980f..ad1b495af 100644 --- a/Libraries/Image/AssetRegistry.js +++ b/Libraries/Image/AssetRegistry.js @@ -21,7 +21,7 @@ export type PackagerAsset = { +type: string, }; -var assets: Array = []; +const assets: Array = []; function registerAsset(asset: PackagerAsset): number { // `push` returns new array length, so the first asset will diff --git a/Libraries/Image/AssetSourceResolver.js b/Libraries/Image/AssetSourceResolver.js index d7b583ebc..6ae1a7801 100644 --- a/Libraries/Image/AssetSourceResolver.js +++ b/Libraries/Image/AssetSourceResolver.js @@ -29,9 +29,9 @@ const invariant = require('fbjs/lib/invariant'); * Returns a path like 'assets/AwesomeModule/icon@2x.png' */ function getScaledAssetPath(asset): string { - var scale = AssetSourceResolver.pickScale(asset.scales, PixelRatio.get()); - var scaleSuffix = scale === 1 ? '' : '@' + scale + 'x'; - var assetDir = assetPathUtils.getBasePath(asset); + const scale = AssetSourceResolver.pickScale(asset.scales, PixelRatio.get()); + const scaleSuffix = scale === 1 ? '' : '@' + scale + 'x'; + const assetDir = assetPathUtils.getBasePath(asset); return assetDir + '/' + asset.name + scaleSuffix + '.' + asset.type; } @@ -39,9 +39,9 @@ function getScaledAssetPath(asset): string { * Returns a path like 'drawable-mdpi/icon.png' */ function getAssetPathInDrawableFolder(asset): string { - var scale = AssetSourceResolver.pickScale(asset.scales, PixelRatio.get()); - var drawbleFolder = assetPathUtils.getAndroidResourceFolderName(asset, scale); - var fileName = assetPathUtils.getAndroidResourceIdentifier(asset); + const scale = AssetSourceResolver.pickScale(asset.scales, PixelRatio.get()); + const drawbleFolder = assetPathUtils.getAndroidResourceFolderName(asset, scale); + const fileName = assetPathUtils.getAndroidResourceIdentifier(asset); return drawbleFolder + '/' + fileName + '.' + asset.type; } @@ -151,7 +151,7 @@ class AssetSourceResolver { static pickScale(scales: Array, deviceScale: number): number { // Packager guarantees that `scales` array is sorted - for (var i = 0; i < scales.length; i++) { + for (let i = 0; i < scales.length; i++) { if (scales[i] >= deviceScale) { return scales[i]; } diff --git a/Libraries/Image/Image.android.js b/Libraries/Image/Image.android.js index d9702700b..b54d62411 100644 --- a/Libraries/Image/Image.android.js +++ b/Libraries/Image/Image.android.js @@ -10,25 +10,25 @@ 'use strict'; -var ImageResizeMode = require('ImageResizeMode'); -var ImageStylePropTypes = require('ImageStylePropTypes'); -var NativeMethodsMixin = require('NativeMethodsMixin'); -var NativeModules = require('NativeModules'); -var React = require('React'); -var PropTypes = require('prop-types'); -var ReactNativeViewAttributes = require('ReactNativeViewAttributes'); -var StyleSheet = require('StyleSheet'); -var StyleSheetPropType = require('StyleSheetPropType'); +const ImageResizeMode = require('ImageResizeMode'); +const ImageStylePropTypes = require('ImageStylePropTypes'); +const NativeMethodsMixin = require('NativeMethodsMixin'); +const NativeModules = require('NativeModules'); +const React = require('React'); +const PropTypes = require('prop-types'); +const ReactNativeViewAttributes = require('ReactNativeViewAttributes'); +const StyleSheet = require('StyleSheet'); +const StyleSheetPropType = require('StyleSheetPropType'); const TextAncestor = require('TextAncestor'); -var ViewPropTypes = require('ViewPropTypes'); +const ViewPropTypes = require('ViewPropTypes'); -var createReactClass = require('create-react-class'); -var flattenStyle = require('flattenStyle'); -var merge = require('merge'); -var requireNativeComponent = require('requireNativeComponent'); -var resolveAssetSource = require('resolveAssetSource'); +const createReactClass = require('create-react-class'); +const flattenStyle = require('flattenStyle'); +const merge = require('merge'); +const requireNativeComponent = require('requireNativeComponent'); +const resolveAssetSource = require('resolveAssetSource'); -var {ImageLoader} = NativeModules; +const {ImageLoader} = NativeModules; let _requestId = 1; function generateRequestId() { @@ -42,7 +42,7 @@ function generateRequestId() { * * See https://facebook.github.io/react-native/docs/image.html */ -var Image = createReactClass({ +const Image = createReactClass({ displayName: 'Image', propTypes: { ...ViewPropTypes, @@ -275,13 +275,13 @@ var Image = createReactClass({ }, }); -var styles = StyleSheet.create({ +const styles = StyleSheet.create({ base: { overflow: 'hidden', }, }); -var cfg = { +const cfg = { nativeOnly: { src: true, headers: true, @@ -290,8 +290,8 @@ var cfg = { shouldNotifyLoadEvents: true, }, }; -var RKImage = requireNativeComponent('RCTImageView', Image, cfg); -var RCTTextInlineImage = requireNativeComponent( +const RKImage = requireNativeComponent('RCTImageView', Image, cfg); +const RCTTextInlineImage = requireNativeComponent( 'RCTTextInlineImage', Image, cfg, diff --git a/Libraries/Image/ImageResizeMode.js b/Libraries/Image/ImageResizeMode.js index 89e74bcc5..48779e383 100644 --- a/Libraries/Image/ImageResizeMode.js +++ b/Libraries/Image/ImageResizeMode.js @@ -12,13 +12,13 @@ /* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error * found when Flow v0.54 was deployed. To see the error delete this comment and * run Flow. */ -var keyMirror = require('fbjs/lib/keyMirror'); +const keyMirror = require('fbjs/lib/keyMirror'); /** * ImageResizeMode - Enum for different image resizing modes, set via * `resizeMode` style property on `` components. */ -var ImageResizeMode = keyMirror({ +const ImageResizeMode = keyMirror({ /** * contain - The image will be resized such that it will be completely * visible, contained within the frame of the View. diff --git a/Libraries/Image/ImageStylePropTypes.js b/Libraries/Image/ImageStylePropTypes.js index c88c19ea3..54e500994 100644 --- a/Libraries/Image/ImageStylePropTypes.js +++ b/Libraries/Image/ImageStylePropTypes.js @@ -9,14 +9,14 @@ */ 'use strict'; -var ColorPropType = require('ColorPropType'); -var ImageResizeMode = require('ImageResizeMode'); -var LayoutPropTypes = require('LayoutPropTypes'); -var ReactPropTypes = require('prop-types'); -var ShadowPropTypesIOS = require('ShadowPropTypesIOS'); -var TransformPropTypes = require('TransformPropTypes'); +const ColorPropType = require('ColorPropType'); +const ImageResizeMode = require('ImageResizeMode'); +const LayoutPropTypes = require('LayoutPropTypes'); +const ReactPropTypes = require('prop-types'); +const ShadowPropTypesIOS = require('ShadowPropTypesIOS'); +const TransformPropTypes = require('TransformPropTypes'); -var ImageStylePropTypes = { +const ImageStylePropTypes = { ...LayoutPropTypes, ...ShadowPropTypesIOS, ...TransformPropTypes, diff --git a/Libraries/Image/RelativeImageStub.js b/Libraries/Image/RelativeImageStub.js index 866488eec..1a74c36cb 100644 --- a/Libraries/Image/RelativeImageStub.js +++ b/Libraries/Image/RelativeImageStub.js @@ -11,7 +11,7 @@ // This is a stub for flow to make it understand require('./icon.png') // See metro/src/Bundler/index.js -var AssetRegistry = require('AssetRegistry'); +const AssetRegistry = require('AssetRegistry'); module.exports = AssetRegistry.registerAsset({ __packager_asset: true, diff --git a/Libraries/Image/__tests__/resolveAssetSource-test.js b/Libraries/Image/__tests__/resolveAssetSource-test.js index 50a666a5b..db1a0a853 100644 --- a/Libraries/Image/__tests__/resolveAssetSource-test.js +++ b/Libraries/Image/__tests__/resolveAssetSource-test.js @@ -8,13 +8,13 @@ */ 'use strict'; -var AssetRegistry = require('AssetRegistry'); -var Platform = require('Platform'); -var NativeModules = require('NativeModules'); -var resolveAssetSource = require('../resolveAssetSource'); +const AssetRegistry = require('AssetRegistry'); +const Platform = require('Platform'); +const NativeModules = require('NativeModules'); +const resolveAssetSource = require('../resolveAssetSource'); function expectResolvesAsset(input, expectedSource) { - var assetId = AssetRegistry.registerAsset(input); + const assetId = AssetRegistry.registerAsset(input); expect(resolveAssetSource(assetId)).toEqual(expectedSource); } @@ -24,10 +24,10 @@ describe('resolveAssetSource', () => { }); it('returns same source for simple static and network images', () => { - var source1 = {uri: 'https://www.facebook.com/logo'}; + const source1 = {uri: 'https://www.facebook.com/logo'}; expect(resolveAssetSource(source1)).toBe(source1); - var source2 = {uri: 'logo'}; + const source2 = {uri: 'logo'}; expect(resolveAssetSource(source2)).toBe(source2); }); diff --git a/Libraries/Image/resolveAssetSource.js b/Libraries/Image/resolveAssetSource.js index fefb28ff5..fe483beff 100644 --- a/Libraries/Image/resolveAssetSource.js +++ b/Libraries/Image/resolveAssetSource.js @@ -85,7 +85,7 @@ function resolveAssetSource(source: any): ?ResolvedAssetSource { return source; } - var asset = AssetRegistry.getAssetByID(source); + const asset = AssetRegistry.getAssetByID(source); if (!asset) { return null; } diff --git a/Libraries/Inspector/BorderBox.js b/Libraries/Inspector/BorderBox.js index 7ed32e73a..21ace69d9 100644 --- a/Libraries/Inspector/BorderBox.js +++ b/Libraries/Inspector/BorderBox.js @@ -8,16 +8,16 @@ */ 'use strict'; -var React = require('React'); -var View = require('View'); +const React = require('React'); +const View = require('View'); class BorderBox extends React.Component<$FlowFixMeProps> { render() { - var box = this.props.box; + const box = this.props.box; if (!box) { return this.props.children; } - var style = { + const style = { borderTopWidth: box.top, borderBottomWidth: box.bottom, borderLeftWidth: box.left, diff --git a/Libraries/Inspector/BoxInspector.js b/Libraries/Inspector/BoxInspector.js index 6009e78ea..11fe9c8c9 100644 --- a/Libraries/Inspector/BoxInspector.js +++ b/Libraries/Inspector/BoxInspector.js @@ -8,13 +8,13 @@ */ 'use strict'; -var React = require('React'); -var StyleSheet = require('StyleSheet'); -var Text = require('Text'); -var View = require('View'); -var resolveBoxStyle = require('resolveBoxStyle'); +const React = require('React'); +const StyleSheet = require('StyleSheet'); +const Text = require('Text'); +const View = require('View'); +const resolveBoxStyle = require('resolveBoxStyle'); -var blank = { +const blank = { top: 0, left: 0, right: 0, @@ -23,10 +23,10 @@ var blank = { class BoxInspector extends React.Component<$FlowFixMeProps> { render() { - var frame = this.props.frame; - var style = this.props.style; - var margin = style && resolveBoxStyle('margin', style) || blank; - var padding = style && resolveBoxStyle('padding', style) || blank; + const frame = this.props.frame; + const style = this.props.style; + const margin = style && resolveBoxStyle('margin', style) || blank; + const padding = style && resolveBoxStyle('padding', style) || blank; return ( @@ -46,7 +46,7 @@ class BoxInspector extends React.Component<$FlowFixMeProps> { class BoxContainer extends React.Component<$FlowFixMeProps> { render() { - var box = this.props.box; + const box = this.props.box; return ( @@ -66,7 +66,7 @@ class BoxContainer extends React.Component<$FlowFixMeProps> { } } -var styles = StyleSheet.create({ +const styles = StyleSheet.create({ row: { flexDirection: 'row', alignItems: 'center', diff --git a/Libraries/Inspector/ElementBox.js b/Libraries/Inspector/ElementBox.js index 7eebb22f3..17b2c8920 100644 --- a/Libraries/Inspector/ElementBox.js +++ b/Libraries/Inspector/ElementBox.js @@ -8,20 +8,20 @@ */ 'use strict'; -var React = require('React'); -var View = require('View'); -var StyleSheet = require('StyleSheet'); -var BorderBox = require('BorderBox'); -var resolveBoxStyle = require('resolveBoxStyle'); +const React = require('React'); +const View = require('View'); +const StyleSheet = require('StyleSheet'); +const BorderBox = require('BorderBox'); +const resolveBoxStyle = require('resolveBoxStyle'); -var flattenStyle = require('flattenStyle'); +const flattenStyle = require('flattenStyle'); class ElementBox extends React.Component<$FlowFixMeProps> { render() { - var style = flattenStyle(this.props.style) || {}; - var margin = resolveBoxStyle('margin', style); - var padding = resolveBoxStyle('padding', style); - var frameStyle = this.props.frame; + const style = flattenStyle(this.props.style) || {}; + const margin = resolveBoxStyle('margin', style); + const padding = resolveBoxStyle('padding', style); + let frameStyle = this.props.frame; if (margin) { frameStyle = { top: frameStyle.top - margin.top, @@ -30,7 +30,7 @@ class ElementBox extends React.Component<$FlowFixMeProps> { width: frameStyle.width + margin.left + margin.right, }; } - var contentStyle = { + let contentStyle = { width: this.props.frame.width, height: this.props.frame.height, }; @@ -52,7 +52,7 @@ class ElementBox extends React.Component<$FlowFixMeProps> { } } -var styles = StyleSheet.create({ +const styles = StyleSheet.create({ frame: { position: 'absolute', }, diff --git a/Libraries/Inspector/InspectorOverlay.js b/Libraries/Inspector/InspectorOverlay.js index 3ef8ae60f..a2dda0b31 100644 --- a/Libraries/Inspector/InspectorOverlay.js +++ b/Libraries/Inspector/InspectorOverlay.js @@ -8,13 +8,13 @@ */ 'use strict'; -var Dimensions = require('Dimensions'); -var ElementBox = require('ElementBox'); -var PropTypes = require('prop-types'); -var React = require('React'); -var StyleSheet = require('StyleSheet'); -var UIManager = require('UIManager'); -var View = require('View'); +const Dimensions = require('Dimensions'); +const ElementBox = require('ElementBox'); +const PropTypes = require('prop-types'); +const React = require('React'); +const StyleSheet = require('StyleSheet'); +const UIManager = require('UIManager'); +const View = require('View'); type EventLike = { nativeEvent: Object, @@ -38,7 +38,7 @@ class InspectorOverlay extends React.Component<{ }; findViewForTouchEvent = (e: EventLike) => { - var {locationX, locationY} = e.nativeEvent.touches[0]; + const {locationX, locationY} = e.nativeEvent.touches[0]; UIManager.findSubviewIn( this.props.inspectedViewTag, [locationX, locationY], @@ -54,7 +54,7 @@ class InspectorOverlay extends React.Component<{ }; render() { - var content = null; + let content = null; if (this.props.inspected) { content = ; } @@ -70,7 +70,7 @@ class InspectorOverlay extends React.Component<{ } } -var styles = StyleSheet.create({ +const styles = StyleSheet.create({ inspector: { backgroundColor: 'transparent', position: 'absolute', diff --git a/Libraries/Inspector/PerformanceOverlay.js b/Libraries/Inspector/PerformanceOverlay.js index d414ea2db..b75c8f1b3 100644 --- a/Libraries/Inspector/PerformanceOverlay.js +++ b/Libraries/Inspector/PerformanceOverlay.js @@ -8,20 +8,20 @@ */ 'use strict'; -var PerformanceLogger = require('PerformanceLogger'); -var React = require('React'); -var StyleSheet = require('StyleSheet'); -var Text = require('Text'); -var View = require('View'); +const PerformanceLogger = require('PerformanceLogger'); +const React = require('React'); +const StyleSheet = require('StyleSheet'); +const Text = require('Text'); +const View = require('View'); class PerformanceOverlay extends React.Component<{}> { render() { - var perfLogs = PerformanceLogger.getTimespans(); - var items = []; + const perfLogs = PerformanceLogger.getTimespans(); + const items = []; - for (var key in perfLogs) { + for (const key in perfLogs) { if (perfLogs[key].totalTime) { - var unit = (key === 'BundleSize') ? 'b' : 'ms'; + const unit = (key === 'BundleSize') ? 'b' : 'ms'; items.push( {key} @@ -41,7 +41,7 @@ class PerformanceOverlay extends React.Component<{}> { } } -var styles = StyleSheet.create({ +const styles = StyleSheet.create({ container: { height: 100, paddingTop: 10, diff --git a/Libraries/Inspector/StyleInspector.js b/Libraries/Inspector/StyleInspector.js index a65e02799..df32a6688 100644 --- a/Libraries/Inspector/StyleInspector.js +++ b/Libraries/Inspector/StyleInspector.js @@ -8,17 +8,17 @@ */ 'use strict'; -var React = require('React'); -var StyleSheet = require('StyleSheet'); -var Text = require('Text'); -var View = require('View'); +const React = require('React'); +const StyleSheet = require('StyleSheet'); +const Text = require('Text'); +const View = require('View'); class StyleInspector extends React.Component<$FlowFixMeProps> { render() { if (!this.props.style) { return No style; } - var names = Object.keys(this.props.style); + const names = Object.keys(this.props.style); return ( @@ -27,7 +27,7 @@ class StyleInspector extends React.Component<$FlowFixMeProps> { {names.map(name => { - var value = typeof this.props.style[name] === 'object' ? JSON.stringify(this.props.style[name]) : this.props.style[name]; + const value = typeof this.props.style[name] === 'object' ? JSON.stringify(this.props.style[name]) : this.props.style[name]; return {value}; } ) } @@ -36,7 +36,7 @@ class StyleInspector extends React.Component<$FlowFixMeProps> { } } -var styles = StyleSheet.create({ +const styles = StyleSheet.create({ container: { flexDirection: 'row', }, diff --git a/Libraries/Inspector/resolveBoxStyle.js b/Libraries/Inspector/resolveBoxStyle.js index 43026ada8..27c89de9b 100644 --- a/Libraries/Inspector/resolveBoxStyle.js +++ b/Libraries/Inspector/resolveBoxStyle.js @@ -18,9 +18,9 @@ * If none are set, returns false. */ function resolveBoxStyle(prefix: string, style: Object): ?Object { - var res = {}; - var subs = ['top', 'left', 'bottom', 'right']; - var set = false; + const res = {}; + const subs = ['top', 'left', 'bottom', 'right']; + let set = false; subs.forEach(sub => { res[sub] = style[prefix] || 0; }); @@ -36,7 +36,7 @@ function resolveBoxStyle(prefix: string, style: Object): ?Object { set = true; } subs.forEach(sub => { - var val = style[prefix + capFirst(sub)]; + const val = style[prefix + capFirst(sub)]; if (val) { res[sub] = val; set = true; diff --git a/Libraries/Interaction/InteractionManager.js b/Libraries/Interaction/InteractionManager.js index 7373575a0..3d2f2fa46 100644 --- a/Libraries/Interaction/InteractionManager.js +++ b/Libraries/Interaction/InteractionManager.js @@ -77,7 +77,7 @@ const DEBUG = false; * allowing events such as touches to start interactions and block queued tasks * from executing, making apps more responsive. */ -var InteractionManager = { +const InteractionManager = { Events: keyMirror({ interactionStart: true, interactionComplete: true, @@ -118,7 +118,7 @@ var InteractionManager = { createInteractionHandle(): Handle { DEBUG && infoLog('create interaction handle'); _scheduleUpdate(); - var handle = ++_inc; + const handle = ++_inc; _addInteractionSet.add(handle); return handle; }, @@ -181,14 +181,14 @@ function _scheduleUpdate() { function _processUpdate() { _nextUpdateHandle = 0; - var interactionCount = _interactionSet.size; + const interactionCount = _interactionSet.size; _addInteractionSet.forEach(handle => _interactionSet.add(handle) ); _deleteInteractionSet.forEach(handle => _interactionSet.delete(handle) ); - var nextInteractionCount = _interactionSet.size; + const nextInteractionCount = _interactionSet.size; if (interactionCount !== 0 && nextInteractionCount === 0) { // transition from 1+ --> 0 interactions diff --git a/Libraries/Interaction/InteractionMixin.js b/Libraries/Interaction/InteractionMixin.js index e4310ad91..018ca1bd1 100644 --- a/Libraries/Interaction/InteractionMixin.js +++ b/Libraries/Interaction/InteractionMixin.js @@ -8,14 +8,14 @@ */ 'use strict'; -var InteractionManager = require('InteractionManager'); +const InteractionManager = require('InteractionManager'); /** * This mixin provides safe versions of InteractionManager start/end methods * that ensures `clearInteractionHandle` is always called * once per start, even if the component is unmounted. */ -var InteractionMixin = { +const InteractionMixin = { componentWillUnmount: function() { while (this._interactionMixinHandles.length) { InteractionManager.clearInteractionHandle( @@ -27,7 +27,7 @@ var InteractionMixin = { _interactionMixinHandles: ([]: Array), createInteractionHandle: function() { - var handle = InteractionManager.createInteractionHandle(); + const handle = InteractionManager.createInteractionHandle(); this._interactionMixinHandles.push(handle); return handle; }, diff --git a/Libraries/Interaction/__tests__/InteractionMixin-test.js b/Libraries/Interaction/__tests__/InteractionMixin-test.js index 08f33d759..7a3675b13 100644 --- a/Libraries/Interaction/__tests__/InteractionMixin-test.js +++ b/Libraries/Interaction/__tests__/InteractionMixin-test.js @@ -11,9 +11,9 @@ jest.enableAutomock().unmock('InteractionMixin'); describe('InteractionMixin', () => { - var InteractionManager; - var InteractionMixin; - var component; + let InteractionManager; + let InteractionMixin; + let component; beforeEach(() => { jest.resetModules(); @@ -29,19 +29,19 @@ describe('InteractionMixin', () => { }); it('should end interactions', () => { - var handle = {}; + const handle = {}; component.clearInteractionHandle(handle); expect(InteractionManager.clearInteractionHandle).toBeCalledWith(handle); }); it('should schedule tasks', () => { - var task = jest.fn(); + const task = jest.fn(); component.runAfterInteractions(task); expect(InteractionManager.runAfterInteractions).toBeCalledWith(task); }); it('should end unfinished interactions in componentWillUnmount', () => { - var handle = component.createInteractionHandle(); + const handle = component.createInteractionHandle(); component.componentWillUnmount(); expect(InteractionManager.clearInteractionHandle).toBeCalledWith(handle); }); diff --git a/Libraries/Lists/ListView/ListView.js b/Libraries/Lists/ListView/ListView.js index b36150510..cd168bc65 100644 --- a/Libraries/Lists/ListView/ListView.js +++ b/Libraries/Lists/ListView/ListView.js @@ -9,34 +9,34 @@ */ 'use strict'; -var ListViewDataSource = require('ListViewDataSource'); -var Platform = require('Platform'); -var React = require('React'); -var PropTypes = require('prop-types'); -var ReactNative = require('ReactNative'); -var RCTScrollViewManager = require('NativeModules').ScrollViewManager; -var ScrollView = require('ScrollView'); -var ScrollResponder = require('ScrollResponder'); -var StaticRenderer = require('StaticRenderer'); +const ListViewDataSource = require('ListViewDataSource'); +const Platform = require('Platform'); +const React = require('React'); +const PropTypes = require('prop-types'); +const ReactNative = require('ReactNative'); +const RCTScrollViewManager = require('NativeModules').ScrollViewManager; +const ScrollView = require('ScrollView'); +const ScrollResponder = require('ScrollResponder'); +const StaticRenderer = require('StaticRenderer'); /* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error * found when Flow v0.54 was deployed. To see the error delete this comment and * run Flow. */ -var TimerMixin = require('react-timer-mixin'); -var View = require('View'); +const TimerMixin = require('react-timer-mixin'); +const View = require('View'); /* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error * found when Flow v0.54 was deployed. To see the error delete this comment and * run Flow. */ -var cloneReferencedElement = require('react-clone-referenced-element'); -var createReactClass = require('create-react-class'); -var isEmpty = require('isEmpty'); -var merge = require('merge'); +const cloneReferencedElement = require('react-clone-referenced-element'); +const createReactClass = require('create-react-class'); +const isEmpty = require('isEmpty'); +const merge = require('merge'); -var DEFAULT_PAGE_SIZE = 1; -var DEFAULT_INITIAL_ROWS = 10; -var DEFAULT_SCROLL_RENDER_AHEAD = 1000; -var DEFAULT_END_REACHED_THRESHOLD = 1000; -var DEFAULT_SCROLL_CALLBACK_THROTTLE = 50; +const DEFAULT_PAGE_SIZE = 1; +const DEFAULT_INITIAL_ROWS = 10; +const DEFAULT_SCROLL_RENDER_AHEAD = 1000; +const DEFAULT_END_REACHED_THRESHOLD = 1000; +const DEFAULT_SCROLL_CALLBACK_THROTTLE = 50; /** * DEPRECATED - use one of the new list components, such as [`FlatList`](docs/flatlist.html) @@ -95,7 +95,7 @@ var DEFAULT_SCROLL_CALLBACK_THROTTLE = 50; * rendering rows. */ -var ListView = createReactClass({ +const ListView = createReactClass({ displayName: 'ListView', _childFrames: ([]: Array), _sentEndForContentLength: (null: ?number), @@ -405,28 +405,28 @@ var ListView = createReactClass({ }, render: function() { - var bodyComponents = []; + const bodyComponents = []; - var dataSource = this.props.dataSource; - var allRowIDs = dataSource.rowIdentities; - var rowCount = 0; - var stickySectionHeaderIndices = []; + const dataSource = this.props.dataSource; + const allRowIDs = dataSource.rowIdentities; + let rowCount = 0; + const stickySectionHeaderIndices = []; const {renderSectionHeader} = this.props; - var header = this.props.renderHeader && this.props.renderHeader(); - var footer = this.props.renderFooter && this.props.renderFooter(); - var totalIndex = header ? 1 : 0; + const header = this.props.renderHeader && this.props.renderHeader(); + const footer = this.props.renderFooter && this.props.renderFooter(); + let totalIndex = header ? 1 : 0; - for (var sectionIdx = 0; sectionIdx < allRowIDs.length; sectionIdx++) { - var sectionID = dataSource.sectionIdentities[sectionIdx]; - var rowIDs = allRowIDs[sectionIdx]; + for (let sectionIdx = 0; sectionIdx < allRowIDs.length; sectionIdx++) { + const sectionID = dataSource.sectionIdentities[sectionIdx]; + const rowIDs = allRowIDs[sectionIdx]; if (rowIDs.length === 0) { if (this.props.enableEmptySections === undefined) { /* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses * an error found when Flow v0.54 was deployed. To see the error * delete this comment and run Flow. */ - var warning = require('fbjs/lib/warning'); + const warning = require('fbjs/lib/warning'); warning( false, 'In next release empty section headers will be rendered.' + @@ -434,7 +434,7 @@ var ListView = createReactClass({ ); continue; } else { - var invariant = require('fbjs/lib/invariant'); + const invariant = require('fbjs/lib/invariant'); invariant( this.props.enableEmptySections, "In next release 'enableEmptySections' flag will be deprecated, empty section headers will always be rendered." + @@ -460,13 +460,13 @@ var ListView = createReactClass({ } } - for (var rowIdx = 0; rowIdx < rowIDs.length; rowIdx++) { - var rowID = rowIDs[rowIdx]; - var comboID = sectionID + '_' + rowID; - var shouldUpdateRow = + for (let rowIdx = 0; rowIdx < rowIDs.length; rowIdx++) { + const rowID = rowIDs[rowIdx]; + const comboID = sectionID + '_' + rowID; + const shouldUpdateRow = rowCount >= this._prevRenderedRowsCount && dataSource.rowShouldUpdate(sectionIdx, rowIdx); - var row = ( + const row = ( { - var rowsToRender = Math.min( + const rowsToRender = Math.min( state.curRenderedRowsCount + props.pageSize, props.enableEmptySections ? props.dataSource.getRowAndSectionCount() @@ -666,32 +666,32 @@ var ListView = createReactClass({ this._childFrames[newFrame.index] = merge(newFrame); }); } - var isVertical = !this.props.horizontal; - var dataSource = this.props.dataSource; - var visibleMin = this.scrollProperties.offset; - var visibleMax = visibleMin + this.scrollProperties.visibleLength; - var allRowIDs = dataSource.rowIdentities; + const isVertical = !this.props.horizontal; + const dataSource = this.props.dataSource; + const visibleMin = this.scrollProperties.offset; + const visibleMax = visibleMin + this.scrollProperties.visibleLength; + const allRowIDs = dataSource.rowIdentities; - var header = this.props.renderHeader && this.props.renderHeader(); - var totalIndex = header ? 1 : 0; - var visibilityChanged = false; - var changedRows = {}; - for (var sectionIdx = 0; sectionIdx < allRowIDs.length; sectionIdx++) { - var rowIDs = allRowIDs[sectionIdx]; + const header = this.props.renderHeader && this.props.renderHeader(); + let totalIndex = header ? 1 : 0; + let visibilityChanged = false; + const changedRows = {}; + for (let sectionIdx = 0; sectionIdx < allRowIDs.length; sectionIdx++) { + const rowIDs = allRowIDs[sectionIdx]; if (rowIDs.length === 0) { continue; } - var sectionID = dataSource.sectionIdentities[sectionIdx]; + const sectionID = dataSource.sectionIdentities[sectionIdx]; if (this.props.renderSectionHeader) { totalIndex++; } - var visibleSection = this._visibleRows[sectionID]; + let visibleSection = this._visibleRows[sectionID]; if (!visibleSection) { visibleSection = {}; } - for (var rowIdx = 0; rowIdx < rowIDs.length; rowIdx++) { - var rowID = rowIDs[rowIdx]; - var frame = this._childFrames[totalIndex]; + for (let rowIdx = 0; rowIdx < rowIDs.length; rowIdx++) { + const rowID = rowIDs[rowIdx]; + const frame = this._childFrames[totalIndex]; totalIndex++; if ( this.props.renderSeparator && @@ -702,9 +702,9 @@ var ListView = createReactClass({ if (!frame) { break; } - var rowVisible = visibleSection[rowID]; - var min = isVertical ? frame.y : frame.x; - var max = min + (isVertical ? frame.height : frame.width); + const rowVisible = visibleSection[rowID]; + const min = isVertical ? frame.y : frame.x; + const max = min + (isVertical ? frame.height : frame.width); if ((!min && !max) || min === max) { break; } @@ -737,7 +737,7 @@ var ListView = createReactClass({ }, _onScroll: function(e: Object) { - var isVertical = !this.props.horizontal; + const isVertical = !this.props.horizontal; this.scrollProperties.visibleLength = e.nativeEvent.layoutMeasurement[isVertical ? 'height' : 'width']; this.scrollProperties.contentLength = diff --git a/Libraries/Lists/ListView/ListViewDataSource.js b/Libraries/Lists/ListView/ListViewDataSource.js index dda74b50c..b046a58bf 100644 --- a/Libraries/Lists/ListView/ListViewDataSource.js +++ b/Libraries/Lists/ListView/ListViewDataSource.js @@ -9,12 +9,12 @@ */ 'use strict'; -var invariant = require('fbjs/lib/invariant'); -var isEmpty = require('isEmpty'); +const invariant = require('fbjs/lib/invariant'); +const isEmpty = require('isEmpty'); /* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error * found when Flow v0.54 was deployed. To see the error delete this comment and * run Flow. */ -var warning = require('fbjs/lib/warning'); +const warning = require('fbjs/lib/warning'); function defaultGetRowData( dataBlob: any, @@ -142,7 +142,7 @@ class ListViewDataSource { dataBlob: $ReadOnlyArray | {+[key: string]: any}, rowIdentities: ?$ReadOnlyArray, ): ListViewDataSource { - var rowIds = rowIdentities ? [[...rowIdentities]] : null; + const rowIds = rowIdentities ? [[...rowIdentities]] : null; if (!this._sectionHeaderHasChanged) { this._sectionHeaderHasChanged = () => false; } @@ -184,7 +184,7 @@ class ListViewDataSource { 'row and section ids lengths must be the same', ); - var newSource = new ListViewDataSource({ + const newSource = new ListViewDataSource({ getRowData: this._getRowData, getSectionHeaderData: this._getSectionHeaderData, rowHasChanged: this._rowHasChanged, @@ -237,7 +237,7 @@ class ListViewDataSource { * Returns if the row is dirtied and needs to be rerendered */ rowShouldUpdate(sectionIndex: number, rowIndex: number): boolean { - var needsUpdate = this._dirtyRows[sectionIndex][rowIndex]; + const needsUpdate = this._dirtyRows[sectionIndex][rowIndex]; warning( needsUpdate !== undefined, 'missing dirtyBit for section, row: ' + sectionIndex + ', ' + rowIndex, @@ -249,8 +249,8 @@ class ListViewDataSource { * Gets the data required to render the row. */ getRowData(sectionIndex: number, rowIndex: number): any { - var sectionID = this.sectionIdentities[sectionIndex]; - var rowID = this.rowIdentities[sectionIndex][rowIndex]; + const sectionID = this.sectionIdentities[sectionIndex]; + const rowID = this.rowIdentities[sectionIndex][rowIndex]; warning( sectionID !== undefined && rowID !== undefined, 'rendering invalid section, row: ' + sectionIndex + ', ' + rowIndex, @@ -263,8 +263,8 @@ class ListViewDataSource { * or null of out of range indexes. */ getRowIDForFlatIndex(index: number): ?string { - var accessIndex = index; - for (var ii = 0; ii < this.sectionIdentities.length; ii++) { + let accessIndex = index; + for (let ii = 0; ii < this.sectionIdentities.length; ii++) { if (accessIndex >= this.rowIdentities[ii].length) { accessIndex -= this.rowIdentities[ii].length; } else { @@ -279,8 +279,8 @@ class ListViewDataSource { * or null for out of range indexes. */ getSectionIDForFlatIndex(index: number): ?string { - var accessIndex = index; - for (var ii = 0; ii < this.sectionIdentities.length; ii++) { + let accessIndex = index; + for (let ii = 0; ii < this.sectionIdentities.length; ii++) { if (accessIndex >= this.rowIdentities[ii].length) { accessIndex -= this.rowIdentities[ii].length; } else { @@ -294,8 +294,8 @@ class ListViewDataSource { * Returns an array containing the number of rows in each section */ getSectionLengths(): Array { - var results = []; - for (var ii = 0; ii < this.sectionIdentities.length; ii++) { + const results = []; + for (let ii = 0; ii < this.sectionIdentities.length; ii++) { results.push(this.rowIdentities[ii].length); } return results; @@ -305,7 +305,7 @@ class ListViewDataSource { * Returns if the section header is dirtied and needs to be rerendered */ sectionHeaderShouldUpdate(sectionIndex: number): boolean { - var needsUpdate = this._dirtySections[sectionIndex]; + const needsUpdate = this._dirtySections[sectionIndex]; warning( needsUpdate !== undefined, 'missing dirtyBit for section: ' + sectionIndex, @@ -320,7 +320,7 @@ class ListViewDataSource { if (!this._getSectionHeaderData) { return null; } - var sectionID = this.sectionIdentities[sectionIndex]; + const sectionID = this.sectionIdentities[sectionIndex]; warning( sectionID !== undefined, 'renderSection called on invalid section: ' + sectionIndex, @@ -353,9 +353,9 @@ class ListViewDataSource { prevRowIDs: Array>, ): void { // construct a hashmap of the existing (old) id arrays - var prevSectionsHash = keyedDictionaryFromArray(prevSectionIDs); - var prevRowsHash = {}; - for (var ii = 0; ii < prevRowIDs.length; ii++) { + const prevSectionsHash = keyedDictionaryFromArray(prevSectionIDs); + const prevRowsHash = {}; + for (let ii = 0; ii < prevRowIDs.length; ii++) { var sectionID = prevSectionIDs[ii]; warning( !prevRowsHash[sectionID], @@ -368,12 +368,12 @@ class ListViewDataSource { this._dirtySections = []; this._dirtyRows = []; - var dirty; - for (var sIndex = 0; sIndex < this.sectionIdentities.length; sIndex++) { + let dirty; + for (let sIndex = 0; sIndex < this.sectionIdentities.length; sIndex++) { var sectionID = this.sectionIdentities[sIndex]; // dirty if the sectionHeader is new or _sectionHasChanged is true dirty = !prevSectionsHash[sectionID]; - var sectionHeaderHasChanged = this._sectionHeaderHasChanged; + const sectionHeaderHasChanged = this._sectionHeaderHasChanged; if (!dirty && sectionHeaderHasChanged) { dirty = sectionHeaderHasChanged( this._getSectionHeaderData(prevDataBlob, sectionID), @@ -384,11 +384,11 @@ class ListViewDataSource { this._dirtyRows[sIndex] = []; for ( - var rIndex = 0; + let rIndex = 0; rIndex < this.rowIdentities[sIndex].length; rIndex++ ) { - var rowID = this.rowIdentities[sIndex][rIndex]; + const rowID = this.rowIdentities[sIndex][rIndex]; // dirty if the section is new, row is new or _rowHasChanged is true dirty = !prevSectionsHash[sectionID] || @@ -404,9 +404,9 @@ class ListViewDataSource { } function countRows(allRowIDs) { - var totalRows = 0; - for (var sectionIdx = 0; sectionIdx < allRowIDs.length; sectionIdx++) { - var rowIDs = allRowIDs[sectionIdx]; + let totalRows = 0; + for (let sectionIdx = 0; sectionIdx < allRowIDs.length; sectionIdx++) { + const rowIDs = allRowIDs[sectionIdx]; totalRows += rowIDs.length; } return totalRows; @@ -416,9 +416,9 @@ function keyedDictionaryFromArray(arr) { if (isEmpty(arr)) { return {}; } - var result = {}; - for (var ii = 0; ii < arr.length; ii++) { - var key = arr[ii]; + const result = {}; + for (let ii = 0; ii < arr.length; ii++) { + const key = arr[ii]; warning(!result[key], 'Value appears more than once in array: ' + key); result[key] = true; } diff --git a/Libraries/Modal/Modal.js b/Libraries/Modal/Modal.js index 52ed8c7a2..77f50cf27 100644 --- a/Libraries/Modal/Modal.js +++ b/Libraries/Modal/Modal.js @@ -36,7 +36,7 @@ import type EmitterSubscription from 'EmitterSubscription'; // on screen. There can be different ones, either nested or as siblings. // We cannot pass the onDismiss callback to native as the view will be // destroyed before the callback is fired. -var uniqueModalIdentifier = 0; +let uniqueModalIdentifier = 0; class Modal extends React.Component { static propTypes = { diff --git a/Libraries/Network/FormData.js b/Libraries/Network/FormData.js index 6028a06bf..40f351c5a 100644 --- a/Libraries/Network/FormData.js +++ b/Libraries/Network/FormData.js @@ -60,9 +60,9 @@ class FormData { getParts(): Array { return this._parts.map(([name, value]) => { - var contentDisposition = 'form-data; name="' + name + '"'; + const contentDisposition = 'form-data; name="' + name + '"'; - var headers: Headers = {'content-disposition': contentDisposition}; + const headers: Headers = {'content-disposition': contentDisposition}; // The body part is a "blob", which in React Native just means // an object with a `uri` attribute. Optionally, it can also diff --git a/Libraries/Network/XHRInterceptor.js b/Libraries/Network/XHRInterceptor.js index 22c6cf853..f3dd1e03e 100644 --- a/Libraries/Network/XHRInterceptor.js +++ b/Libraries/Network/XHRInterceptor.js @@ -12,13 +12,13 @@ const originalXHROpen = XMLHttpRequest.prototype.open; const originalXHRSend = XMLHttpRequest.prototype.send; const originalXHRSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader; -var openCallback; -var sendCallback; -var requestHeaderCallback; -var headerReceivedCallback; -var responseCallback; +let openCallback; +let sendCallback; +let requestHeaderCallback; +let headerReceivedCallback; +let responseCallback; -var isInterceptorEnabled = false; +let isInterceptorEnabled = false; /** * A network interceptor which monkey-patches XMLHttpRequest methods diff --git a/Libraries/Network/XMLHttpRequest.js b/Libraries/Network/XMLHttpRequest.js index dd43fa40c..afbfc7db6 100644 --- a/Libraries/Network/XMLHttpRequest.js +++ b/Libraries/Network/XMLHttpRequest.js @@ -421,14 +421,14 @@ class XMLHttpRequest extends EventTarget(...XHR_EVENTS) { // according to the spec, return null if no response has been received return null; } - var headers = this.responseHeaders || {}; + const headers = this.responseHeaders || {}; return Object.keys(headers).map((headerName) => { return headerName + ': ' + headers[headerName]; }).join('\r\n'); } getResponseHeader(header: string): ?string { - var value = this._lowerCaseResponseHeaders[header.toLowerCase()]; + const value = this._lowerCaseResponseHeaders[header.toLowerCase()]; return value !== undefined ? value : null; } @@ -545,7 +545,7 @@ class XMLHttpRequest extends EventTarget(...XHR_EVENTS) { setResponseHeaders(responseHeaders: ?Object): void { this.responseHeaders = responseHeaders || null; - var headers = responseHeaders || {}; + const headers = responseHeaders || {}; this._lowerCaseResponseHeaders = Object.keys(headers).reduce((lcaseHeaders, headerName) => { lcaseHeaders[headerName.toLowerCase()] = headers[headerName]; diff --git a/Libraries/PushNotificationIOS/PushNotificationIOS.js b/Libraries/PushNotificationIOS/PushNotificationIOS.js index 9f013436c..fc3db58f2 100644 --- a/Libraries/PushNotificationIOS/PushNotificationIOS.js +++ b/Libraries/PushNotificationIOS/PushNotificationIOS.js @@ -182,7 +182,7 @@ class PushNotificationIOS { type === 'notification' || type === 'register' || type === 'registrationError' || type === 'localNotification', 'PushNotificationIOS only supports `notification`, `register`, `registrationError`, and `localNotification` events' ); - var listener; + let listener; if (type === 'notification') { listener = PushNotificationEmitter.addListener( DEVICE_NOTIF_EVENT, @@ -226,7 +226,7 @@ class PushNotificationIOS { type === 'notification' || type === 'register' || type === 'registrationError' || type === 'localNotification', 'PushNotificationIOS only supports `notification`, `register`, `registrationError`, and `localNotification` events' ); - var listener = _notifHandlers.get(type); + const listener = _notifHandlers.get(type); if (!listener) { return; } @@ -251,7 +251,7 @@ class PushNotificationIOS { badge: boolean, sound: boolean }> { - var requestedPermissions = {}; + let requestedPermissions = {}; if (permissions) { requestedPermissions = { alert: !!permissions.alert, @@ -321,7 +321,7 @@ class PushNotificationIOS { // Extract data from Apple's `aps` dict as defined: // https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html Object.keys(nativeNotif).forEach((notifKey) => { - var notifVal = nativeNotif[notifKey]; + const notifVal = nativeNotif[notifKey]; if (notifKey === 'aps') { this._alert = notifVal.alert; this._sound = notifVal.sound; diff --git a/Libraries/RCTTest/SnapshotViewIOS.ios.js b/Libraries/RCTTest/SnapshotViewIOS.ios.js index 050ec5d63..0a2877a9d 100644 --- a/Libraries/RCTTest/SnapshotViewIOS.ios.js +++ b/Libraries/RCTTest/SnapshotViewIOS.ios.js @@ -8,16 +8,16 @@ */ 'use strict'; -var React = require('React'); +const React = require('React'); const PropTypes = require('prop-types'); -var StyleSheet = require('StyleSheet'); -var { TestModule } = require('NativeModules'); -var UIManager = require('UIManager'); -var View = require('View'); +const StyleSheet = require('StyleSheet'); +const { TestModule } = require('NativeModules'); +const UIManager = require('UIManager'); +const View = require('View'); const ViewPropTypes = require('ViewPropTypes'); -var requireNativeComponent = require('requireNativeComponent'); +const requireNativeComponent = require('requireNativeComponent'); class SnapshotViewIOS extends React.Component<{ onSnapshotReady?: Function, @@ -37,8 +37,8 @@ class SnapshotViewIOS extends React.Component<{ }; render() { - var testIdentifier = this.props.testIdentifier || 'test'; - var onSnapshotReady = this.props.onSnapshotReady || this.onDefaultAction; + const testIdentifier = this.props.testIdentifier || 'test'; + const onSnapshotReady = this.props.onSnapshotReady || this.onDefaultAction; return ( void; * @param {function} onError `func(error)` * @param {function} onSuccess `func(left, top, width, height, pageX, pageY)` */ -var queryLayoutByID = function( +const queryLayoutByID = function( tag: ?number, onError: OnErrorCallback, onSuccess: OnSuccessCallback, diff --git a/Libraries/Sample/Sample.android.js b/Libraries/Sample/Sample.android.js index dbb43949f..61b394841 100644 --- a/Libraries/Sample/Sample.android.js +++ b/Libraries/Sample/Sample.android.js @@ -5,9 +5,9 @@ */ 'use strict'; -var warning = require('fbjs/lib/warning'); +const warning = require('fbjs/lib/warning'); -var Sample = { +const Sample = { test: function() { warning('Not yet implemented for Android.'); } diff --git a/Libraries/Sample/Sample.ios.js b/Libraries/Sample/Sample.ios.js index ae51247cc..0e459eb90 100644 --- a/Libraries/Sample/Sample.ios.js +++ b/Libraries/Sample/Sample.ios.js @@ -3,13 +3,13 @@ */ 'use strict'; -var NativeSample = require('NativeModules').Sample; +const NativeSample = require('NativeModules').Sample; /** * High-level docs for the Sample iOS API can be written here. */ -var Sample = { +const Sample = { test: function() { NativeSample.test(); } diff --git a/Libraries/Settings/Settings.android.js b/Libraries/Settings/Settings.android.js index 220c04e8b..c87accba5 100644 --- a/Libraries/Settings/Settings.android.js +++ b/Libraries/Settings/Settings.android.js @@ -8,7 +8,7 @@ */ 'use strict'; -var Settings = { +const Settings = { get(key: string): mixed { console.warn('Settings is not yet supported on Android'); return null; diff --git a/Libraries/Settings/Settings.ios.js b/Libraries/Settings/Settings.ios.js index 46f0a8beb..d0c893ddf 100644 --- a/Libraries/Settings/Settings.ios.js +++ b/Libraries/Settings/Settings.ios.js @@ -8,14 +8,14 @@ */ 'use strict'; -var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter'); -var RCTSettingsManager = require('NativeModules').SettingsManager; +const RCTDeviceEventEmitter = require('RCTDeviceEventEmitter'); +const RCTSettingsManager = require('NativeModules').SettingsManager; -var invariant = require('fbjs/lib/invariant'); +const invariant = require('fbjs/lib/invariant'); -var subscriptions: Array<{keys: Array, callback: ?Function}> = []; +const subscriptions: Array<{keys: Array, callback: ?Function}> = []; -var Settings = { +const Settings = { _settings: RCTSettingsManager && RCTSettingsManager.settings, get(key: string): mixed { @@ -37,7 +37,7 @@ var Settings = { 'keys should be a string or array of strings' ); - var sid = subscriptions.length; + const sid = subscriptions.length; subscriptions.push({keys: keys, callback: callback}); return sid; }, @@ -50,8 +50,8 @@ var Settings = { _sendObservations(body: Object) { Object.keys(body).forEach((key) => { - var newValue = body[key]; - var didChange = this._settings[key] !== newValue; + const newValue = body[key]; + const didChange = this._settings[key] !== newValue; this._settings[key] = newValue; if (didChange) { diff --git a/Libraries/Storage/AsyncStorage.js b/Libraries/Storage/AsyncStorage.js index f953aecbc..ed5042edd 100644 --- a/Libraries/Storage/AsyncStorage.js +++ b/Libraries/Storage/AsyncStorage.js @@ -24,7 +24,7 @@ const RCTAsyncStorage = NativeModules.AsyncRocksDBStorage || * * See http://facebook.github.io/react-native/docs/asyncstorage.html */ -var AsyncStorage = { +const AsyncStorage = { _getRequests: ([]: Array), _getKeys: ([]: Array), _immediate: (null: ?number), @@ -41,8 +41,8 @@ var AsyncStorage = { return new Promise((resolve, reject) => { RCTAsyncStorage.multiGet([key], function(errors, result) { // Unpack result to get value from [[key,value]] - var value = (result && result[0] && result[0][1]) ? result[0][1] : null; - var errs = convertErrors(errors); + const value = (result && result[0] && result[0][1]) ? result[0][1] : null; + const errs = convertErrors(errors); callback && callback(errs && errs[0], value); if (errs) { reject(errs[0]); @@ -65,7 +65,7 @@ var AsyncStorage = { ): Promise { return new Promise((resolve, reject) => { RCTAsyncStorage.multiSet([[key,value]], function(errors) { - var errs = convertErrors(errors); + const errs = convertErrors(errors); callback && callback(errs && errs[0]); if (errs) { reject(errs[0]); @@ -87,7 +87,7 @@ var AsyncStorage = { ): Promise { return new Promise((resolve, reject) => { RCTAsyncStorage.multiRemove([key], function(errors) { - var errs = convertErrors(errors); + const errs = convertErrors(errors); callback && callback(errs && errs[0]); if (errs) { reject(errs[0]); @@ -113,7 +113,7 @@ var AsyncStorage = { ): Promise { return new Promise((resolve, reject) => { RCTAsyncStorage.multiMerge([[key,value]], function(errors) { - var errs = convertErrors(errors); + const errs = convertErrors(errors); callback && callback(errs && errs[0]); if (errs) { reject(errs[0]); @@ -222,7 +222,7 @@ var AsyncStorage = { }); } - var getRequest = { + const getRequest = { keys: keys, callback: callback, // do we need this? @@ -231,7 +231,7 @@ var AsyncStorage = { reject: null, }; - var promiseResult = new Promise((resolve, reject) => { + const promiseResult = new Promise((resolve, reject) => { getRequest.resolve = resolve; getRequest.reject = reject; }); @@ -259,7 +259,7 @@ var AsyncStorage = { ): Promise { return new Promise((resolve, reject) => { RCTAsyncStorage.multiSet(keyValuePairs, function(errors) { - var error = convertErrors(errors); + const error = convertErrors(errors); callback && callback(error); if (error) { reject(error); @@ -281,7 +281,7 @@ var AsyncStorage = { ): Promise { return new Promise((resolve, reject) => { RCTAsyncStorage.multiRemove(keys, function(errors) { - var error = convertErrors(errors); + const error = convertErrors(errors); callback && callback(error); if (error) { reject(error); @@ -306,7 +306,7 @@ var AsyncStorage = { ): Promise { return new Promise((resolve, reject) => { RCTAsyncStorage.multiMerge(keyValuePairs, function(errors) { - var error = convertErrors(errors); + const error = convertErrors(errors); callback && callback(error); if (error) { reject(error); @@ -335,7 +335,7 @@ function convertError(error) { if (!error) { return null; } - var out = new Error(error.message); + const out = new Error(error.message); out.key = error.key; // flow doesn't like this :( return out; } diff --git a/Libraries/StyleSheet/ColorPropType.js b/Libraries/StyleSheet/ColorPropType.js index 28bc93f45..562d3ad89 100644 --- a/Libraries/StyleSheet/ColorPropType.js +++ b/Libraries/StyleSheet/ColorPropType.js @@ -7,10 +7,10 @@ */ 'use strict'; -var normalizeColor = require('normalizeColor'); +const normalizeColor = require('normalizeColor'); -var colorPropType = function(isRequired, props, propName, componentName, location, propFullName) { - var color = props[propName]; +const colorPropType = function(isRequired, props, propName, componentName, location, propFullName) { + const color = props[propName]; if (color === undefined || color === null) { if (isRequired) { return new Error( @@ -48,7 +48,7 @@ var colorPropType = function(isRequired, props, propName, componentName, locatio } }; -var ColorPropType = colorPropType.bind(null, false /* isRequired */); +const ColorPropType = colorPropType.bind(null, false /* isRequired */); ColorPropType.isRequired = colorPropType.bind(null, true /* isRequired */); module.exports = ColorPropType; diff --git a/Libraries/StyleSheet/LayoutPropTypes.js b/Libraries/StyleSheet/LayoutPropTypes.js index 6ff1844c7..aa755aa44 100644 --- a/Libraries/StyleSheet/LayoutPropTypes.js +++ b/Libraries/StyleSheet/LayoutPropTypes.js @@ -8,7 +8,7 @@ */ 'use strict'; -var ReactPropTypes = require('prop-types'); +const ReactPropTypes = require('prop-types'); /** * React Native's layout system is based on Flexbox and is powered both @@ -23,7 +23,7 @@ var ReactPropTypes = require('prop-types'); * These properties are a subset of our styles that are consumed by the layout * algorithm and affect the positioning and sizing of views. */ -var LayoutPropTypes = { +const LayoutPropTypes = { /** `display` sets the display type of this component. * * It works similarly to `display` in CSS, but only support 'flex' and 'none'. diff --git a/Libraries/StyleSheet/PointPropType.js b/Libraries/StyleSheet/PointPropType.js index 44efc2d5f..8a93b6c54 100644 --- a/Libraries/StyleSheet/PointPropType.js +++ b/Libraries/StyleSheet/PointPropType.js @@ -8,11 +8,11 @@ */ 'use strict'; -var PropTypes = require('prop-types'); +const PropTypes = require('prop-types'); -var createStrictShapeTypeChecker = require('createStrictShapeTypeChecker'); +const createStrictShapeTypeChecker = require('createStrictShapeTypeChecker'); -var PointPropType = createStrictShapeTypeChecker({ +const PointPropType = createStrictShapeTypeChecker({ x: PropTypes.number, y: PropTypes.number, }); diff --git a/Libraries/StyleSheet/StyleSheetPropType.js b/Libraries/StyleSheet/StyleSheetPropType.js index 9fed3d207..e024c9374 100644 --- a/Libraries/StyleSheet/StyleSheetPropType.js +++ b/Libraries/StyleSheet/StyleSheetPropType.js @@ -8,15 +8,15 @@ */ 'use strict'; -var createStrictShapeTypeChecker = require('createStrictShapeTypeChecker'); -var flattenStyle = require('flattenStyle'); +const createStrictShapeTypeChecker = require('createStrictShapeTypeChecker'); +const flattenStyle = require('flattenStyle'); function StyleSheetPropType( shape: {[key: string]: ReactPropsCheckType} ): ReactPropsCheckType { - var shapePropType = createStrictShapeTypeChecker(shape); + const shapePropType = createStrictShapeTypeChecker(shape); return function(props, propName, componentName, location?, ...rest) { - var newProps = props; + let newProps = props; if (props[propName]) { // Just make a dummy prop object with only the flattened style newProps = {}; diff --git a/Libraries/StyleSheet/StyleSheetValidation.js b/Libraries/StyleSheet/StyleSheetValidation.js index ae6c843de..c7686dcb9 100644 --- a/Libraries/StyleSheet/StyleSheetValidation.js +++ b/Libraries/StyleSheet/StyleSheetValidation.js @@ -8,11 +8,11 @@ */ 'use strict'; -var ImageStylePropTypes = require('ImageStylePropTypes'); -var TextStylePropTypes = require('TextStylePropTypes'); -var ViewStylePropTypes = require('ViewStylePropTypes'); +const ImageStylePropTypes = require('ImageStylePropTypes'); +const TextStylePropTypes = require('TextStylePropTypes'); +const ViewStylePropTypes = require('ViewStylePropTypes'); -var invariant = require('fbjs/lib/invariant'); +const invariant = require('fbjs/lib/invariant'); // Hardcoded because this is a legit case but we don't want to load it from // a private API. We might likely want to unify style sheet creation with how it @@ -26,12 +26,12 @@ class StyleSheetValidation { return; } if (allStylePropTypes[prop] === undefined) { - var message1 = '"' + prop + '" is not a valid style property.'; - var message2 = '\nValid style props: ' + + const message1 = '"' + prop + '" is not a valid style property.'; + const message2 = '\nValid style props: ' + JSON.stringify(Object.keys(allStylePropTypes).sort(), null, ' '); styleError(message1, style, caller, message2); } - var error = allStylePropTypes[prop]( + const error = allStylePropTypes[prop]( style, prop, caller, @@ -48,19 +48,19 @@ class StyleSheetValidation { if (!__DEV__) { return; } - for (var prop in styles[name]) { + for (const prop in styles[name]) { StyleSheetValidation.validateStyleProp(prop, styles[name], 'StyleSheet ' + name); } } static addValidStylePropTypes(stylePropTypes) { - for (var key in stylePropTypes) { + for (const key in stylePropTypes) { allStylePropTypes[key] = stylePropTypes[key]; } } } -var styleError = function(message1, style, caller?, message2?) { +const styleError = function(message1, style, caller?, message2?) { invariant( false, message1 + '\n' + (caller || '<>') + ': ' + @@ -68,7 +68,7 @@ var styleError = function(message1, style, caller?, message2?) { ); }; -var allStylePropTypes = {}; +const allStylePropTypes = {}; StyleSheetValidation.addValidStylePropTypes(ImageStylePropTypes); StyleSheetValidation.addValidStylePropTypes(TextStylePropTypes); diff --git a/Libraries/StyleSheet/TransformPropTypes.js b/Libraries/StyleSheet/TransformPropTypes.js index 13a58fdd7..2f9037abf 100644 --- a/Libraries/StyleSheet/TransformPropTypes.js +++ b/Libraries/StyleSheet/TransformPropTypes.js @@ -8,11 +8,11 @@ */ 'use strict'; -var ReactPropTypes = require('prop-types'); +const ReactPropTypes = require('prop-types'); -var deprecatedPropType = require('deprecatedPropType'); +const deprecatedPropType = require('deprecatedPropType'); -var TransformMatrixPropType = function( +const TransformMatrixPropType = function( props : Object, propName : string, componentName : string @@ -25,7 +25,7 @@ var TransformMatrixPropType = function( } }; -var DecomposedMatrixPropType = function( +const DecomposedMatrixPropType = function( props : Object, propName : string, componentName : string @@ -38,7 +38,7 @@ var DecomposedMatrixPropType = function( } }; -var TransformPropTypes = { +const TransformPropTypes = { /** * `transform` accepts an array of transformation objects. Each object specifies * the property that will be transformed as the key, and the value to use in the diff --git a/Libraries/StyleSheet/__tests__/flattenStyle-test.js b/Libraries/StyleSheet/__tests__/flattenStyle-test.js index 76ce2822d..0db505ff2 100644 --- a/Libraries/StyleSheet/__tests__/flattenStyle-test.js +++ b/Libraries/StyleSheet/__tests__/flattenStyle-test.js @@ -83,8 +83,8 @@ describe('flattenStyle', () => { it('should not allocate an object when there is a single class', () => { const fixture = getFixture(); - var singleStyle = flattenStyle(fixture.elementA); - var singleStyleAgain = flattenStyle(fixture.elementA); + const singleStyle = flattenStyle(fixture.elementA); + const singleStyleAgain = flattenStyle(fixture.elementA); expect(singleStyle).toBe(singleStyleAgain); expect(singleStyle).toEqual({ @@ -95,8 +95,8 @@ describe('flattenStyle', () => { it('should merge single class and style properly', () => { const fixture = getFixture(); - var style = {styleA: 'overrideA', styleC: 'overrideC'}; - var arrayStyle = flattenStyle([fixture.elementA, style]); + const style = {styleA: 'overrideA', styleC: 'overrideC'}; + const arrayStyle = flattenStyle([fixture.elementA, style]); expect(arrayStyle).toEqual({ styleA: 'overrideA', @@ -107,8 +107,8 @@ describe('flattenStyle', () => { it('should merge multiple classes', () => { const fixture = getFixture(); - var AthenB = flattenStyle([fixture.elementA, fixture.elementB]); - var BthenA = flattenStyle([fixture.elementB, fixture.elementA]); + const AthenB = flattenStyle([fixture.elementA, fixture.elementB]); + const BthenA = flattenStyle([fixture.elementB, fixture.elementA]); expect(AthenB).toEqual({ styleA: 'moduleA/elementA/styleA', @@ -122,9 +122,9 @@ describe('flattenStyle', () => { it('should merge multiple classes with style', () => { const fixture = getFixture(); - var style = {styleA: 'overrideA'}; - var AthenB = flattenStyle([fixture.elementA, fixture.elementB, style]); - var BthenA = flattenStyle([fixture.elementB, fixture.elementA, style]); + const style = {styleA: 'overrideA'}; + const AthenB = flattenStyle([fixture.elementA, fixture.elementB, style]); + const BthenA = flattenStyle([fixture.elementB, fixture.elementA, style]); expect(AthenB).toEqual({ styleA: 'overrideA', @@ -138,8 +138,8 @@ describe('flattenStyle', () => { it('should flatten recursively', () => { const fixture = getFixture(); - var style = [{styleA: 'newA', styleB: 'newB'}, {styleA: 'newA2'}]; - var AthenB = flattenStyle([fixture.elementA, fixture.elementB, style]); + const style = [{styleA: 'newA', styleB: 'newB'}, {styleA: 'newA2'}]; + const AthenB = flattenStyle([fixture.elementA, fixture.elementB, style]); expect(AthenB).toEqual({ styleA: 'newA2', @@ -148,7 +148,7 @@ describe('flattenStyle', () => { }); it('should ignore invalid class names', () => { - var invalid = flattenStyle(1234, null); + const invalid = flattenStyle(1234, null); expect(invalid).toEqual(undefined); // Invalid class name 1234 skipping ... diff --git a/Libraries/StyleSheet/__tests__/normalizeColor-test.js b/Libraries/StyleSheet/__tests__/normalizeColor-test.js index d7482a9c5..7edfdb4ac 100644 --- a/Libraries/StyleSheet/__tests__/normalizeColor-test.js +++ b/Libraries/StyleSheet/__tests__/normalizeColor-test.js @@ -8,7 +8,7 @@ */ 'use strict'; -var normalizeColor = require('normalizeColor'); +const normalizeColor = require('normalizeColor'); describe('normalizeColor', function() { it('should accept only spec compliant colors', function() { diff --git a/Libraries/StyleSheet/__tests__/processColor-test.js b/Libraries/StyleSheet/__tests__/processColor-test.js index 2af0baa10..a353a52a6 100644 --- a/Libraries/StyleSheet/__tests__/processColor-test.js +++ b/Libraries/StyleSheet/__tests__/processColor-test.js @@ -20,26 +20,26 @@ describe('processColor', () => { describe('predefined color names', () => { it('should convert red', () => { - var colorFromString = processColor('red'); - var expectedInt = 0xFFFF0000; + const colorFromString = processColor('red'); + const expectedInt = 0xFFFF0000; expect(colorFromString).toEqual(platformSpecific(expectedInt)); }); it('should convert white', () => { - var colorFromString = processColor('white'); - var expectedInt = 0xFFFFFFFF; + const colorFromString = processColor('white'); + const expectedInt = 0xFFFFFFFF; expect(colorFromString).toEqual(platformSpecific(expectedInt)); }); it('should convert black', () => { - var colorFromString = processColor('black'); - var expectedInt = 0xFF000000; + const colorFromString = processColor('black'); + const expectedInt = 0xFF000000; expect(colorFromString).toEqual(platformSpecific(expectedInt)); }); it('should convert transparent', () => { - var colorFromString = processColor('transparent'); - var expectedInt = 0x00000000; + const colorFromString = processColor('transparent'); + const expectedInt = 0x00000000; expect(colorFromString).toEqual(platformSpecific(expectedInt)); }); }); @@ -47,8 +47,8 @@ describe('processColor', () => { describe('RGB strings', () => { it('should convert rgb(x, y, z)', () => { - var colorFromString = processColor('rgb(10, 20, 30)'); - var expectedInt = 0xFF0A141E; + const colorFromString = processColor('rgb(10, 20, 30)'); + const expectedInt = 0xFF0A141E; expect(colorFromString).toEqual(platformSpecific(expectedInt)); }); @@ -57,8 +57,8 @@ describe('processColor', () => { describe('RGBA strings', () => { it('should convert rgba(x, y, z, a)', () => { - var colorFromString = processColor('rgba(10, 20, 30, 0.4)'); - var expectedInt = 0x660A141E; + const colorFromString = processColor('rgba(10, 20, 30, 0.4)'); + const expectedInt = 0x660A141E; expect(colorFromString).toEqual(platformSpecific(expectedInt)); }); @@ -67,8 +67,8 @@ describe('processColor', () => { describe('HSL strings', () => { it('should convert hsl(x, y%, z%)', () => { - var colorFromString = processColor('hsl(318, 69%, 55%)'); - var expectedInt = 0xFFDB3DAC; + const colorFromString = processColor('hsl(318, 69%, 55%)'); + const expectedInt = 0xFFDB3DAC; expect(colorFromString).toEqual(platformSpecific(expectedInt)); }); @@ -77,8 +77,8 @@ describe('processColor', () => { describe('HSLA strings', () => { it('should convert hsla(x, y%, z%, a)', () => { - var colorFromString = processColor('hsla(318, 69%, 55%, 0.25)'); - var expectedInt = 0x40DB3DAC; + const colorFromString = processColor('hsla(318, 69%, 55%, 0.25)'); + const expectedInt = 0x40DB3DAC; expect(colorFromString).toEqual(platformSpecific(expectedInt)); }); @@ -87,8 +87,8 @@ describe('processColor', () => { describe('hex strings', () => { it('should convert #xxxxxx', () => { - var colorFromString = processColor('#1e83c9'); - var expectedInt = 0xFF1E83C9; + const colorFromString = processColor('#1e83c9'); + const expectedInt = 0xFF1E83C9; expect(colorFromString).toEqual(platformSpecific(expectedInt)); }); diff --git a/Libraries/StyleSheet/__tests__/setNormalizedColorAlpha-test.js b/Libraries/StyleSheet/__tests__/setNormalizedColorAlpha-test.js index 13e47aff5..5fd4a9f73 100644 --- a/Libraries/StyleSheet/__tests__/setNormalizedColorAlpha-test.js +++ b/Libraries/StyleSheet/__tests__/setNormalizedColorAlpha-test.js @@ -8,8 +8,8 @@ */ 'use strict'; -var setNormalizedColorAlpha = require('setNormalizedColorAlpha'); -var normalizeColor = require('normalizeColor'); +const setNormalizedColorAlpha = require('setNormalizedColorAlpha'); +const normalizeColor = require('normalizeColor'); describe('setNormalizedColorAlpha', function() { it('should adjust the alpha of the color passed in', function() { @@ -27,7 +27,7 @@ describe('setNormalizedColorAlpha', function() { }); it('should return the original color when alpha is unchanged', function() { - var originalColor = normalizeColor('blue'); + const originalColor = normalizeColor('blue'); expect(setNormalizedColorAlpha(originalColor, 1)).toBe(originalColor); }); }); diff --git a/Libraries/StyleSheet/flattenStyle.js b/Libraries/StyleSheet/flattenStyle.js index f62e35ea7..cb5f6ebc9 100644 --- a/Libraries/StyleSheet/flattenStyle.js +++ b/Libraries/StyleSheet/flattenStyle.js @@ -25,11 +25,11 @@ function flattenStyle( return style; } - var result = {}; - for (var i = 0, styleLength = style.length; i < styleLength; ++i) { - var computedStyle = flattenStyle(style[i]); + const result = {}; + for (let i = 0, styleLength = style.length; i < styleLength; ++i) { + const computedStyle = flattenStyle(style[i]); if (computedStyle) { - for (var key in computedStyle) { + for (const key in computedStyle) { result[key] = computedStyle[key]; } } diff --git a/Libraries/StyleSheet/processTransform.js b/Libraries/StyleSheet/processTransform.js index 3c8d30ea0..fb4ed3445 100644 --- a/Libraries/StyleSheet/processTransform.js +++ b/Libraries/StyleSheet/processTransform.js @@ -8,11 +8,11 @@ */ 'use strict'; -var MatrixMath = require('MatrixMath'); -var Platform = require('Platform'); +const MatrixMath = require('MatrixMath'); +const Platform = require('Platform'); -var invariant = require('fbjs/lib/invariant'); -var stringifySafe = require('stringifySafe'); +const invariant = require('fbjs/lib/invariant'); +const stringifySafe = require('stringifySafe'); /** * Generate a transform matrix based on the provided transforms, and use that @@ -34,11 +34,11 @@ function processTransform(transform: Array): Array | Array { - var key = Object.keys(transformation)[0]; - var value = transformation[key]; + const key = Object.keys(transformation)[0]; + const value = transformation[key]; switch (key) { case 'matrix': @@ -97,8 +97,8 @@ function _multiplyTransform( matrixMathFunction: Function, args: Array ): void { - var matrixToApply = MatrixMath.createIdentityMatrix(); - var argsWithIdentity = [matrixToApply].concat(args); + const matrixToApply = MatrixMath.createIdentityMatrix(); + const argsWithIdentity = [matrixToApply].concat(args); matrixMathFunction.apply(this, argsWithIdentity); MatrixMath.multiplyInto(result, result, matrixToApply); } @@ -108,20 +108,20 @@ function _multiplyTransform( * Note that validation on the string is done in `_validateTransform()`. */ function _convertToRadians(value: string): number { - var floatValue = parseFloat(value); + const floatValue = parseFloat(value); return value.indexOf('rad') > -1 ? floatValue : floatValue * Math.PI / 180; } function _validateTransforms(transform: Array): void { transform.forEach(transformation => { - var keys = Object.keys(transformation); + const keys = Object.keys(transformation); invariant( keys.length === 1, 'You must specify exactly one property per transform object. Passed properties: %s', stringifySafe(transformation), ); - var key = keys[0]; - var value = transformation[key]; + const key = keys[0]; + const value = transformation[key]; _validateTransform(key, value, transformation); }); } @@ -134,7 +134,7 @@ function _validateTransform(key, value, transformation) { 'replace by .' ); - var multivalueTransforms = [ + const multivalueTransforms = [ 'matrix', 'translate', ]; diff --git a/Libraries/Text/TextUpdateTest.js b/Libraries/Text/TextUpdateTest.js index 18a3ac508..b3dc0949a 100644 --- a/Libraries/Text/TextUpdateTest.js +++ b/Libraries/Text/TextUpdateTest.js @@ -8,22 +8,22 @@ */ 'use strict'; -var React = require('react'); -var createReactClass = require('create-react-class'); -var ReactNative = require('react-native'); +const React = require('react'); +const createReactClass = require('create-react-class'); +const ReactNative = require('react-native'); /* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error * found when Flow v0.54 was deployed. To see the error delete this comment and * run Flow. */ -var TimerMixin = require('react-timer-mixin'); -var { +const TimerMixin = require('react-timer-mixin'); +const { NativeModules, StyleSheet, Text, } = ReactNative; -var TestManager = NativeModules.TestManager || NativeModules.SnapshotTestManager; +const TestManager = NativeModules.TestManager || NativeModules.SnapshotTestManager; -var TextUpdateTest = createReactClass({ +const TextUpdateTest = createReactClass({ displayName: 'TextUpdateTest', mixins: [TimerMixin], getInitialState: function() { @@ -48,7 +48,7 @@ var TextUpdateTest = createReactClass({ }, }); -var styles = StyleSheet.create({ +const styles = StyleSheet.create({ container: { margin: 10, marginTop: 100, diff --git a/Libraries/Utilities/BackAndroid.js b/Libraries/Utilities/BackAndroid.js index 51a68a767..57e2d8d77 100644 --- a/Libraries/Utilities/BackAndroid.js +++ b/Libraries/Utilities/BackAndroid.js @@ -11,14 +11,14 @@ 'use strict'; -var BackHandler = require('BackHandler'); +const BackHandler = require('BackHandler'); -var warning = require('fbjs/lib/warning'); +const warning = require('fbjs/lib/warning'); /** * Deprecated. Use BackHandler instead. */ -var BackAndroid = { +const BackAndroid = { exitApp: function() { warning(false, 'BackAndroid is deprecated. Please use BackHandler instead.'); diff --git a/Libraries/Utilities/BackHandler.android.js b/Libraries/Utilities/BackHandler.android.js index b2e3a74bc..0db35d872 100644 --- a/Libraries/Utilities/BackHandler.android.js +++ b/Libraries/Utilities/BackHandler.android.js @@ -8,22 +8,22 @@ 'use strict'; -var DeviceEventManager = require('NativeModules').DeviceEventManager; -var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter'); +const DeviceEventManager = require('NativeModules').DeviceEventManager; +const RCTDeviceEventEmitter = require('RCTDeviceEventEmitter'); -var DEVICE_BACK_EVENT = 'hardwareBackPress'; +const DEVICE_BACK_EVENT = 'hardwareBackPress'; type BackPressEventName = $Enum<{ backPress: string, }>; -var _backPressSubscriptions = new Set(); +const _backPressSubscriptions = new Set(); RCTDeviceEventEmitter.addListener(DEVICE_BACK_EVENT, function() { - var invokeDefault = true; - var subscriptions = Array.from(_backPressSubscriptions.values()).reverse(); + let invokeDefault = true; + const subscriptions = Array.from(_backPressSubscriptions.values()).reverse(); - for (var i = 0; i < subscriptions.length; ++i) { + for (let i = 0; i < subscriptions.length; ++i) { if (subscriptions[i]()) { invokeDefault = false; break; @@ -65,7 +65,7 @@ RCTDeviceEventEmitter.addListener(DEVICE_BACK_EVENT, function() { * }); * ``` */ -var BackHandler = { +const BackHandler = { exitApp: function() { DeviceEventManager.invokeDefaultBackPressHandler(); diff --git a/Libraries/Utilities/BackHandler.ios.js b/Libraries/Utilities/BackHandler.ios.js index 0c0d7d437..4112d6197 100644 --- a/Libraries/Utilities/BackHandler.ios.js +++ b/Libraries/Utilities/BackHandler.ios.js @@ -54,14 +54,14 @@ let BackHandler; if (Platform.isTVOS) { const _tvEventHandler = new TVEventHandler(); - var _backPressSubscriptions = new Set(); + const _backPressSubscriptions = new Set(); _tvEventHandler.enable(this, function(cmp, evt) { if (evt && evt.eventType === 'menu') { - var invokeDefault = true; - var subscriptions = Array.from(_backPressSubscriptions.values()).reverse(); + let invokeDefault = true; + const subscriptions = Array.from(_backPressSubscriptions.values()).reverse(); - for (var i = 0; i < subscriptions.length; ++i) { + for (let i = 0; i < subscriptions.length; ++i) { if (subscriptions[i]()) { invokeDefault = false; break; diff --git a/Libraries/Utilities/Dimensions.js b/Libraries/Utilities/Dimensions.js index f27ecc097..76bde0243 100644 --- a/Libraries/Utilities/Dimensions.js +++ b/Libraries/Utilities/Dimensions.js @@ -8,15 +8,15 @@ */ 'use strict'; -var EventEmitter = require('EventEmitter'); -var Platform = require('Platform'); -var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter'); +const EventEmitter = require('EventEmitter'); +const Platform = require('Platform'); +const RCTDeviceEventEmitter = require('RCTDeviceEventEmitter'); -var invariant = require('fbjs/lib/invariant'); +const invariant = require('fbjs/lib/invariant'); -var eventEmitter = new EventEmitter(); -var dimensionsInitialized = false; -var dimensions = {}; +const eventEmitter = new EventEmitter(); +let dimensionsInitialized = false; +const dimensions = {}; class Dimensions { /** * This should only be called from native code by sending the diff --git a/Libraries/Utilities/HMRLoadingView.android.js b/Libraries/Utilities/HMRLoadingView.android.js index f4c0c5c73..61bc75c7e 100644 --- a/Libraries/Utilities/HMRLoadingView.android.js +++ b/Libraries/Utilities/HMRLoadingView.android.js @@ -9,7 +9,7 @@ 'use strict'; -var ToastAndroid = require('ToastAndroid'); +const ToastAndroid = require('ToastAndroid'); const TOAST_SHORT_DELAY = 2000; diff --git a/Libraries/Utilities/HeapCapture.js b/Libraries/Utilities/HeapCapture.js index 519a2e943..91df130ed 100644 --- a/Libraries/Utilities/HeapCapture.js +++ b/Libraries/Utilities/HeapCapture.js @@ -8,9 +8,9 @@ */ 'use strict'; -var HeapCapture = { +const HeapCapture = { captureHeap: function (path: string) { - var error = null; + let error = null; try { global.nativeCaptureHeap(path); console.log('HeapCapture.captureHeap succeeded: ' + path); diff --git a/Libraries/Utilities/MatrixMath.js b/Libraries/Utilities/MatrixMath.js index be329c2e6..40f934cc8 100755 --- a/Libraries/Utilities/MatrixMath.js +++ b/Libraries/Utilities/MatrixMath.js @@ -9,13 +9,13 @@ /* eslint-disable space-infix-ops */ 'use strict'; -var invariant = require('fbjs/lib/invariant'); +const invariant = require('fbjs/lib/invariant'); /** * Memory conservative (mutative) matrix math utilities. Uses "command" * matrices, which are reusable. */ -var MatrixMath = { +const MatrixMath = { createIdentityMatrix: function() { return [ 1,0,0,0, @@ -35,13 +35,13 @@ var MatrixMath = { }, createOrthographic: function(left, right, bottom, top, near, far) { - var a = 2 / (right - left); - var b = 2 / (top - bottom); - var c = -2 / (far - near); + const a = 2 / (right - left); + const b = 2 / (top - bottom); + const c = -2 / (far - near); - var tx = -(right + left) / (right - left); - var ty = -(top + bottom) / (top - bottom); - var tz = -(far + near) / (far - near); + const tx = -(right + left) / (right - left); + const ty = -(top + bottom) / (top - bottom); + const tz = -(far + near) / (far - near); return [ a, 0, 0, 0, @@ -52,15 +52,15 @@ var MatrixMath = { }, createFrustum: function(left, right, bottom, top, near, far) { - var r_width = 1 / (right - left); - var r_height = 1 / (top - bottom); - var r_depth = 1 / (near - far); - var x = 2 * (near * r_width); - var y = 2 * (near * r_height); - var A = (right + left) * r_width; - var B = (top + bottom) * r_height; - var C = (far + near) * r_depth; - var D = 2 * (far * near * r_depth); + const r_width = 1 / (right - left); + const r_height = 1 / (top - bottom); + const r_depth = 1 / (near - far); + const x = 2 * (near * r_width); + const y = 2 * (near * r_height); + const A = (right + left) * r_width; + const B = (top + bottom) * r_height; + const C = (far + near) * r_depth; + const D = 2 * (far * near * r_depth); return [ x, 0, 0, 0, 0, y, 0, 0, @@ -76,10 +76,10 @@ var MatrixMath = { * @param fovInRadians - field of view in randians */ createPerspective: function(fovInRadians, aspect, near, far) { - var h = 1 / Math.tan(fovInRadians / 2); - var r_depth = 1 / (near - far); - var C = (far + near) * r_depth; - var D = 2 * (far * near * r_depth); + const h = 1 / Math.tan(fovInRadians / 2); + const r_depth = 1 / (near - far); + const C = (far + near) * r_depth; + const D = 2 * (far * near * r_depth); return [ h/aspect, 0, 0, 0, 0, h, 0, 0, @@ -89,7 +89,7 @@ var MatrixMath = { }, createTranslate2d: function(x, y) { - var mat = MatrixMath.createIdentityMatrix(); + const mat = MatrixMath.createIdentityMatrix(); MatrixMath.reuseTranslate2dCommand(mat, x, y); return mat; }, @@ -106,7 +106,7 @@ var MatrixMath = { }, createScale: function(factor) { - var mat = MatrixMath.createIdentityMatrix(); + const mat = MatrixMath.createIdentityMatrix(); MatrixMath.reuseScaleCommand(mat, factor); return mat; }, @@ -161,7 +161,7 @@ var MatrixMath = { }, createRotateZ: function(radians) { - var mat = MatrixMath.createIdentityMatrix(); + const mat = MatrixMath.createIdentityMatrix(); MatrixMath.reuseRotateZCommand(mat, radians); return mat; }, @@ -175,12 +175,9 @@ var MatrixMath = { }, multiplyInto: function(out, a, b) { - var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], - a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], - a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], - a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15]; + const a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15]; - var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3]; + let b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3]; out[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30; out[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31; out[2] = b0*a02 + b1*a12 + b2*a22 + b3*a32; @@ -206,7 +203,7 @@ var MatrixMath = { }, determinant(matrix: Array): number { - var [ + const [ m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, @@ -236,11 +233,11 @@ var MatrixMath = { * http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm */ inverse(matrix: Array): Array { - var det = MatrixMath.determinant(matrix); + const det = MatrixMath.determinant(matrix); if (!det) { return matrix; } - var [ + const [ m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, @@ -285,7 +282,7 @@ var MatrixMath = { v: Array, m: Array ): Array { - var [vx, vy, vz, vw] = v; + const [vx, vy, vz, vw] = v; return [ vx * m[0] + vy * m[4] + vz * m[8] + vw * m[12], vx * m[1] + vy * m[5] + vz * m[9] + vw * m[13], @@ -308,7 +305,7 @@ var MatrixMath = { vector: Array, v3Length: number ): Array { - var im = 1 / (v3Length || MatrixMath.v3Length(vector)); + const im = 1 / (v3Length || MatrixMath.v3Length(vector)); return [ vector[0] * im, vector[1] * im, @@ -372,14 +369,14 @@ var MatrixMath = { * roll === bank === x-axis */ quaternionToDegreesXYZ(q: Array, matrix, row): Array { - var [qx, qy, qz, qw] = q; - var qw2 = qw * qw; - var qx2 = qx * qx; - var qy2 = qy * qy; - var qz2 = qz * qz; - var test = qx * qy + qz * qw; - var unit = qw2 + qx2 + qy2 + qz2; - var conv = 180 / Math.PI; + const [qx, qy, qz, qw] = q; + const qw2 = qw * qw; + const qx2 = qx * qx; + const qy2 = qy * qy; + const qz2 = qz * qz; + const test = qx * qy + qz * qw; + const unit = qw2 + qx2 + qy2 + qz2; + const conv = 180 / Math.PI; if (test > 0.49999 * unit) { return [0, 2 * Math.atan2(qx, qw) * conv, 90]; @@ -406,7 +403,7 @@ var MatrixMath = { * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round */ roundTo3Places(n: number): number { - var arr = n.toString().split('e'); + const arr = n.toString().split('e'); return Math.round(arr[0] + 'e' + (arr[1] ? (+arr[1] - 3) : 3)) * 0.001; }, @@ -431,22 +428,22 @@ var MatrixMath = { // output values var perspective = []; - var quaternion = []; - var scale = []; - var skew = []; - var translation = []; + const quaternion = []; + const scale = []; + const skew = []; + const translation = []; // create normalized, 2d array matrix // and normalized 1d array perspectiveMatrix with redefined 4th column if (!transformMatrix[15]) { return; } - var matrix = []; - var perspectiveMatrix = []; + const matrix = []; + const perspectiveMatrix = []; for (var i = 0; i < 4; i++) { matrix.push([]); - for (var j = 0; j < 4; j++) { - var value = transformMatrix[(i * 4) + j] / transformMatrix[15]; + for (let j = 0; j < 4; j++) { + const value = transformMatrix[(i * 4) + j] / transformMatrix[15]; matrix[i].push(value); perspectiveMatrix.push(j === 3 ? 0 : value); } @@ -462,7 +459,7 @@ var MatrixMath = { if (matrix[0][3] !== 0 || matrix[1][3] !== 0 || matrix[2][3] !== 0) { // rightHandSide is the right hand side of the equation. // rightHandSide is a vector, or point in 3d space relative to the origin. - var rightHandSide = [ + const rightHandSide = [ matrix[0][3], matrix[1][3], matrix[2][3], @@ -471,10 +468,10 @@ var MatrixMath = { // Solve the equation by inverting perspectiveMatrix and multiplying // rightHandSide by the inverse. - var inversePerspectiveMatrix = MatrixMath.inverse( + const inversePerspectiveMatrix = MatrixMath.inverse( perspectiveMatrix ); - var transposedInversePerspectiveMatrix = MatrixMath.transpose( + const transposedInversePerspectiveMatrix = MatrixMath.transpose( inversePerspectiveMatrix ); var perspective = MatrixMath.multiplyVectorByMatrix( @@ -494,7 +491,7 @@ var MatrixMath = { // Now get scale and shear. // 'row' is a 3 element array of 3 component vectors - var row = []; + const row = []; for (i = 0; i < 3; i++) { row[i] = [ matrix[i][0], @@ -535,7 +532,7 @@ var MatrixMath = { // At this point, the matrix (in rows) is orthonormal. // Check for a coordinate system flip. If the determinant // is -1, then negate the matrix and the scaling factors. - var pdum3 = MatrixMath.v3Cross(row[1], row[2]); + const pdum3 = MatrixMath.v3Cross(row[1], row[2]); if (MatrixMath.v3Dot(row[0], pdum3) < 0) { for (i = 0; i < 3; i++) { scale[i] *= -1; @@ -566,7 +563,7 @@ var MatrixMath = { } // correct for occasional, weird Euler synonyms for 2d rotation - var rotationDegrees; + let rotationDegrees; if ( quaternion[0] < 0.001 && quaternion[0] >= 0 && quaternion[1] < 0.001 && quaternion[1] >= 0 diff --git a/Libraries/Utilities/PixelRatio.js b/Libraries/Utilities/PixelRatio.js index 5f52bdc0f..58b2b0224 100644 --- a/Libraries/Utilities/PixelRatio.js +++ b/Libraries/Utilities/PixelRatio.js @@ -8,7 +8,7 @@ */ 'use strict'; -var Dimensions = require('Dimensions'); +const Dimensions = require('Dimensions'); /** * PixelRatio class gives access to the device pixel density. @@ -108,7 +108,7 @@ class PixelRatio { * exactly (8.33 * 3) = 25 pixels. */ static roundToNearestPixel(layoutSize: number): number { - var ratio = PixelRatio.get(); + const ratio = PixelRatio.get(); return Math.round(layoutSize * ratio) / ratio; } diff --git a/Libraries/Utilities/__tests__/MatrixMath-test.js b/Libraries/Utilities/__tests__/MatrixMath-test.js index 2eb14cb5b..f8491cec0 100644 --- a/Libraries/Utilities/__tests__/MatrixMath-test.js +++ b/Libraries/Utilities/__tests__/MatrixMath-test.js @@ -8,7 +8,7 @@ */ 'use strict'; -var MatrixMath = require('MatrixMath'); +const MatrixMath = require('MatrixMath'); function degreesToRadians(degrees) { return degrees * Math.PI / 180; @@ -26,7 +26,7 @@ describe('MatrixMath', () => { ]).rotationDegrees).toEqual([0, 0, 0]); [30, 45, 60, 75, 90, 100, 115, 120, 133, 167].forEach(angle => { - var mat = MatrixMath.createRotateZ(degreesToRadians(angle)); + let mat = MatrixMath.createRotateZ(degreesToRadians(angle)); expect(convertZeroes(MatrixMath.decomposeMatrix(mat).rotationDegrees)) .toEqual([0, 0, angle]); @@ -80,7 +80,7 @@ describe('MatrixMath', () => { }); it('decomposes a 4x4 matrix to produce accurate Y-axis angles', () => { - var mat; + let mat; [30, 45, 60, 75, 90, 100, 110, 120, 133, 167].forEach(angle => { mat = MatrixMath.createIdentityMatrix(); MatrixMath.reuseRotateYCommand(mat, degreesToRadians(angle)); @@ -112,7 +112,7 @@ describe('MatrixMath', () => { }); it('decomposes a 4x4 matrix to produce accurate X-axis angles', () => { - var mat; + let mat; [30, 45, 60, 75, 90, 100, 110, 120, 133, 167].forEach(angle => { mat = MatrixMath.createIdentityMatrix(); MatrixMath.reuseRotateXCommand(mat, degreesToRadians(angle)); diff --git a/Libraries/Utilities/__tests__/Platform-test.js b/Libraries/Utilities/__tests__/Platform-test.js index 1fdfaaa1a..72dafb432 100644 --- a/Libraries/Utilities/__tests__/Platform-test.js +++ b/Libraries/Utilities/__tests__/Platform-test.js @@ -8,8 +8,8 @@ */ 'use strict'; -var PlatformIOS = require('../Platform.ios'); -var PlatformAndroid = require('../Platform.android'); +const PlatformIOS = require('../Platform.ios'); +const PlatformAndroid = require('../Platform.android'); describe('Platform', () => { diff --git a/Libraries/Utilities/__tests__/buildStyleInterpolator-test.js b/Libraries/Utilities/__tests__/buildStyleInterpolator-test.js index ccb5f7edf..78440b640 100644 --- a/Libraries/Utilities/__tests__/buildStyleInterpolator-test.js +++ b/Libraries/Utilities/__tests__/buildStyleInterpolator-test.js @@ -8,11 +8,11 @@ */ 'use strict'; -var buildStyleInterpolator = require('buildStyleInterpolator'); +const buildStyleInterpolator = require('buildStyleInterpolator'); -var validateEmpty = function(interpolator, value, validator) { - var emptyObject = {}; - var changed = interpolator(emptyObject, value); +const validateEmpty = function(interpolator, value, validator) { + const emptyObject = {}; + let changed = interpolator(emptyObject, value); validator(emptyObject); expect(changed).toBe(true); changed = interpolator(emptyObject, value); @@ -20,7 +20,7 @@ var validateEmpty = function(interpolator, value, validator) { }; describe('buildStyleInterpolator', function() { it('should linearly interpolate without extrapolating', function() { - var testAnim = { + const testAnim = { opacity: { from: 100, to: 200, @@ -42,7 +42,7 @@ describe('buildStyleInterpolator', function() { value: 23.5, }, }; - var interpolator = buildStyleInterpolator(testAnim); + const interpolator = buildStyleInterpolator(testAnim); validateEmpty(interpolator, 0, function(res) { expect(res).toEqual({ opacity: 100, @@ -80,7 +80,7 @@ describe('buildStyleInterpolator', function() { }); }); it('should linearly interpolate with extrapolating', function() { - var testAnim = { + const testAnim = { opacity: { from: 100, to: 200, @@ -104,7 +104,7 @@ describe('buildStyleInterpolator', function() { value: 23.5, }, }; - var interpolator = buildStyleInterpolator(testAnim); + const interpolator = buildStyleInterpolator(testAnim); validateEmpty(interpolator, 0, function(res) { expect(res).toEqual({ opacity: 100, @@ -142,7 +142,7 @@ describe('buildStyleInterpolator', function() { }); }); it('should round accordingly', function() { - var testAnim = { + const testAnim = { opacity: { from: 0, to: 1, @@ -153,7 +153,7 @@ describe('buildStyleInterpolator', function() { extrapolate: true, }, }; - var interpolator = buildStyleInterpolator(testAnim); + const interpolator = buildStyleInterpolator(testAnim); validateEmpty(interpolator, 0, function(res) { expect(res).toEqual({ opacity: 0, @@ -186,7 +186,7 @@ describe('buildStyleInterpolator', function() { }); }); it('should detect chnages correctly', function() { - var testAnim = { + const testAnim = { opacity: { from: 0, to: 1, @@ -197,9 +197,9 @@ describe('buildStyleInterpolator', function() { extrapolate: false, }, }; - var interpolator = buildStyleInterpolator(testAnim); - var obj = {}; - var res = interpolator(obj, 0); + const interpolator = buildStyleInterpolator(testAnim); + const obj = {}; + let res = interpolator(obj, 0); expect(obj).toEqual({ opacity: 0, }); @@ -227,14 +227,14 @@ describe('buildStyleInterpolator', function() { expect(res).toBe(false); }); it('should handle identity', function() { - var testAnim = { + const testAnim = { opacity: { type: 'identity', }, }; - var interpolator = buildStyleInterpolator(testAnim); - var obj = {}; - var res = interpolator(obj, 0.5); + const interpolator = buildStyleInterpolator(testAnim); + const obj = {}; + let res = interpolator(obj, 0.5); expect(obj).toEqual({ opacity: 0.5, }); @@ -248,7 +248,7 @@ describe('buildStyleInterpolator', function() { expect(res).toBe(false); }); it('should translate', function() { - var testAnim = { + const testAnim = { transformTranslate: { from: {x: 1, y: 10, z: 100}, to: {x: 5, y: 50, z: 500}, @@ -257,9 +257,9 @@ describe('buildStyleInterpolator', function() { type: 'linear', }, }; - var interpolator = buildStyleInterpolator(testAnim); - var obj = {}; - var res = interpolator(obj, 1); + const interpolator = buildStyleInterpolator(testAnim); + const obj = {}; + const res = interpolator(obj, 1); expect(obj).toEqual({ transform: [{matrix: [1, 0, 0, 0, 0, 1, 0, 0, @@ -269,7 +269,7 @@ describe('buildStyleInterpolator', function() { expect(res).toBe(true); }); it('should scale', function() { - var testAnim = { + const testAnim = { transformScale: { from: {x: 1, y: 10, z: 100}, to: {x: 5, y: 50, z: 500}, @@ -278,9 +278,9 @@ describe('buildStyleInterpolator', function() { type: 'linear', }, }; - var interpolator = buildStyleInterpolator(testAnim); - var obj = {}; - var res = interpolator(obj, 1); + const interpolator = buildStyleInterpolator(testAnim); + const obj = {}; + const res = interpolator(obj, 1); expect(obj).toEqual({ transform: [{matrix: [2, 0, 0, 0, 0, 20, 0, 0, @@ -290,7 +290,7 @@ describe('buildStyleInterpolator', function() { expect(res).toBe(true); }); it('should combine scale and translate', function() { - var testAnim = { + const testAnim = { transformScale: { from: {x: 1, y: 10, z: 100}, to: {x: 5, y: 50, z: 500}, @@ -306,9 +306,9 @@ describe('buildStyleInterpolator', function() { type: 'linear', }, }; - var interpolator = buildStyleInterpolator(testAnim); - var obj = {}; - var res = interpolator(obj, 1); + const interpolator = buildStyleInterpolator(testAnim); + const obj = {}; + const res = interpolator(obj, 1); expect(obj).toEqual({ transform: [{matrix: [2, 0, 0, 0, 0, 20, 0, 0, @@ -318,7 +318,7 @@ describe('buildStyleInterpolator', function() { expect(res).toBe(true); }); it('should step', function() { - var testAnim = { + const testAnim = { opacity: { threshold: 13, from: 10, @@ -326,9 +326,9 @@ describe('buildStyleInterpolator', function() { type: 'step', }, }; - var interpolator = buildStyleInterpolator(testAnim); - var obj = {}; - var res = interpolator(obj, 0); + const interpolator = buildStyleInterpolator(testAnim); + const obj = {}; + let res = interpolator(obj, 0); expect(obj).toEqual({ opacity: 10, }); diff --git a/Libraries/Utilities/__tests__/deepFreezeAndThrowOnMutationInDev-test.js b/Libraries/Utilities/__tests__/deepFreezeAndThrowOnMutationInDev-test.js index cc307eeda..f00b974d9 100644 --- a/Libraries/Utilities/__tests__/deepFreezeAndThrowOnMutationInDev-test.js +++ b/Libraries/Utilities/__tests__/deepFreezeAndThrowOnMutationInDev-test.js @@ -6,7 +6,7 @@ * * @emails oncall+react_native */ -var deepFreezeAndThrowOnMutationInDev = require('deepFreezeAndThrowOnMutationInDev'); +const deepFreezeAndThrowOnMutationInDev = require('deepFreezeAndThrowOnMutationInDev'); describe('deepFreezeAndThrowOnMutationInDev', function() { @@ -28,7 +28,7 @@ describe('deepFreezeAndThrowOnMutationInDev', function() { it('should throw on mutation in dev with strict', () => { 'use strict'; __DEV__ = true; - var o = {key: 'oldValue'}; + const o = {key: 'oldValue'}; deepFreezeAndThrowOnMutationInDev(o); expect(() => { o.key = 'newValue'; }).toThrowError( 'You attempted to set the key `key` with the value `"newValue"` ' + @@ -39,7 +39,7 @@ describe('deepFreezeAndThrowOnMutationInDev', function() { it('should throw on mutation in dev without strict', () => { __DEV__ = true; - var o = {key: 'oldValue'}; + const o = {key: 'oldValue'}; deepFreezeAndThrowOnMutationInDev(o); expect(() => { o.key = 'newValue'; }).toThrowError( 'You attempted to set the key `key` with the value `"newValue"` ' + @@ -51,7 +51,7 @@ describe('deepFreezeAndThrowOnMutationInDev', function() { it('should throw on nested mutation in dev with strict', () => { 'use strict'; __DEV__ = true; - var o = {key1: {key2: {key3: 'oldValue'}}}; + const o = {key1: {key2: {key3: 'oldValue'}}}; deepFreezeAndThrowOnMutationInDev(o); expect(() => { o.key1.key2.key3 = 'newValue'; }).toThrowError( 'You attempted to set the key `key3` with the value `"newValue"` ' + @@ -62,7 +62,7 @@ describe('deepFreezeAndThrowOnMutationInDev', function() { it('should throw on nested mutation in dev without strict', () => { __DEV__ = true; - var o = {key1: {key2: {key3: 'oldValue'}}}; + const o = {key1: {key2: {key3: 'oldValue'}}}; deepFreezeAndThrowOnMutationInDev(o); expect(() => { o.key1.key2.key3 = 'newValue'; }).toThrowError( 'You attempted to set the key `key3` with the value `"newValue"` ' + @@ -74,7 +74,7 @@ describe('deepFreezeAndThrowOnMutationInDev', function() { it('should throw on insertion in dev with strict', () => { 'use strict'; __DEV__ = true; - var o = {oldKey: 'value'}; + const o = {oldKey: 'value'}; deepFreezeAndThrowOnMutationInDev(o); expect(() => { o.newKey = 'value'; }) .toThrowError( @@ -85,7 +85,7 @@ describe('deepFreezeAndThrowOnMutationInDev', function() { it('should not throw on insertion in dev without strict', () => { __DEV__ = true; - var o = {oldKey: 'value'}; + const o = {oldKey: 'value'}; deepFreezeAndThrowOnMutationInDev(o); expect(() => { o.newKey = 'value'; }).not.toThrow(); expect(o.newKey).toBe(undefined); @@ -94,7 +94,7 @@ describe('deepFreezeAndThrowOnMutationInDev', function() { it('should mutate and not throw on mutation in prod', () => { 'use strict'; __DEV__ = false; - var o = {key: 'oldValue'}; + const o = {key: 'oldValue'}; deepFreezeAndThrowOnMutationInDev(o); expect(() => { o.key = 'newValue'; }).not.toThrow(); expect(o.key).toBe('newValue'); @@ -104,7 +104,7 @@ describe('deepFreezeAndThrowOnMutationInDev', function() { it('should not deep freeze already frozen objects', () => { 'use strict'; __DEV__ = true; - var o = {key1: {key2: 'oldValue'}}; + const o = {key1: {key2: 'oldValue'}}; Object.freeze(o); deepFreezeAndThrowOnMutationInDev(o); expect(() => { o.key1.key2 = 'newValue'; }).not.toThrow(); @@ -113,7 +113,7 @@ describe('deepFreezeAndThrowOnMutationInDev', function() { it("shouldn't recurse infinitely", () => { __DEV__ = true; - var o = {}; + const o = {}; o.circular = o; deepFreezeAndThrowOnMutationInDev(o); }); diff --git a/Libraries/Utilities/__tests__/groupByEveryN-test.js b/Libraries/Utilities/__tests__/groupByEveryN-test.js index 5fe348335..56baa9b0a 100644 --- a/Libraries/Utilities/__tests__/groupByEveryN-test.js +++ b/Libraries/Utilities/__tests__/groupByEveryN-test.js @@ -9,7 +9,7 @@ 'use strict'; describe('groupByEveryN', () => { - var groupByEveryN = require('groupByEveryN'); + const groupByEveryN = require('groupByEveryN'); it('should group by with different n', () => { expect(groupByEveryN([1, 2, 3, 4, 5, 6, 7, 8, 9], 1)) diff --git a/Libraries/Utilities/__tests__/truncate-test.js b/Libraries/Utilities/__tests__/truncate-test.js index 9c38d1e1e..47b2a3ae9 100644 --- a/Libraries/Utilities/__tests__/truncate-test.js +++ b/Libraries/Utilities/__tests__/truncate-test.js @@ -10,7 +10,7 @@ describe('truncate', () => { - var truncate = require('truncate'); + const truncate = require('truncate'); it('should truncate', () => { expect(truncate('Hello, world.', 5)) diff --git a/Libraries/Utilities/buildStyleInterpolator.js b/Libraries/Utilities/buildStyleInterpolator.js index a22526e45..2ffed265f 100644 --- a/Libraries/Utilities/buildStyleInterpolator.js +++ b/Libraries/Utilities/buildStyleInterpolator.js @@ -8,18 +8,18 @@ 'use strict'; -var keyOf = require('fbjs/lib/keyOf'); +const keyOf = require('fbjs/lib/keyOf'); -var X_DIM = keyOf({x: null}); -var Y_DIM = keyOf({y: null}); -var Z_DIM = keyOf({z: null}); +const X_DIM = keyOf({x: null}); +const Y_DIM = keyOf({y: null}); +const Z_DIM = keyOf({z: null}); -var InitialOperationField = { +const InitialOperationField = { transformTranslate: [0, 0, 0], transformScale: [1, 1, 1], }; -var InterpolateMatrix = { +const InterpolateMatrix = { transformScale: function(mat, x, y, z) { mat[0] = mat[0] * x; mat[1] = mat[1] * x; @@ -42,27 +42,27 @@ var InterpolateMatrix = { } }; -var computeNextValLinear = function(anim, from, to, value) { - var hasRoundRatio = 'round' in anim; - var roundRatio = anim.round; - var ratio = (value - anim.min) / (anim.max - anim.min); +const computeNextValLinear = function(anim, from, to, value) { + const hasRoundRatio = 'round' in anim; + const roundRatio = anim.round; + let ratio = (value - anim.min) / (anim.max - anim.min); if (!anim.extrapolate) { ratio = ratio > 1 ? 1 : (ratio < 0 ? 0 : ratio); } - var nextVal = from * (1 - ratio) + to * ratio; + let nextVal = from * (1 - ratio) + to * ratio; if (hasRoundRatio) { nextVal = Math.round(roundRatio * nextVal) / roundRatio; } return nextVal; }; -var computeNextValLinearScalar = function(anim, value) { +const computeNextValLinearScalar = function(anim, value) { return computeNextValLinear(anim, anim.from, anim.to, value); }; -var setNextValAndDetectChange = function(result, name, nextVal, didChange) { +const setNextValAndDetectChange = function(result, name, nextVal, didChange) { if (!didChange) { - var prevVal = result[name]; + const prevVal = result[name]; result[name] = nextVal; didChange = didChange || (nextVal !== prevVal); } else { @@ -71,7 +71,7 @@ var setNextValAndDetectChange = function(result, name, nextVal, didChange) { return didChange; }; -var initIdentity = function(mat) { +const initIdentity = function(mat) { mat[0] = 1; mat[1] = 0; mat[2] = 0; @@ -90,7 +90,7 @@ var initIdentity = function(mat) { mat[15] = 1; }; -var computeNextMatrixOperationField = function(anim, name, dim, index, value) { +const computeNextMatrixOperationField = function(anim, name, dim, index, value) { if (anim.from[dim] !== undefined && anim.to[dim] !== undefined) { return computeNextValLinear(anim, anim.from[dim], anim.to[dim], value); } else { @@ -98,33 +98,33 @@ var computeNextMatrixOperationField = function(anim, name, dim, index, value) { } }; -var computeTransform = function(anim, name, value, result, +const computeTransform = function(anim, name, value, result, didChange, didMatrix) { - var transform = result.transform !== undefined ? + const transform = result.transform !== undefined ? result.transform : (result.transform = [{ matrix: [] }]); - var mat = transform[0].matrix; - var m0 = mat[0]; - var m1 = mat[1]; - var m2 = mat[2]; - var m3 = mat[3]; - var m4 = mat[4]; - var m5 = mat[5]; - var m6 = mat[6]; - var m7 = mat[7]; - var m8 = mat[8]; - var m9 = mat[9]; - var m10 = mat[10]; - var m11 = mat[11]; - var m12 = mat[12]; - var m13 = mat[13]; - var m14 = mat[14]; - var m15 = mat[15]; + const mat = transform[0].matrix; + const m0 = mat[0]; + const m1 = mat[1]; + const m2 = mat[2]; + const m3 = mat[3]; + const m4 = mat[4]; + const m5 = mat[5]; + const m6 = mat[6]; + const m7 = mat[7]; + const m8 = mat[8]; + const m9 = mat[9]; + const m10 = mat[10]; + const m11 = mat[11]; + const m12 = mat[12]; + const m13 = mat[13]; + const m14 = mat[14]; + const m15 = mat[15]; if (!didMatrix) { initIdentity(mat); // This will be the first transform. } - var x = computeNextMatrixOperationField(anim, name, X_DIM, 0, value); - var y = computeNextMatrixOperationField(anim, name, Y_DIM, 1, value); - var z = computeNextMatrixOperationField(anim, name, Z_DIM, 2, value); + const x = computeNextMatrixOperationField(anim, name, X_DIM, 0, value); + const y = computeNextMatrixOperationField(anim, name, Y_DIM, 1, value); + const z = computeNextMatrixOperationField(anim, name, Z_DIM, 2, value); InterpolateMatrix[name](mat, x, y, z); if (!didChange) { didChange = m0 !== mat[0] || m1 !== mat[1] || @@ -144,12 +144,12 @@ var computeTransform = function(anim, name, value, result, * @return {function} Function accepting style object, that mutates that style * object and returns a boolean describing if any update was actually applied. */ -var buildStyleInterpolator = function(anims) { +const buildStyleInterpolator = function(anims) { function styleInterpolator(result, value) { - var didChange = false; - var didMatrix = false; - for (var name in anims) { - var anim = anims[name]; + let didChange = false; + let didMatrix = false; + for (const name in anims) { + const anim = anims[name]; if (anim.type === 'linear') { if (name in InterpolateMatrix) { didChange = computeTransform(anim, name, value, result, diff --git a/Libraries/Utilities/createStrictShapeTypeChecker.js b/Libraries/Utilities/createStrictShapeTypeChecker.js index 5cde7eb53..558119f6a 100644 --- a/Libraries/Utilities/createStrictShapeTypeChecker.js +++ b/Libraries/Utilities/createStrictShapeTypeChecker.js @@ -8,8 +8,8 @@ */ 'use strict'; -var invariant = require('fbjs/lib/invariant'); -var merge = require('merge'); +const invariant = require('fbjs/lib/invariant'); +const merge = require('merge'); function createStrictShapeTypeChecker( shapeTypes: {[key: string]: ReactPropsCheckType} @@ -25,9 +25,9 @@ function createStrictShapeTypeChecker( } return; } - var propValue = props[propName]; - var propType = typeof propValue; - var locationName = location || '(unknown)'; + const propValue = props[propName]; + const propType = typeof propValue; + const locationName = location || '(unknown)'; if (propType !== 'object') { invariant( false, @@ -37,9 +37,9 @@ function createStrictShapeTypeChecker( } // We need to check all keys in case some are required but missing from // props. - var allKeys = merge(props[propName], shapeTypes); - for (var key in allKeys) { - var checker = shapeTypes[key]; + const allKeys = merge(props[propName], shapeTypes); + for (const key in allKeys) { + const checker = shapeTypes[key]; if (!checker) { invariant( false, @@ -48,7 +48,7 @@ function createStrictShapeTypeChecker( '\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ') ); } - var error = checker(propValue, key, componentName, location, ...rest); + const error = checker(propValue, key, componentName, location, ...rest); if (error) { invariant( false, diff --git a/Libraries/Utilities/deepFreezeAndThrowOnMutationInDev.js b/Libraries/Utilities/deepFreezeAndThrowOnMutationInDev.js index 041691a67..9e21a2aae 100644 --- a/Libraries/Utilities/deepFreezeAndThrowOnMutationInDev.js +++ b/Libraries/Utilities/deepFreezeAndThrowOnMutationInDev.js @@ -35,7 +35,7 @@ function deepFreezeAndThrowOnMutationInDev(object: T): T { return object; } - var keys = Object.keys(object); + const keys = Object.keys(object); for (var i = 0; i < keys.length; i++) { var key = keys[i]; diff --git a/Libraries/Utilities/differ/__tests__/deepDiffer-test.js b/Libraries/Utilities/differ/__tests__/deepDiffer-test.js index 4fb31ee05..cb39370dc 100644 --- a/Libraries/Utilities/differ/__tests__/deepDiffer-test.js +++ b/Libraries/Utilities/differ/__tests__/deepDiffer-test.js @@ -8,7 +8,7 @@ */ 'use strict'; -var deepDiffer = require('deepDiffer'); +const deepDiffer = require('deepDiffer'); describe('deepDiffer', function() { it('should diff primitives of the same type', () => { @@ -95,7 +95,7 @@ describe('deepDiffer', function() { expect(deepDiffer(['a', 'b'], {length: 2, 0: 'a', 1: 'b'})).toBe(true); }); it('should diff same object', () => { - var obj = [1,[2,3]]; + const obj = [1,[2,3]]; expect(deepDiffer(obj, obj)).toBe(false); }); it('should respect maxDepth arg', () => { diff --git a/Libraries/Utilities/differ/deepDiffer.js b/Libraries/Utilities/differ/deepDiffer.js index f3f826fe9..94dc0cd71 100644 --- a/Libraries/Utilities/differ/deepDiffer.js +++ b/Libraries/Utilities/differ/deepDiffer.js @@ -11,7 +11,7 @@ /* * @returns {bool} true if different, false if equal */ -var deepDiffer = function(one: any, two: any, maxDepth: number = -1): bool { +const deepDiffer = function(one: any, two: any, maxDepth: number = -1): bool { if (maxDepth === 0) { return true; } @@ -37,22 +37,22 @@ var deepDiffer = function(one: any, two: any, maxDepth: number = -1): bool { } if (Array.isArray(one)) { // We know two is also an array because the constructors are equal - var len = one.length; + const len = one.length; if (two.length !== len) { return true; } - for (var ii = 0; ii < len; ii++) { + for (let ii = 0; ii < len; ii++) { if (deepDiffer(one[ii], two[ii], maxDepth - 1)) { return true; } } } else { - for (var key in one) { + for (const key in one) { if (deepDiffer(one[key], two[key], maxDepth - 1)) { return true; } } - for (var twoKey in two) { + for (const twoKey in two) { // The only case we haven't checked yet is keys that are in two but aren't // in one, which means they are different. if (one[twoKey] === undefined && two[twoKey] !== undefined) { diff --git a/Libraries/Utilities/differ/insetsDiffer.js b/Libraries/Utilities/differ/insetsDiffer.js index 7214ab6d7..c86f6d17b 100644 --- a/Libraries/Utilities/differ/insetsDiffer.js +++ b/Libraries/Utilities/differ/insetsDiffer.js @@ -15,14 +15,14 @@ type Inset = { bottom: ?number, } -var dummyInsets = { +const dummyInsets = { top: undefined, left: undefined, right: undefined, bottom: undefined, }; -var insetsDiffer = function( +const insetsDiffer = function( one: ?Inset, two: ?Inset ): bool { diff --git a/Libraries/Utilities/differ/matricesDiffer.js b/Libraries/Utilities/differ/matricesDiffer.js index 177a7a110..883081fa0 100644 --- a/Libraries/Utilities/differ/matricesDiffer.js +++ b/Libraries/Utilities/differ/matricesDiffer.js @@ -16,7 +16,7 @@ * @param {MatrixMath.Matrix} two Second matrix. * @return {boolean} Whether or not the two matrices differ. */ -var matricesDiffer = function(one, two) { +const matricesDiffer = function(one, two) { if (one === two) { return false; } diff --git a/Libraries/Utilities/differ/pointsDiffer.js b/Libraries/Utilities/differ/pointsDiffer.js index e019124e7..b9d239c79 100644 --- a/Libraries/Utilities/differ/pointsDiffer.js +++ b/Libraries/Utilities/differ/pointsDiffer.js @@ -13,9 +13,9 @@ type Point = { y: ?number, } -var dummyPoint = {x: undefined, y: undefined}; +const dummyPoint = {x: undefined, y: undefined}; -var pointsDiffer = function(one: ?Point, two: ?Point): bool { +const pointsDiffer = function(one: ?Point, two: ?Point): bool { one = one || dummyPoint; two = two || dummyPoint; return one !== two && ( diff --git a/Libraries/Utilities/differ/sizesDiffer.js b/Libraries/Utilities/differ/sizesDiffer.js index c4e104a14..ad2939cc7 100644 --- a/Libraries/Utilities/differ/sizesDiffer.js +++ b/Libraries/Utilities/differ/sizesDiffer.js @@ -7,9 +7,9 @@ */ 'use strict'; -var dummySize = {width: undefined, height: undefined}; +const dummySize = {width: undefined, height: undefined}; -var sizesDiffer = function(one, two) { +const sizesDiffer = function(one, two) { one = one || dummySize; two = two || dummySize; return one !== two && ( diff --git a/Libraries/Utilities/dismissKeyboard.js b/Libraries/Utilities/dismissKeyboard.js index a5b9e2f00..64f7368a3 100644 --- a/Libraries/Utilities/dismissKeyboard.js +++ b/Libraries/Utilities/dismissKeyboard.js @@ -9,7 +9,7 @@ */ 'use strict'; -var TextInputState = require('TextInputState'); +const TextInputState = require('TextInputState'); function dismissKeyboard() { TextInputState.blurTextInput(TextInputState.currentlyFocusedField()); diff --git a/Libraries/Utilities/groupByEveryN.js b/Libraries/Utilities/groupByEveryN.js index 2cda280be..bdf13b226 100644 --- a/Libraries/Utilities/groupByEveryN.js +++ b/Libraries/Utilities/groupByEveryN.js @@ -25,10 +25,10 @@ 'use strict'; function groupByEveryN(array: Array, n: number): Array> { - var result = []; - var temp = []; + const result = []; + let temp = []; - for (var i = 0; i < array.length; ++i) { + for (let i = 0; i < array.length; ++i) { if (i > 0 && i % n === 0) { result.push(temp); temp = []; diff --git a/Libraries/Utilities/logError.js b/Libraries/Utilities/logError.js index 5482448ae..e79b34056 100644 --- a/Libraries/Utilities/logError.js +++ b/Libraries/Utilities/logError.js @@ -13,9 +13,9 @@ * `console.error` as a failure callback - it's not properly bound. If passes an * `Error` object, it will print the message and stack. */ -var logError = function(...args: $ReadOnlyArray) { +const logError = function(...args: $ReadOnlyArray) { if (args.length === 1 && args[0] instanceof Error) { - var err = args[0]; + const err = args[0]; console.error('Error: "' + err.message + '". Stack:\n' + err.stack); } else { console.error.apply(console, args); diff --git a/Libraries/Utilities/mergeIntoFast.js b/Libraries/Utilities/mergeIntoFast.js index e657de7c3..cfbc87923 100644 --- a/Libraries/Utilities/mergeIntoFast.js +++ b/Libraries/Utilities/mergeIntoFast.js @@ -15,8 +15,8 @@ * @param {object} one Object to assign to. * @param {object} two Object to assign from. */ -var mergeIntoFast = function(one: Object, two: Object): void { - for (var keyTwo in two) { +const mergeIntoFast = function(one: Object, two: Object): void { + for (const keyTwo in two) { one[keyTwo] = two[keyTwo]; } }; diff --git a/Libraries/Utilities/stringifySafe.js b/Libraries/Utilities/stringifySafe.js index f8f7ab8f0..4536b8f66 100644 --- a/Libraries/Utilities/stringifySafe.js +++ b/Libraries/Utilities/stringifySafe.js @@ -13,8 +13,8 @@ * (e.g. from circular objects) and always returns a string and never throws. */ function stringifySafe(arg: any): string { - var ret; - var type = typeof arg; + let ret; + const type = typeof arg; if (arg === undefined) { ret = 'undefined'; } else if (arg === null) { diff --git a/Libraries/Utilities/truncate.js b/Libraries/Utilities/truncate.js index 5b89e8ff2..017a52491 100644 --- a/Libraries/Utilities/truncate.js +++ b/Libraries/Utilities/truncate.js @@ -30,12 +30,12 @@ const truncate = function( if (str && str.length && str.length - options.minDelta + options.elipsis.length >= maxChars) { // If the slice is happening in the middle of a wide char, add one more char - var extraChar = str.charCodeAt(maxChars - options.elipsis.length) > 255 + const extraChar = str.charCodeAt(maxChars - options.elipsis.length) > 255 ? 1 : 0; str = str.slice(0, maxChars - options.elipsis.length + 1 + extraChar); if (options.breakOnWords) { - var ii = Math.max(str.lastIndexOf(' '), str.lastIndexOf('\n')); + const ii = Math.max(str.lastIndexOf(' '), str.lastIndexOf('\n')); str = str.slice(0, ii); } str = str.trim() + options.elipsis; diff --git a/Libraries/Vibration/Vibration.js b/Libraries/Vibration/Vibration.js index c0ee75203..182ca26d9 100644 --- a/Libraries/Vibration/Vibration.js +++ b/Libraries/Vibration/Vibration.js @@ -9,8 +9,8 @@ */ 'use strict'; -var RCTVibration = require('NativeModules').Vibration; -var Platform = require('Platform'); +const RCTVibration = require('NativeModules').Vibration; +const Platform = require('Platform'); /** * Vibration API @@ -18,8 +18,8 @@ var Platform = require('Platform'); * See https://facebook.github.io/react-native/docs/vibration.html */ -var _vibrating: boolean = false; -var _id: number = 0; // _id is necessary to prevent race condition. +let _vibrating: boolean = false; +let _id: number = 0; // _id is necessary to prevent race condition. function vibrateByPattern(pattern: Array, repeat: boolean = false) { if (_vibrating) { @@ -53,7 +53,7 @@ function vibrateScheduler(id, pattern: Array, repeat: boolean, nextIndex setTimeout(() => vibrateScheduler(id, pattern, repeat, nextIndex + 1), pattern[nextIndex]); } -var Vibration = { +const Vibration = { /** * Trigger a vibration with specified `pattern`. * diff --git a/Libraries/Vibration/VibrationIOS.android.js b/Libraries/Vibration/VibrationIOS.android.js index b57279a73..93a1aab1a 100644 --- a/Libraries/Vibration/VibrationIOS.android.js +++ b/Libraries/Vibration/VibrationIOS.android.js @@ -9,9 +9,9 @@ */ 'use strict'; -var warning = require('fbjs/lib/warning'); +const warning = require('fbjs/lib/warning'); -var VibrationIOS = { +const VibrationIOS = { vibrate: function() { warning('VibrationIOS is not supported on this platform!'); } diff --git a/Libraries/Vibration/VibrationIOS.ios.js b/Libraries/Vibration/VibrationIOS.ios.js index 5ce5f4019..29cc3eee0 100644 --- a/Libraries/Vibration/VibrationIOS.ios.js +++ b/Libraries/Vibration/VibrationIOS.ios.js @@ -8,9 +8,9 @@ */ 'use strict'; -var RCTVibration = require('NativeModules').Vibration; +const RCTVibration = require('NativeModules').Vibration; -var invariant = require('fbjs/lib/invariant'); +const invariant = require('fbjs/lib/invariant'); /** * NOTE: `VibrationIOS` is being deprecated. Use `Vibration` instead. @@ -25,7 +25,7 @@ var invariant = require('fbjs/lib/invariant'); * Vibration patterns are currently unsupported. */ -var VibrationIOS = { +const VibrationIOS = { /** * @deprecated */ diff --git a/Libraries/WebSocket/__tests__/WebSocket-test.js b/Libraries/WebSocket/__tests__/WebSocket-test.js index c6e04bf0a..a263caf3e 100644 --- a/Libraries/WebSocket/__tests__/WebSocket-test.js +++ b/Libraries/WebSocket/__tests__/WebSocket-test.js @@ -15,7 +15,7 @@ jest.setMock('NativeModules', { } }); -var WebSocket = require('WebSocket'); +const WebSocket = require('WebSocket'); describe('WebSocket', function() { diff --git a/Libraries/vendor/core/Map.js b/Libraries/vendor/core/Map.js index 115e2f855..575a6b1d5 100644 --- a/Libraries/vendor/core/Map.js +++ b/Libraries/vendor/core/Map.js @@ -12,10 +12,10 @@ 'use strict'; -var _shouldPolyfillES6Collection = require('_shouldPolyfillES6Collection'); -var guid = require('guid'); -var isNode = require('fbjs/lib/isNode'); -var toIterator = require('toIterator'); +const _shouldPolyfillES6Collection = require('_shouldPolyfillES6Collection'); +const guid = require('guid'); +const isNode = require('fbjs/lib/isNode'); +const toIterator = require('toIterator'); module.exports = (function(global, undefined) { // Since our implementation is spec-compliant for the most part we can safely @@ -81,23 +81,23 @@ module.exports = (function(global, undefined) { */ // Kinds of map iterations 23.1.5.3 - var KIND_KEY = 'key'; - var KIND_VALUE = 'value'; - var KIND_KEY_VALUE = 'key+value'; + const KIND_KEY = 'key'; + const KIND_VALUE = 'value'; + const KIND_KEY_VALUE = 'key+value'; // In older browsers we can't create a null-prototype object so we have to // defend against key collisions with built-in methods. - var KEY_PREFIX = '$map_'; + const KEY_PREFIX = '$map_'; // This property will be used as the internal size variable to disallow // writing and to issue warnings for writings in development. - var SECRET_SIZE_PROP; + let SECRET_SIZE_PROP; if (__DEV__) { SECRET_SIZE_PROP = '$size' + guid(); } // In oldIE we use the DOM Node `uniqueID` property to get create the hash. - var OLD_IE_HASH_PREFIX = 'IE_HASH_'; + const OLD_IE_HASH_PREFIX = 'IE_HASH_'; class Map { @@ -118,8 +118,8 @@ module.exports = (function(global, undefined) { initMap(this); if (iterable != null) { - var it = toIterator(iterable); - var next; + const it = toIterator(iterable); + let next; while (!(next = it.next()).done) { if (!isObject(next.value)) { throw new TypeError('Expected iterable items to be pair objects.'); @@ -145,7 +145,7 @@ module.exports = (function(global, undefined) { * @return {boolean} */ has(key) { - var index = getIndex(this, key); + const index = getIndex(this, key); return !!(index != null && this._mapData[index]); } @@ -158,7 +158,7 @@ module.exports = (function(global, undefined) { * @return {map} */ set(key, value) { - var index = getIndex(this, key); + let index = getIndex(this, key); if (index != null && this._mapData[index]) { this._mapData[index][1] = value; @@ -186,7 +186,7 @@ module.exports = (function(global, undefined) { * @return {*} */ get(key) { - var index = getIndex(this, key); + const index = getIndex(this, key); if (index == null) { return undefined; } else { @@ -203,7 +203,7 @@ module.exports = (function(global, undefined) { * @return {boolean} Whether the key was found and deleted. */ delete(key) { - var index = getIndex(this, key); + const index = getIndex(this, key); if (index != null && this._mapData[index]) { setIndex(this, key, undefined); this._mapData[index] = undefined; @@ -263,14 +263,14 @@ module.exports = (function(global, undefined) { throw new TypeError('Callback must be callable.'); } - var boundCallback = callback.bind(thisArg || undefined); - var mapData = this._mapData; + const boundCallback = callback.bind(thisArg || undefined); + const mapData = this._mapData; // Note that `mapData.length` should be computed on each iteration to // support iterating over new items in the map that were added after the // start of the iteration. - for (var i = 0; i < mapData.length; i++) { - var entry = mapData[i]; + for (let i = 0; i < mapData.length; i++) { + const entry = mapData[i]; if (entry != null) { boundCallback(entry[1], entry[0], this); } @@ -316,18 +316,18 @@ module.exports = (function(global, undefined) { throw new TypeError('Expected to be called on a MapIterator.'); } - var map = this._map; - var index = this._nextIndex; - var kind = this._kind; + const map = this._map; + let index = this._nextIndex; + const kind = this._kind; if (map == null) { return createIterResultObject(undefined, true); } - var entries = map._mapData; + const entries = map._mapData; while (index < entries.length) { - var record = entries[index]; + const record = entries[index]; index += 1; this._nextIndex = index; @@ -369,10 +369,10 @@ module.exports = (function(global, undefined) { */ function getIndex(map, key) { if (isObject(key)) { - var hash = getHash(key); + const hash = getHash(key); return map._objectIndex[hash]; } else { - var prefixedKey = KEY_PREFIX + key; + const prefixedKey = KEY_PREFIX + key; if (typeof key === 'string') { return map._stringIndex[prefixedKey]; } else { @@ -388,17 +388,17 @@ module.exports = (function(global, undefined) { * @param {*} key */ function setIndex(map, key, index) { - var shouldDelete = index == null; + const shouldDelete = index == null; if (isObject(key)) { - var hash = getHash(key); + const hash = getHash(key); if (shouldDelete) { delete map._objectIndex[hash]; } else { map._objectIndex[hash] = index; } } else { - var prefixedKey = KEY_PREFIX + key; + const prefixedKey = KEY_PREFIX + key; if (typeof key === 'string') { if (shouldDelete) { delete map._stringIndex[prefixedKey]; @@ -505,7 +505,7 @@ module.exports = (function(global, undefined) { } // Are we in a legit ES5 environment. Spoiler alert: that doesn't include IE8. - var isES5 = (function() { + const isES5 = (function() { try { Object.defineProperty({}, 'x', {}); return true; @@ -537,7 +537,7 @@ module.exports = (function(global, undefined) { * @return {?string} */ function getIENodeHash(node) { - var uniqueID; + let uniqueID; switch (node.nodeType) { case 1: // Element uniqueID = node.uniqueID; @@ -556,10 +556,10 @@ module.exports = (function(global, undefined) { } } - var getHash = (function() { - var propIsEnumerable = Object.prototype.propertyIsEnumerable; - var hashProperty = guid(); - var hashCounter = 0; + const getHash = (function() { + const propIsEnumerable = Object.prototype.propertyIsEnumerable; + const hashProperty = guid(); + let hashCounter = 0; /** * Get the "hash" associated with an object. diff --git a/Libraries/vendor/core/Set.js b/Libraries/vendor/core/Set.js index 16e3cecae..3ba61c26a 100644 --- a/Libraries/vendor/core/Set.js +++ b/Libraries/vendor/core/Set.js @@ -12,10 +12,10 @@ 'use strict'; -var Map = require('Map'); +const Map = require('Map'); -var _shouldPolyfillES6Collection = require('_shouldPolyfillES6Collection'); -var toIterator = require('toIterator'); +const _shouldPolyfillES6Collection = require('_shouldPolyfillES6Collection'); +const toIterator = require('toIterator'); module.exports = (function(global) { // Since our implementation is spec-compliant for the most part we can safely @@ -88,8 +88,8 @@ module.exports = (function(global) { initSet(this); if (iterable != null) { - var it = toIterator(iterable); - var next; + const it = toIterator(iterable); + let next; while (!(next = it.next()).done) { this.add(next.value); } @@ -129,7 +129,7 @@ module.exports = (function(global) { * @return {boolean} */ delete(value) { - var ret = this._map.delete(value); + const ret = this._map.delete(value); this.size = this._map.size; return ret; } @@ -151,9 +151,9 @@ module.exports = (function(global) { * @param {function} callback */ forEach(callback) { - var thisArg = arguments[1]; - var it = this._map.keys(); - var next; + const thisArg = arguments[1]; + const it = this._map.keys(); + let next; while (!(next = it.next()).done) { callback.call(thisArg, next.value, next.value, this); } diff --git a/Libraries/vendor/core/_shouldPolyfillES6Collection.js b/Libraries/vendor/core/_shouldPolyfillES6Collection.js index 84ed51ded..576d1eb67 100644 --- a/Libraries/vendor/core/_shouldPolyfillES6Collection.js +++ b/Libraries/vendor/core/_shouldPolyfillES6Collection.js @@ -14,7 +14,7 @@ * that is safe to be used. */ function _shouldActuallyPolyfillES6Collection(collectionName: string): boolean { - var Collection = global[collectionName]; + const Collection = global[collectionName]; if (Collection == null) { return true; } @@ -27,7 +27,7 @@ function _shouldActuallyPolyfillES6Collection(collectionName: string): boolean { return true; } - var proto = Collection.prototype; + const proto = Collection.prototype; // These checks are adapted from es6-shim: https://fburl.com/34437854 // NOTE: `isCallableWithoutNew` and `!supportsSubclassing` are not checked diff --git a/Libraries/vendor/core/getObjectValues.js b/Libraries/vendor/core/getObjectValues.js index 398788c1e..0a020af51 100644 --- a/Libraries/vendor/core/getObjectValues.js +++ b/Libraries/vendor/core/getObjectValues.js @@ -18,8 +18,8 @@ * @return {array} The object's values. */ function getObjectValues(obj) { - var values = []; - for (var key in obj) { + const values = []; + for (const key in obj) { values.push(obj[key]); } return values; diff --git a/Libraries/vendor/core/isEmpty.js b/Libraries/vendor/core/isEmpty.js index 6d451729c..c7747c980 100644 --- a/Libraries/vendor/core/isEmpty.js +++ b/Libraries/vendor/core/isEmpty.js @@ -14,7 +14,7 @@ function isEmpty(obj) { if (Array.isArray(obj)) { return obj.length === 0; } else if (typeof obj === 'object') { - for (var i in obj) { + for (const i in obj) { return false; } return true; diff --git a/Libraries/vendor/core/mergeHelpers.js b/Libraries/vendor/core/mergeHelpers.js index e24559ddb..10072ed46 100644 --- a/Libraries/vendor/core/mergeHelpers.js +++ b/Libraries/vendor/core/mergeHelpers.js @@ -10,13 +10,13 @@ 'use strict'; -var invariant = require('fbjs/lib/invariant'); +const invariant = require('fbjs/lib/invariant'); /** * Maximum number of levels to traverse. Will catch circular structures. * @const */ -var MAX_MERGE_DEPTH = 36; +const MAX_MERGE_DEPTH = 36; /** * We won't worry about edge cases like new String('x') or new Boolean(true). @@ -24,11 +24,11 @@ var MAX_MERGE_DEPTH = 36; * @param {*} o The item/object/value to test. * @return {boolean} true iff the argument is a terminal. */ -var isTerminal = function(o) { +const isTerminal = function(o) { return typeof o !== 'object' || o instanceof Date || o === null; }; -var mergeHelpers = { +const mergeHelpers = { MAX_MERGE_DEPTH: MAX_MERGE_DEPTH, diff --git a/Libraries/vendor/core/toIterator.js b/Libraries/vendor/core/toIterator.js index cabd1e2b0..728b68c7b 100644 --- a/Libraries/vendor/core/toIterator.js +++ b/Libraries/vendor/core/toIterator.js @@ -17,15 +17,15 @@ * Constants */ -var KIND_KEY = 'key'; -var KIND_VALUE = 'value'; -var KIND_KEY_VAL = 'key+value'; +const KIND_KEY = 'key'; +const KIND_VALUE = 'value'; +const KIND_KEY_VAL = 'key+value'; /*global Symbol: true*/ -var ITERATOR_SYMBOL = (typeof Symbol === 'function') +const ITERATOR_SYMBOL = (typeof Symbol === 'function') ? Symbol.iterator : '@@iterator'; -var toIterator = (function() { +const toIterator = (function() { if (!(Array.prototype[ITERATOR_SYMBOL] && String.prototype[ITERATOR_SYMBOL])) { // IIFE to avoid creating classes for no reason because of hoisting. @@ -51,10 +51,10 @@ var toIterator = (function() { return createIterResultObject(undefined, true); } - var array = this._iteratedObject; - var len = this._iteratedObject.length; - var index = this._nextIndex; - var kind = this._kind; + const array = this._iteratedObject; + const len = this._iteratedObject.length; + const index = this._nextIndex; + const kind = this._kind; if (index >= len) { this._iteratedObject = undefined; @@ -98,22 +98,22 @@ var toIterator = (function() { return createIterResultObject(undefined, true); } - var index = this._nextIndex; - var s = this._iteratedString; - var len = s.length; + const index = this._nextIndex; + const s = this._iteratedString; + const len = s.length; if (index >= len) { this._iteratedString = undefined; return createIterResultObject(undefined, true); } - var ret; - var first = s.charCodeAt(index); + let ret; + const first = s.charCodeAt(index); if (first < 0xD800 || first > 0xDBFF || index + 1 === len) { ret = s[index]; } else { - var second = s.charCodeAt(index + 1); + const second = s.charCodeAt(index + 1); if (second < 0xDC00 || second > 0xDFFF) { ret = s[index]; } else { diff --git a/Libraries/vendor/document/selection/DocumentSelectionState.js b/Libraries/vendor/document/selection/DocumentSelectionState.js index 28b93e343..350732776 100644 --- a/Libraries/vendor/document/selection/DocumentSelectionState.js +++ b/Libraries/vendor/document/selection/DocumentSelectionState.js @@ -9,7 +9,7 @@ 'use strict'; -var mixInEventEmitter = require('mixInEventEmitter'); +const mixInEventEmitter = require('mixInEventEmitter'); /** * DocumentSelectionState is responsible for maintaining selection information