@samitouri / QOS-React / commits / 6c1fba539a

shared: convert vars into let/const (#11730)

Raphael Amorim committed Nov 30, 2017 at 22:03 UTC 6c1fba539adbc3088c425a4d832bb8c4132e7b31
9 files changed +45 -45
packages/shared/ReactDOMFrameScheduling.js
+13 -13
@@ -74,20 +74,20 @@ if (!ExecutionEnvironment.canUseDOM) {
74 ) {
75 // Polyfill requestIdleCallback and cancelIdleCallback
76
77 - var scheduledRICCallback = null;
78 - var isIdleScheduled = false;
79 - var timeoutTime = -1;
77 + let scheduledRICCallback = null;
78 + let isIdleScheduled = false;
79 + let timeoutTime = -1;
80
81 - var isAnimationFrameScheduled = false;
81 + let isAnimationFrameScheduled = false;
82
83 - var frameDeadline = 0;
83 + let frameDeadline = 0;
84 // We start out assuming that we run at 30fps but then the heuristic tracking
85 // will adjust this value to a faster fps if we get more frequent animation
86 // frames.
87 - var previousFrameTime = 33;
88 - var activeFrameTime = 33;
87 + let previousFrameTime = 33;
88 + let activeFrameTime = 33;
89
90 - var frameDeadlineObject;
90 + let frameDeadlineObject;
91 if (hasNativePerformanceNow) {
92 frameDeadlineObject = {
93 didTimeout: false,
@@ -110,12 +110,12 @@ if (!ExecutionEnvironment.canUseDOM) {
110 }
111
112 // We use the postMessage trick to defer idle work until after the repaint.
113 - var messageKey =
113 + const messageKey =
114 '__reactIdleCallback$' +
115 Math.random()
116 .toString(36)
117 .slice(2);
118 - var idleTick = function(event) {
118 + const idleTick = function(event) {
119 if (event.source !== window || event.data !== messageKey) {
120 return;
121 }
@@ -146,7 +146,7 @@ if (!ExecutionEnvironment.canUseDOM) {
146 }
147
148 timeoutTime = -1;
149 - var callback = scheduledRICCallback;
149 + const callback = scheduledRICCallback;
150 scheduledRICCallback = null;
151 if (callback !== null) {
152 callback(frameDeadlineObject);
@@ -156,9 +156,9 @@ if (!ExecutionEnvironment.canUseDOM) {
156 // something better for old IE.
157 window.addEventListener('message', idleTick, false);
158
159 - var animationTick = function(rafTime) {
159 + const animationTick = function(rafTime) {
160 isAnimationFrameScheduled = false;
161 - var nextFrameTime = rafTime - frameDeadline + activeFrameTime;
161 + let nextFrameTime = rafTime - frameDeadline + activeFrameTime;
162 if (
163 nextFrameTime < activeFrameTime &&
164 previousFrameTime < activeFrameTime
packages/shared/ReactFiberComponentTreeHook.js
+6 -6
@@ -24,10 +24,10 @@ function describeFiber(fiber: Fiber): string {
24 case FunctionalComponent:
25 case ClassComponent:
26 case HostComponent:
27 - var owner = fiber._debugOwner;
28 - var source = fiber._debugSource;
29 - var name = getComponentName(fiber);
30 - var ownerName = null;
27 + const owner = fiber._debugOwner;
28 + const source = fiber._debugSource;
29 + const name = getComponentName(fiber);
30 + let ownerName = null;
31 if (owner) {
32 ownerName = getComponentName(owner);
33 }
@@ -43,8 +43,8 @@ function describeFiber(fiber: Fiber): string {
43 export function getStackAddendumByWorkInProgressFiber(
44 workInProgress: Fiber,
45 ): string {
46 - var info = '';
47 - var node = workInProgress;
46 + let info = '';
47 + let node = workInProgress;
48 do {
49 info += describeFiber(node);
50 // Otherwise this return pointer might point to the wrong tree:
packages/shared/ReactGlobalSharedState.js
+1 -1
@@ -7,7 +7,7 @@
7
8 import React from 'react';
9
10 -var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
10 +const ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
11
12 export const ReactCurrentOwner = ReactInternals.ReactCurrentOwner;
13 export const ReactDebugCurrentFrame = __DEV__
packages/shared/ReactTreeTraversal.js
+7 -7
@@ -27,12 +27,12 @@ function getParent(inst) {
27 * different trees.
28 */
29 export function getLowestCommonAncestor(instA, instB) {
30 - var depthA = 0;
31 - for (var tempA = instA; tempA; tempA = getParent(tempA)) {
30 + let depthA = 0;
31 + for (let tempA = instA; tempA; tempA = getParent(tempA)) {
32 depthA++;
33 }
34 - var depthB = 0;
35 - for (var tempB = instB; tempB; tempB = getParent(tempB)) {
34 + let depthB = 0;
35 + for (let tempB = instB; tempB; tempB = getParent(tempB)) {
36 depthB++;
37 }
38
@@ -49,7 +49,7 @@ export function getLowestCommonAncestor(instA, instB) {
49 }
50
51 // Walk in lockstep until we find a match.
52 - var depth = depthA;
52 + let depth = depthA;
53 while (depth--) {
54 if (instA === instB || instA === instB.alternate) {
55 return instA;
@@ -84,12 +84,12 @@ export function getParentInstance(inst) {
84 * Simulates the traversal of a two-phase, capture/bubble event dispatch.
85 */
86 export function traverseTwoPhase(inst, fn, arg) {
87 - var path = [];
87 + const path = [];
88 while (inst) {
89 path.push(inst);
90 inst = getParent(inst);
91 }
92 - var i;
92 + let i;
93 for (i = path.length; i-- > 0; ) {
94 fn(path[i], 'captured', arg);
95 }
packages/shared/__tests__/ReactErrorUtils-test.internal.js
+8 -8
@@ -9,7 +9,7 @@
9
10 'use strict';
11
12 -var ReactErrorUtils;
12 +let ReactErrorUtils;
13
14 describe('ReactErrorUtils', () => {
15 beforeEach(() => {
@@ -18,8 +18,8 @@ describe('ReactErrorUtils', () => {
18 });
19
20 it(`it should rethrow caught errors`, () => {
21 - var err = new Error('foo');
22 - var callback = function() {
21 + const err = new Error('foo');
22 + const callback = function() {
23 throw err;
24 };
25 ReactErrorUtils.invokeGuardedCallbackAndCatchFirstError(
@@ -32,7 +32,7 @@ describe('ReactErrorUtils', () => {
32 });
33
34 it(`should call the callback the passed arguments`, () => {
35 - var callback = jest.fn();
35 + const callback = jest.fn();
36 ReactErrorUtils.invokeGuardedCallback(
37 'foo',
38 callback,
@@ -44,7 +44,7 @@ describe('ReactErrorUtils', () => {
44 });
45
46 it(`should call the callback with the provided context`, () => {
47 - var context = {didCall: false};
47 + const context = {didCall: false};
48 ReactErrorUtils.invokeGuardedCallback(
49 'foo',
50 function() {
@@ -72,7 +72,7 @@ describe('ReactErrorUtils', () => {
72 });
73
74 it(`should return false from clearCaughtError if no error was thrown`, () => {
75 - var callback = jest.fn();
75 + const callback = jest.fn();
76 ReactErrorUtils.invokeGuardedCallback('foo', callback, null);
77 expect(ReactErrorUtils.hasCaughtError()).toBe(false);
78 expect(ReactErrorUtils.clearCaughtError).toThrow('no error was captured');
@@ -193,8 +193,8 @@ describe('ReactErrorUtils', () => {
193 ReactErrorUtils = require('shared/ReactErrorUtils').default;
194
195 try {
196 - var err = new Error('foo');
197 - var callback = function() {
196 + const err = new Error('foo');
197 + const callback = function() {
198 throw err;
199 };
200 ReactErrorUtils.invokeGuardedCallbackAndCatchFirstError(
packages/shared/__tests__/reactProdInvariant-test.internal.js
+1 -1
@@ -8,7 +8,7 @@
8 */
9 'use strict';
10
11 -var reactProdInvariant;
11 +let reactProdInvariant;
12
13 describe('reactProdInvariant', () => {
14 let globalErrorMock;
packages/shared/isTextInputElement.js
+2 -2
@@ -10,7 +10,7 @@
10 /**
11 * @see http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html#input-type-attr-summary
12 */
13 -var supportedInputTypes: {[key: string]: true | void} = {
13 +const supportedInputTypes: {[key: string]: true | void} = {
14 color: true,
15 date: true,
16 datetime: true,
@@ -29,7 +29,7 @@ var supportedInputTypes: {[key: string]: true | void} = {
29 };
30
31 function isTextInputElement(elem: ?HTMLElement): boolean {
32 - var nodeName = elem && elem.nodeName && elem.nodeName.toLowerCase();
32 + const nodeName = elem && elem.nodeName && elem.nodeName.toLowerCase();
33
34 if (nodeName === 'input') {
35 return !!supportedInputTypes[((elem: any): HTMLInputElement).type];
packages/shared/lowPriorityWarning.js
+3 -3
@@ -19,12 +19,12 @@
19 * same logic and follow the same code paths.
20 */
21
22 -var lowPriorityWarning = function() {};
22 +let lowPriorityWarning = function() {};
23
24 if (__DEV__) {
25 const printWarning = function(format, ...args) {
26 - var argIndex = 0;
27 - var message = 'Warning: ' + format.replace(/%s/g, () => args[argIndex++]);
26 + let argIndex = 0;
27 + const message = 'Warning: ' + format.replace(/%s/g, () => args[argIndex++]);
28 if (typeof console !== 'undefined') {
29 console.warn(message);
30 }
packages/shared/reactProdInvariant.js
+4 -4
@@ -14,16 +14,16 @@
14 * It always throws.
15 */
16 function reactProdInvariant(code: string): void {
17 - var argCount = arguments.length - 1;
17 + const argCount = arguments.length - 1;
18
19 - var message =
19 + let message =
20 'Minified React error #' +
21 code +
22 '; visit ' +
23 'http://facebook.github.io/react/docs/error-decoder.html?invariant=' +
24 code;
25
26 - for (var argIdx = 0; argIdx < argCount; argIdx++) {
26 + for (let argIdx = 0; argIdx < argCount; argIdx++) {
27 message += '&args[]=' + encodeURIComponent(arguments[argIdx + 1]);
28 }
29
@@ -31,7 +31,7 @@ function reactProdInvariant(code: string): void {
31 ' for the full message or use the non-minified dev environment' +
32 ' for full errors and additional helpful warnings.';
33
34 - var error: Error & {framesToPop?: number} = new Error(message);
34 + const error: Error & {framesToPop?: number} = new Error(message);
35 error.name = 'Invariant Violation';
36 error.framesToPop = 1; // we don't care about reactProdInvariant's own frame
37