@samitouri / QOS-React / commits / ea9714807b

react-native-renderer: convert vars to let/const (#11722)

Raphael Amorim committed Nov 30, 2017 at 19:39 UTC ea9714807b0d694e6f67d52ccf7aac93439b16f7
25 files changed +139 -139
packages/react-native-renderer/index.js
+1 -1
@@ -9,7 +9,7 @@
9
10 'use strict';
11
12 -var ReactNativeRenderer = require('./src/ReactNativeRenderer');
12 +const ReactNativeRenderer = require('./src/ReactNativeRenderer');
13
14 // TODO: decide on the top-level export form.
15 // This is hacky but makes it work with both Rollup and Jest.
packages/react-native-renderer/src/NativeMethodsMixinUtils.js
+4 -4
@@ -37,9 +37,9 @@ export function mountSafeCallback(context: any, callback: ?Function): any {
37
38 export function throwOnStylesProp(component: any, props: any) {
39 if (props.styles !== undefined) {
40 - var owner = component._owner || null;
41 - var name = component.constructor.displayName;
42 - var msg =
40 + const owner = component._owner || null;
41 + const name = component.constructor.displayName;
42 + let msg =
43 '`styles` is not a supported property of `' +
44 name +
45 '`, did ' +
@@ -56,7 +56,7 @@ export function throwOnStylesProp(component: any, props: any) {
56 }
57
58 export function warnForStyleProps(props: any, validAttributes: any) {
59 - for (var key in validAttributes.style) {
59 + for (const key in validAttributes.style) {
60 if (!(validAttributes[key] || props[key] === undefined)) {
61 console.error(
62 'You are setting the style `{ ' +
packages/react-native-renderer/src/ReactNativeAttributePayload.js
+21 -21
@@ -13,7 +13,7 @@ import flattenStyle from 'flattenStyle';
13
14 import ReactNativePropRegistry from './ReactNativePropRegistry';
15
16 -var emptyObject = {};
16 +const emptyObject = {};
17
18 /**
19 * Create a payload that contains all the updates between two sets of props.
@@ -41,8 +41,8 @@ type AttributeConfiguration = {
41 type NestedNode = Array<NestedNode> | Object | number;
42
43 // Tracks removed keys
44 -var removedKeys = null;
45 -var removedKeyCount = 0;
44 +let removedKeys = null;
45 +let removedKeyCount = 0;
46
47 function defaultDiffer(prevProp: mixed, nextProp: mixed): boolean {
48 if (typeof nextProp !== 'object' || nextProp === null) {
@@ -67,7 +67,7 @@ function restoreDeletedValuesInNestedArray(
67 validAttributes: AttributeConfiguration,
68 ) {
69 if (Array.isArray(node)) {
70 - var i = node.length;
70 + let i = node.length;
71 while (i-- && removedKeyCount > 0) {
72 restoreDeletedValuesInNestedArray(
73 updatePayload,
@@ -76,17 +76,17 @@ function restoreDeletedValuesInNestedArray(
76 );
77 }
78 } else if (node && removedKeyCount > 0) {
79 - var obj = resolveObject(node);
80 - for (var propKey in removedKeys) {
79 + const obj = resolveObject(node);
80 + for (const propKey in removedKeys) {
81 if (!removedKeys[propKey]) {
82 continue;
83 }
84 - var nextProp = obj[propKey];
84 + let nextProp = obj[propKey];
85 if (nextProp === undefined) {
86 continue;
87 }
88
89 - var attributeConfig = validAttributes[propKey];
89 + const attributeConfig = validAttributes[propKey];
90 if (!attributeConfig) {
91 continue; // not a valid native prop
92 }
@@ -106,7 +106,7 @@ function restoreDeletedValuesInNestedArray(
106 typeof attributeConfig.process === 'function'
107 ) {
108 // case: CustomAttributeConfiguration
109 - var nextValue =
109 + const nextValue =
110 typeof attributeConfig.process === 'function'
111 ? attributeConfig.process(nextProp)
112 : nextProp;
@@ -124,9 +124,9 @@ function diffNestedArrayProperty(
124 nextArray: Array<NestedNode>,
125 validAttributes: AttributeConfiguration,
126 ): ?Object {
127 - var minLength =
127 + const minLength =
128 prevArray.length < nextArray.length ? prevArray.length : nextArray.length;
129 - var i;
129 + let i;
130 for (i = 0; i < minLength; i++) {
131 // Diff any items in the array in the forward direction. Repeated keys
132 // will be overwritten by later values.
@@ -241,7 +241,7 @@ function addNestedProperty(
241 );
242 }
243
244 - for (var i = 0; i < nextProp.length; i++) {
244 + for (let i = 0; i < nextProp.length; i++) {
245 // Add all the properties of the array.
246 updatePayload = addNestedProperty(
247 updatePayload,
@@ -275,7 +275,7 @@ function clearNestedProperty(
275 );
276 }
277
278 - for (var i = 0; i < prevProp.length; i++) {
278 + for (let i = 0; i < prevProp.length; i++) {
279 // Add all the properties of the array.
280 updatePayload = clearNestedProperty(
281 updatePayload,
@@ -298,11 +298,11 @@ function diffProperties(
298 nextProps: Object,
299 validAttributes: AttributeConfiguration,
300 ): ?Object {
301 - var attributeConfig: ?(CustomAttributeConfiguration | AttributeConfiguration);
302 - var nextProp;
303 - var prevProp;
301 + let attributeConfig: ?(CustomAttributeConfiguration | AttributeConfiguration);
302 + let nextProp;
303 + let prevProp;
304
305 - for (var propKey in nextProps) {
305 + for (const propKey in nextProps) {
306 attributeConfig = validAttributes[propKey];
307 if (!attributeConfig) {
308 continue; // not a valid native prop
@@ -350,7 +350,7 @@ function diffProperties(
350 typeof attributeConfig.process === 'function'
351 ) {
352 // case: CustomAttributeConfiguration
353 - var nextValue =
353 + const nextValue =
354 typeof attributeConfig.process === 'function'
355 ? attributeConfig.process(nextProp)
356 : nextProp;
@@ -375,13 +375,13 @@ function diffProperties(
375 typeof attributeConfig.process === 'function'
376 ) {
377 // case: CustomAttributeConfiguration
378 - var shouldUpdate =
378 + const shouldUpdate =
379 prevProp === undefined ||
380 (typeof attributeConfig.diff === 'function'
381 ? attributeConfig.diff(prevProp, nextProp)
382 : defaultDiffer(prevProp, nextProp));
383 if (shouldUpdate) {
384 - nextValue =
384 + const nextValue =
385 typeof attributeConfig.process === 'function'
386 ? attributeConfig.process(nextProp)
387 : nextProp;
@@ -413,7 +413,7 @@ function diffProperties(
413 // Also iterate through all the previous props to catch any that have been
414 // removed and make sure native gets the signal so it can reset them to the
415 // default.
416 - for (propKey in prevProps) {
416 + for (const propKey in prevProps) {
417 if (nextProps[propKey] !== undefined) {
418 continue; // we've already covered this key in the previous pass
419 }
packages/react-native-renderer/src/ReactNativeComponent.js
+1 -1
@@ -151,7 +151,7 @@ class ReactNativeComponent<DefaultProps, Props, State> extends React.Component<
151 const viewConfig: ReactNativeBaseComponentViewConfig =
152 maybeInstance.viewConfig;
153
154 - var updatePayload = ReactNativeAttributePayload.create(
154 + const updatePayload = ReactNativeAttributePayload.create(
155 nativeProps,
156 viewConfig.validAttributes,
157 );
packages/react-native-renderer/src/ReactNativeComponentTree.js
+3 -3
@@ -7,8 +7,8 @@
7
8 import invariant from 'fbjs/lib/invariant';
9
10 -var instanceCache = {};
11 -var instanceProps = {};
10 +const instanceCache = {};
11 +const instanceProps = {};
12
13 export function precacheFiberNode(hostInst, tag) {
14 instanceCache[tag] = hostInst;
@@ -24,7 +24,7 @@ function getInstanceFromTag(tag) {
24 }
25
26 function getTagFromInstance(inst) {
27 - var tag = inst.stateNode._nativeTag;
27 + const tag = inst.stateNode._nativeTag;
28 invariant(tag, 'All native instances should have a tag.');
29 return tag;
30 }
packages/react-native-renderer/src/ReactNativeEventEmitter.js
+20 -20
@@ -25,7 +25,7 @@ export {getListener, registrationNameModules as registrationNames};
25 */
26
27 // Shared default empty native event - conserve memory.
28 -var EMPTY_NATIVE_EVENT = {};
28 +const EMPTY_NATIVE_EVENT = {};
29
30 /**
31 * Selects a subsequence of `Touch`es, without destroying `touches`.
@@ -34,9 +34,9 @@ var EMPTY_NATIVE_EVENT = {};
34 * @param {Array<number>} indices Indices by which to pull subsequence.
35 * @return {Array<Touch>} Subsequence of touch objects.
36 */
37 -var touchSubsequence = function(touches, indices) {
38 - var ret = [];
39 - for (var i = 0; i < indices.length; i++) {
37 +const touchSubsequence = function(touches, indices) {
38 + const ret = [];
39 + for (let i = 0; i < indices.length; i++) {
40 ret.push(touches[indices[i]]);
41 }
42 return ret;
@@ -53,22 +53,22 @@ var touchSubsequence = function(touches, indices) {
53 * @param {Array<number>} indices Indices to remove from `touches`.
54 * @return {Array<Touch>} Subsequence of removed touch objects.
55 */
56 -var removeTouchesAtIndices = function(
56 +const removeTouchesAtIndices = function(
57 touches: Array<Object>,
58 indices: Array<number>,
59 ): Array<Object> {
60 - var rippedOut = [];
60 + const rippedOut = [];
61 // use an unsafe downcast to alias to nullable elements,
62 // so we can delete and then compact.
63 - var temp: Array<?Object> = (touches: Array<any>);
64 - for (var i = 0; i < indices.length; i++) {
65 - var index = indices[i];
63 + const temp: Array<?Object> = (touches: Array<any>);
64 + for (let i = 0; i < indices.length; i++) {
65 + const index = indices[i];
66 rippedOut.push(touches[index]);
67 temp[index] = null;
68 }
69 - var fillAt = 0;
70 - for (var j = 0; j < temp.length; j++) {
71 - var cur = temp[j];
69 + let fillAt = 0;
70 + for (let j = 0; j < temp.length; j++) {
71 + const cur = temp[j];
72 if (cur !== null) {
73 temp[fillAt++] = cur;
74 }
@@ -92,8 +92,8 @@ export function _receiveRootNodeIDEvent(
92 topLevelType: string,
93 nativeEventParam: ?Object,
94 ) {
95 - var nativeEvent = nativeEventParam || EMPTY_NATIVE_EVENT;
96 - var inst = getInstanceFromNode(rootNodeID);
95 + const nativeEvent = nativeEventParam || EMPTY_NATIVE_EVENT;
96 + const inst = getInstanceFromNode(rootNodeID);
97 batchedUpdates(function() {
98 handleTopLevel(topLevelType, inst, nativeEvent, nativeEvent.target);
99 });
@@ -145,21 +145,21 @@ export function receiveTouches(
145 touches: Array<Object>,
146 changedIndices: Array<number>,
147 ) {
148 - var changedTouches =
148 + const changedTouches =
149 eventTopLevelType === 'topTouchEnd' ||
150 eventTopLevelType === 'topTouchCancel'
151 ? removeTouchesAtIndices(touches, changedIndices)
152 : touchSubsequence(touches, changedIndices);
153
154 - for (var jj = 0; jj < changedTouches.length; jj++) {
155 - var touch = changedTouches[jj];
154 + for (let jj = 0; jj < changedTouches.length; jj++) {
155 + const touch = changedTouches[jj];
156 // Touch objects can fulfill the role of `DOM` `Event` objects if we set
157 // the `changedTouches`/`touches`. This saves allocations.
158 touch.changedTouches = changedTouches;
159 touch.touches = touches;
160 - var nativeEvent = touch;
161 - var rootNodeID = null;
162 - var target = nativeEvent.target;
160 + const nativeEvent = touch;
161 + let rootNodeID = null;
162 + const target = nativeEvent.target;
163 if (target !== null && target !== undefined) {
164 if (target < ReactNativeTagHandles.tagsStartAt) {
165 if (__DEV__) {
packages/react-native-renderer/src/ReactNativeEventPluginOrder.js
+1 -1
@@ -7,7 +7,7 @@
7 * @flow
8 */
9
10 -var ReactNativeEventPluginOrder = [
10 +const ReactNativeEventPluginOrder = [
11 'ResponderEventPlugin',
12 'ReactNativeBridgeEventPlugin',
13 ];
packages/react-native-renderer/src/ReactNativeFiberHostComponent.js
+1 -1
@@ -78,7 +78,7 @@ class ReactNativeFiberHostComponent {
78 warnForStyleProps(nativeProps, this.viewConfig.validAttributes);
79 }
80
81 - var updatePayload = ReactNativeAttributePayload.create(
81 + const updatePayload = ReactNativeAttributePayload.create(
82 nativeProps,
83 this.viewConfig.validAttributes,
84 );
packages/react-native-renderer/src/ReactNativeFiberInspector.js
+7 -7
@@ -25,20 +25,20 @@ import {getClosestInstanceFromNode} from './ReactNativeComponentTree';
25 let getInspectorDataForViewTag;
26
27 if (__DEV__) {
28 - var traverseOwnerTreeUp = function(hierarchy, instance: any) {
28 + const traverseOwnerTreeUp = function(hierarchy, instance: any) {
29 if (instance) {
30 hierarchy.unshift(instance);
31 traverseOwnerTreeUp(hierarchy, instance._debugOwner);
32 }
33 };
34
35 - var getOwnerHierarchy = function(instance: any) {
36 - var hierarchy = [];
35 + const getOwnerHierarchy = function(instance: any) {
36 + const hierarchy = [];
37 traverseOwnerTreeUp(hierarchy, instance);
38 return hierarchy;
39 };
40
41 - var lastNonHostInstance = function(hierarchy) {
41 + const lastNonHostInstance = function(hierarchy) {
42 for (let i = hierarchy.length - 1; i > 1; i--) {
43 const instance = hierarchy[i];
44
@@ -49,7 +49,7 @@ if (__DEV__) {
49 return hierarchy[0];
50 };
51
52 - var getHostProps = function(fiber) {
52 + const getHostProps = function(fiber) {
53 const host = findCurrentHostFiber(fiber);
54 if (host) {
55 return host.memoizedProps || emptyObject;
@@ -57,7 +57,7 @@ if (__DEV__) {
57 return emptyObject;
58 };
59
60 - var getHostNode = function(fiber: Fiber | null, findNodeHandle) {
60 + const getHostNode = function(fiber: Fiber | null, findNodeHandle) {
61 let hostNode;
62 // look for children first for the hostNode
63 // as composite fibers do not have a hostNode
@@ -73,7 +73,7 @@ if (__DEV__) {
73 return null;
74 };
75
76 - var createHierarchy = function(fiberHierarchy) {
76 + const createHierarchy = function(fiberHierarchy) {
77 return fiberHierarchy.map(fiber => ({
78 name: getComponentName(fiber),
79 getInspectorData: findNodeHandle => ({
packages/react-native-renderer/src/ReactNativeGlobalResponderHandler.js
+2 -2
@@ -8,10 +8,10 @@
8 // Module provided by RN:
9 import UIManager from 'UIManager';
10
11 -var ReactNativeGlobalResponderHandler = {
11 +const ReactNativeGlobalResponderHandler = {
12 onChange: function(from, to, blockNativeResponder) {
13 if (to !== null) {
14 - var tag = to.stateNode._nativeTag;
14 + const tag = to.stateNode._nativeTag;
15 UIManager.setJSResponder(tag, blockNativeResponder);
16 } else {
17 UIManager.clearJSResponder();
packages/react-native-renderer/src/ReactNativePropRegistry.js
+5 -5
@@ -7,13 +7,13 @@
7 * @flow
8 */
9
10 -var objects = {};
11 -var uniqueID = 1;
12 -var emptyObject = {};
10 +const objects = {};
11 +let uniqueID = 1;
12 +const emptyObject = {};
13
14 class ReactNativePropRegistry {
15 static register(object: Object): number {
16 - var id = ++uniqueID;
16 + const id = ++uniqueID;
17 if (__DEV__) {
18 Object.freeze(object);
19 }
@@ -28,7 +28,7 @@ class ReactNativePropRegistry {
28 return emptyObject;
29 }
30
31 - var object = objects[id];
31 + const object = objects[id];
32 if (!object) {
33 console.warn('Invalid style with id `' + id + '`. Skipping ...');
34 return emptyObject;
packages/react-native-renderer/src/ReactNativeTagHandles.js
+3 -3
@@ -22,8 +22,8 @@ import invariant from 'fbjs/lib/invariant';
22 * Why: Because `dangerouslyReplaceNodeWithMarkupByID` relies on being able to
23 * unmount a component with a `rootNodeID`, then mount a new one in its place,
24 */
25 -var INITIAL_TAG_COUNT = 1;
26 -var ReactNativeTagHandles = {
25 +const INITIAL_TAG_COUNT = 1;
26 +const ReactNativeTagHandles = {
27 tagsStartAt: INITIAL_TAG_COUNT,
28 tagCount: INITIAL_TAG_COUNT,
29
@@ -32,7 +32,7 @@ var ReactNativeTagHandles = {
32 while (this.reactTagIsNativeTopRootID(ReactNativeTagHandles.tagCount)) {
33 ReactNativeTagHandles.tagCount++;
34 }
35 - var tag = ReactNativeTagHandles.tagCount;
35 + const tag = ReactNativeTagHandles.tagCount;
36 ReactNativeTagHandles.tagCount++;
37 return tag;
38 },
packages/react-native-renderer/src/__mocks__/BatchedBridge.js
+1 -1
@@ -7,7 +7,7 @@
7
8 'use strict';
9
10 -var BatchedBridge = {
10 +const BatchedBridge = {
11 registerCallableModule: jest.fn(),
12 };
13
packages/react-native-renderer/src/__mocks__/RCTEventEmitter.js
+1 -1
@@ -7,7 +7,7 @@
7
8 'use strict';
9
10 -var RCTEventEmitter = {
10 +const RCTEventEmitter = {
11 register: jest.fn(),
12 };
13
packages/react-native-renderer/src/__mocks__/RTManager.js
+1 -1
@@ -9,7 +9,7 @@
9
10 // Mock of the Native Hooks
11
12 -var RCTRTManager = {
12 +const RCTRTManager = {
13 createNode: jest.fn(function createView(tag, classType, props) {}),
14 beginUpdates: jest.fn(function beginUpdates() {}),
15 appendChildToContext: jest.fn(function appendChildToContext(
packages/react-native-renderer/src/__mocks__/TextInputState.js
+1 -1
@@ -10,6 +10,6 @@
10 // Mock of the Native Hooks
11 // TODO: Should this move into the components themselves? E.g. focusable
12
13 -var TextInputState = {};
13 +const TextInputState = {};
14
15 module.exports = TextInputState;
packages/react-native-renderer/src/__mocks__/UIManager.js
+1 -1
@@ -57,7 +57,7 @@ function removeChild(parent, child) {
57 childInfo.parent = null;
58 }
59
60 -var RCTUIManager = {
60 +const RCTUIManager = {
61 __dumpHierarchyForJestTestsOnly: function() {
62 return roots.map(tag => dumpSubtree(tag, 0)).join('\n');
63
packages/react-native-renderer/src/__mocks__/View.js
+2 -2
@@ -7,10 +7,10 @@
7
8 'use strict';
9
10 -var createReactNativeComponentClass = require('../createReactNativeComponentClass')
10 +const createReactNativeComponentClass = require('../createReactNativeComponentClass')
11 .default;
12
13 -var View = createReactNativeComponentClass({
13 +const View = createReactNativeComponentClass({
14 validAttributes: {},
15 uiViewClassName: 'View',
16 });
packages/react-native-renderer/src/__mocks__/deepDiffer.js
+5 -5
@@ -9,7 +9,7 @@
9
10 // TODO: Move deepDiffer into react
11
12 -var deepDiffer = function(one: any, two: any): boolean {
12 +const deepDiffer = function(one: any, two: any): boolean {
13 if (one === two) {
14 // Short circuit on identical object references instead of traversing them.
15 return false;
@@ -32,22 +32,22 @@ var deepDiffer = function(one: any, two: any): boolean {
32 }
33 if (Array.isArray(one)) {
34 // We know two is also an array because the constructors are equal
35 - var len = one.length;
35 + const len = one.length;
36 if (two.length !== len) {
37 return true;
38 }
39 - for (var ii = 0; ii < len; ii++) {
39 + for (let ii = 0; ii < len; ii++) {
40 if (deepDiffer(one[ii], two[ii])) {
41 return true;
42 }
43 }
44 } else {
45 - for (var key in one) {
45 + for (const key in one) {
46 if (deepDiffer(one[key], two[key])) {
47 return true;
48 }
49 }
50 - for (var twoKey in two) {
50 + for (const twoKey in two) {
51 // The only case we haven't checked yet is keys that are in two but aren't
52 // in one, which means they are different.
53 if (one[twoKey] === undefined && two[twoKey] !== undefined) {
packages/react-native-renderer/src/__mocks__/deepFreezeAndThrowOnMutationInDev.js
+1 -1
@@ -9,6 +9,6 @@
9
10 // TODO: move into react or fbjs
11
12 -var deepFreezeAndThrowOnMutationInDev = function() {};
12 +const deepFreezeAndThrowOnMutationInDev = function() {};
13
14 module.exports = deepFreezeAndThrowOnMutationInDev;
packages/react-native-renderer/src/__mocks__/flattenStyle.js
+1 -1
@@ -9,6 +9,6 @@
9
10 // TODO: Move flattenStyle into react
11
12 -var flattenStyle = function() {};
12 +const flattenStyle = function() {};
13
14 module.exports = flattenStyle;
packages/react-native-renderer/src/__tests__/ReactNativeAttributePayload-test.js
+13 -13
@@ -7,10 +7,10 @@
7 */
8 'use strict';
9
10 -var ReactNativeAttributePayload = require('../ReactNativeAttributePayload');
11 -var ReactNativePropRegistry = require('../ReactNativePropRegistry').default;
10 +const ReactNativeAttributePayload = require('../ReactNativeAttributePayload');
11 +const ReactNativePropRegistry = require('../ReactNativePropRegistry').default;
12
13 -var diff = ReactNativeAttributePayload.diff;
13 +const diff = ReactNativeAttributePayload.diff;
14
15 describe('ReactNativeAttributePayload', () => {
16 it('should work with simple example', () => {
@@ -43,8 +43,8 @@ describe('ReactNativeAttributePayload', () => {
43 });
44
45 it('should use the diff attribute', () => {
46 - var diffA = jest.fn((a, b) => true);
47 - var diffB = jest.fn((a, b) => false);
46 + const diffA = jest.fn((a, b) => true);
47 + const diffB = jest.fn((a, b) => false);
48 expect(
49 diff(
50 {a: [1], b: [3]},
@@ -57,8 +57,8 @@ describe('ReactNativeAttributePayload', () => {
57 });
58
59 it('should not use the diff attribute on addition/removal', () => {
60 - var diffA = jest.fn();
61 - var diffB = jest.fn();
60 + const diffA = jest.fn();
61 + const diffB = jest.fn();
62 expect(
63 diff({a: [1]}, {b: [2]}, {a: {diff: diffA}, b: {diff: diffB}}),
64 ).toEqual({a: null, b: [2]});
@@ -103,7 +103,7 @@ describe('ReactNativeAttributePayload', () => {
103 });
104
105 it('should flatten nested styles and predefined styles', () => {
106 - var validStyleAttribute = {someStyle: {foo: true, bar: true}};
106 + const validStyleAttribute = {someStyle: {foo: true, bar: true}};
107
108 expect(
109 diff({}, {someStyle: [{foo: 1}, {bar: 2}]}, validStyleAttribute),
@@ -113,7 +113,7 @@ describe('ReactNativeAttributePayload', () => {
113 diff({someStyle: [{foo: 1}, {bar: 2}]}, {}, validStyleAttribute),
114 ).toEqual({foo: null, bar: null});
115
116 - var barStyle = ReactNativePropRegistry.register({
116 + const barStyle = ReactNativePropRegistry.register({
117 bar: 3,
118 });
119
@@ -127,7 +127,7 @@ describe('ReactNativeAttributePayload', () => {
127 });
128
129 it('should reset a value to a previous if it is removed', () => {
130 - var validStyleAttribute = {someStyle: {foo: true, bar: true}};
130 + const validStyleAttribute = {someStyle: {foo: true, bar: true}};
131
132 expect(
133 diff(
@@ -139,7 +139,7 @@ describe('ReactNativeAttributePayload', () => {
139 });
140
141 it('should not clear removed props if they are still in another slot', () => {
142 - var validStyleAttribute = {someStyle: {foo: true, bar: true}};
142 + const validStyleAttribute = {someStyle: {foo: true, bar: true}};
143
144 expect(
145 diff(
@@ -159,7 +159,7 @@ describe('ReactNativeAttributePayload', () => {
159 });
160
161 it('should clear a prop if a later style is explicit null/undefined', () => {
162 - var validStyleAttribute = {someStyle: {foo: true, bar: true}};
162 + const validStyleAttribute = {someStyle: {foo: true, bar: true}};
163 expect(
164 diff(
165 {someStyle: [{}, {foo: 3, bar: 2}]},
@@ -186,7 +186,7 @@ describe('ReactNativeAttributePayload', () => {
186
187 // Test the same case with object equality because an early bailout doesn't
188 // work in this case.
189 - var fooObj = {foo: 3};
189 + const fooObj = {foo: 3};
190 expect(
191 diff(
192 {someStyle: [{foo: 1}, fooObj]},
packages/react-native-renderer/src/__tests__/ReactNativeEvents-test.internal.js
+25 -25
@@ -9,14 +9,14 @@
9
10 'use strict';
11
12 -var PropTypes;
13 -var RCTEventEmitter;
14 -var React;
15 -var ReactNative;
16 -var ReactNativeBridgeEventPlugin;
17 -var ResponderEventPlugin;
18 -var UIManager;
19 -var createReactNativeComponentClass;
12 +let PropTypes;
13 +let RCTEventEmitter;
14 +let React;
15 +let ReactNative;
16 +let ReactNativeBridgeEventPlugin;
17 +let ResponderEventPlugin;
18 +let UIManager;
19 +let createReactNativeComponentClass;
20
21 // Parallels requireNativeComponent() in that it lazily constructs a view config,
22 // And registers view manager event types with ReactNativeBridgeEventPlugin.
@@ -79,8 +79,8 @@ beforeEach(() => {
79
80 it('fails if unknown/unsupported event types are dispatched', () => {
81 expect(RCTEventEmitter.register.mock.calls.length).toBe(1);
82 - var EventEmitter = RCTEventEmitter.register.mock.calls[0][0];
83 - var View = fakeRequireNativeComponent('View', {});
82 + const EventEmitter = RCTEventEmitter.register.mock.calls[0][0];
83 + const View = fakeRequireNativeComponent('View', {});
84
85 ReactNative.render(<View onUnspecifiedEvent={() => {}} />, 1);
86
@@ -100,10 +100,10 @@ it('fails if unknown/unsupported event types are dispatched', () => {
100
101 it('handles events', () => {
102 expect(RCTEventEmitter.register.mock.calls.length).toBe(1);
103 - var EventEmitter = RCTEventEmitter.register.mock.calls[0][0];
104 - var View = fakeRequireNativeComponent('View', {foo: true});
103 + const EventEmitter = RCTEventEmitter.register.mock.calls[0][0];
104 + const View = fakeRequireNativeComponent('View', {foo: true});
105
106 - var log = [];
106 + const log = [];
107 ReactNative.render(
108 <View
109 foo="outer"
@@ -127,7 +127,7 @@ it('handles events', () => {
127
128 // Don't depend on the order of createView() calls.
129 // Stack creates views outside-in; fiber creates them inside-out.
130 - var innerTag = UIManager.createView.mock.calls.find(
130 + const innerTag = UIManager.createView.mock.calls.find(
131 args => args[3].foo === 'inner',
132 )[0];
133
@@ -156,8 +156,8 @@ it('handles events', () => {
156
157 it('handles events on text nodes', () => {
158 expect(RCTEventEmitter.register.mock.calls.length).toBe(1);
159 - var EventEmitter = RCTEventEmitter.register.mock.calls[0][0];
160 - var Text = fakeRequireNativeComponent('Text', {});
159 + const EventEmitter = RCTEventEmitter.register.mock.calls[0][0];
160 + const Text = fakeRequireNativeComponent('Text', {});
161
162 class ContextHack extends React.Component {
163 static childContextTypes = {isInAParentText: PropTypes.bool};
@@ -169,7 +169,7 @@ it('handles events on text nodes', () => {
169 }
170 }
171
172 - var log = [];
172 + const log = [];
173 ReactNative.render(
174 <ContextHack>
175 <Text>
@@ -196,10 +196,10 @@ it('handles events on text nodes', () => {
196
197 // Don't depend on the order of createView() calls.
198 // Stack creates views outside-in; fiber creates them inside-out.
199 - var innerTagString = UIManager.createView.mock.calls.find(
199 + const innerTagString = UIManager.createView.mock.calls.find(
200 args => args[3] && args[3].text === 'Text Content',
201 )[0];
202 - var innerTagNumber = UIManager.createView.mock.calls.find(
202 + const innerTagNumber = UIManager.createView.mock.calls.find(
203 args => args[3] && args[3].text === '123',
204 )[0];
205
@@ -238,8 +238,8 @@ it('handles events on text nodes', () => {
238 });
239
240 it('handles when a responder is unmounted while a touch sequence is in progress', () => {
241 - var EventEmitter = RCTEventEmitter.register.mock.calls[0][0];
242 - var View = fakeRequireNativeComponent('View', {id: true});
241 + const EventEmitter = RCTEventEmitter.register.mock.calls[0][0];
242 + const View = fakeRequireNativeComponent('View', {id: true});
243
244 function getViewById(id) {
245 return UIManager.createView.mock.calls.find(
@@ -256,7 +256,7 @@ it('handles when a responder is unmounted while a touch sequence is in progress'
256 return props ? props.id : null;
257 }
258
259 - var log = [];
259 + const log = [];
260 ReactNative.render(
261 <View id="parent">
262 <View key={1}>
@@ -327,9 +327,9 @@ it('handles when a responder is unmounted while a touch sequence is in progress'
327 });
328
329 it('handles events without target', () => {
330 - var EventEmitter = RCTEventEmitter.register.mock.calls[0][0];
330 + const EventEmitter = RCTEventEmitter.register.mock.calls[0][0];
331
332 - var View = fakeRequireNativeComponent('View', {id: true});
332 + const View = fakeRequireNativeComponent('View', {id: true});
333
334 function getViewById(id) {
335 return UIManager.createView.mock.calls.find(
@@ -346,7 +346,7 @@ it('handles events without target', () => {
346 return props ? props.id : null;
347 }
348
349 - var log = [];
349 + const log = [];
350
351 function render(renderFirstComponent) {
352 ReactNative.render(
packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js
+15 -15
@@ -9,10 +9,10 @@
9
10 'use strict';
11
12 -var React;
13 -var ReactNative;
14 -var createReactNativeComponentClass;
15 -var UIManager;
12 +let React;
13 +let ReactNative;
14 +let createReactNativeComponentClass;
15 +let UIManager;
16
17 describe('ReactNative', () => {
18 beforeEach(() => {
@@ -26,7 +26,7 @@ describe('ReactNative', () => {
26 });
27
28 it('should be able to create and render a native component', () => {
29 - var View = createReactNativeComponentClass('View', () => ({
29 + const View = createReactNativeComponentClass('View', () => ({
30 validAttributes: {foo: true},
31 uiViewClassName: 'View',
32 }));
@@ -39,7 +39,7 @@ describe('ReactNative', () => {
39 });
40
41 it('should be able to create and update a native component', () => {
42 - var View = createReactNativeComponentClass('View', () => ({
42 + const View = createReactNativeComponentClass('View', () => ({
43 validAttributes: {foo: true},
44 uiViewClassName: 'View',
45 }));
@@ -121,14 +121,14 @@ describe('ReactNative', () => {
121 });
122
123 it('returns the correct instance and calls it in the callback', () => {
124 - var View = createReactNativeComponentClass('View', () => ({
124 + const View = createReactNativeComponentClass('View', () => ({
125 validAttributes: {foo: true},
126 uiViewClassName: 'View',
127 }));
128
129 - var a;
130 - var b;
131 - var c = ReactNative.render(
129 + let a;
130 + let b;
131 + const c = ReactNative.render(
132 <View foo="foo" ref={v => (a = v)} />,
133 11,
134 function() {
@@ -142,14 +142,14 @@ describe('ReactNative', () => {
142 });
143
144 it('renders and reorders children', () => {
145 - var View = createReactNativeComponentClass('View', () => ({
145 + const View = createReactNativeComponentClass('View', () => ({
146 validAttributes: {title: true},
147 uiViewClassName: 'View',
148 }));
149
150 class Component extends React.Component {
151 render() {
152 - var chars = this.props.chars.split('');
152 + const chars = this.props.chars.split('');
153 return (
154 <View>{chars.map(text => <View key={text} title={text} />)}</View>
155 );
@@ -157,8 +157,8 @@ describe('ReactNative', () => {
157 }
158
159 // Mini multi-child stress test: lots of reorders, some adds, some removes.
160 - var before = 'abcdefghijklmnopqrst';
161 - var after = 'mxhpgwfralkeoivcstzy';
160 + const before = 'abcdefghijklmnopqrst';
161 + const after = 'mxhpgwfralkeoivcstzy';
162
163 ReactNative.render(<Component chars={before} />, 11);
164 expect(UIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
@@ -168,7 +168,7 @@ describe('ReactNative', () => {
168 });
169
170 it('calls setState with no arguments', () => {
171 - var mockArgs;
171 + let mockArgs;
172 class Component extends React.Component {
173 componentDidMount() {
174 this.setState({}, (...args) => (mockArgs = args));
packages/react-native-renderer/src/findNodeHandle.js
+3 -3
@@ -52,7 +52,7 @@ import ReactNativeFiberRenderer from './ReactNativeFiberRenderer';
52 // accidentally deep-requiring this version.
53 function findNodeHandle(componentOrHandle: any): any {
54 if (__DEV__) {
55 - var owner = ReactCurrentOwner.current;
55 + const owner = ReactCurrentOwner.current;
56 if (owner !== null && owner.stateNode !== null) {
57 warning(
58 owner.stateNode._warnedAboutRefsInRender,
@@ -75,11 +75,11 @@ function findNodeHandle(componentOrHandle: any): any {
75 return componentOrHandle;
76 }
77
78 - var component = componentOrHandle;
78 + const component = componentOrHandle;
79
80 // TODO (balpert): Wrap iOS native components in a composite wrapper, then
81 // ReactInstanceMap.get here will always succeed for mounted components
82 - var internalInstance: Fiber = ReactInstanceMap.get(component);
82 + const internalInstance: Fiber = ReactInstanceMap.get(component);
83 if (internalInstance) {
84 return ReactNativeFiberRenderer.findHostInstance(internalInstance);
85 } else {