diff --git a/packages/shared/ReactDOMFrameScheduling.js b/packages/shared/ReactDOMFrameScheduling.js index f50e0ed204c7..78041064678e 100644 --- a/packages/shared/ReactDOMFrameScheduling.js +++ b/packages/shared/ReactDOMFrameScheduling.js @@ -74,20 +74,20 @@ if (!ExecutionEnvironment.canUseDOM) { ) { // Polyfill requestIdleCallback and cancelIdleCallback - var scheduledRICCallback = null; - var isIdleScheduled = false; - var timeoutTime = -1; + let scheduledRICCallback = null; + let isIdleScheduled = false; + let timeoutTime = -1; - var isAnimationFrameScheduled = false; + let isAnimationFrameScheduled = false; - var frameDeadline = 0; + let frameDeadline = 0; // We start out assuming that we run at 30fps but then the heuristic tracking // will adjust this value to a faster fps if we get more frequent animation // frames. - var previousFrameTime = 33; - var activeFrameTime = 33; + let previousFrameTime = 33; + let activeFrameTime = 33; - var frameDeadlineObject; + let frameDeadlineObject; if (hasNativePerformanceNow) { frameDeadlineObject = { didTimeout: false, @@ -110,12 +110,12 @@ if (!ExecutionEnvironment.canUseDOM) { } // We use the postMessage trick to defer idle work until after the repaint. - var messageKey = + const messageKey = '__reactIdleCallback$' + Math.random() .toString(36) .slice(2); - var idleTick = function(event) { + const idleTick = function(event) { if (event.source !== window || event.data !== messageKey) { return; } @@ -146,7 +146,7 @@ if (!ExecutionEnvironment.canUseDOM) { } timeoutTime = -1; - var callback = scheduledRICCallback; + const callback = scheduledRICCallback; scheduledRICCallback = null; if (callback !== null) { callback(frameDeadlineObject); @@ -156,9 +156,9 @@ if (!ExecutionEnvironment.canUseDOM) { // something better for old IE. window.addEventListener('message', idleTick, false); - var animationTick = function(rafTime) { + const animationTick = function(rafTime) { isAnimationFrameScheduled = false; - var nextFrameTime = rafTime - frameDeadline + activeFrameTime; + let nextFrameTime = rafTime - frameDeadline + activeFrameTime; if ( nextFrameTime < activeFrameTime && previousFrameTime < activeFrameTime diff --git a/packages/shared/ReactFiberComponentTreeHook.js b/packages/shared/ReactFiberComponentTreeHook.js index ff0648e8a145..8926ce342686 100644 --- a/packages/shared/ReactFiberComponentTreeHook.js +++ b/packages/shared/ReactFiberComponentTreeHook.js @@ -24,10 +24,10 @@ function describeFiber(fiber: Fiber): string { case FunctionalComponent: case ClassComponent: case HostComponent: - var owner = fiber._debugOwner; - var source = fiber._debugSource; - var name = getComponentName(fiber); - var ownerName = null; + const owner = fiber._debugOwner; + const source = fiber._debugSource; + const name = getComponentName(fiber); + let ownerName = null; if (owner) { ownerName = getComponentName(owner); } @@ -43,8 +43,8 @@ function describeFiber(fiber: Fiber): string { export function getStackAddendumByWorkInProgressFiber( workInProgress: Fiber, ): string { - var info = ''; - var node = workInProgress; + let info = ''; + let node = workInProgress; do { info += describeFiber(node); // Otherwise this return pointer might point to the wrong tree: diff --git a/packages/shared/ReactGlobalSharedState.js b/packages/shared/ReactGlobalSharedState.js index 72213c141b8f..b911e90801ed 100644 --- a/packages/shared/ReactGlobalSharedState.js +++ b/packages/shared/ReactGlobalSharedState.js @@ -7,7 +7,7 @@ import React from 'react'; -var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; +const ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; export const ReactCurrentOwner = ReactInternals.ReactCurrentOwner; export const ReactDebugCurrentFrame = __DEV__ diff --git a/packages/shared/ReactTreeTraversal.js b/packages/shared/ReactTreeTraversal.js index e86ea1120939..7db43fdf2fc2 100644 --- a/packages/shared/ReactTreeTraversal.js +++ b/packages/shared/ReactTreeTraversal.js @@ -27,12 +27,12 @@ function getParent(inst) { * different trees. */ export function getLowestCommonAncestor(instA, instB) { - var depthA = 0; - for (var tempA = instA; tempA; tempA = getParent(tempA)) { + let depthA = 0; + for (let tempA = instA; tempA; tempA = getParent(tempA)) { depthA++; } - var depthB = 0; - for (var tempB = instB; tempB; tempB = getParent(tempB)) { + let depthB = 0; + for (let tempB = instB; tempB; tempB = getParent(tempB)) { depthB++; } @@ -49,7 +49,7 @@ export function getLowestCommonAncestor(instA, instB) { } // Walk in lockstep until we find a match. - var depth = depthA; + let depth = depthA; while (depth--) { if (instA === instB || instA === instB.alternate) { return instA; @@ -84,12 +84,12 @@ export function getParentInstance(inst) { * Simulates the traversal of a two-phase, capture/bubble event dispatch. */ export function traverseTwoPhase(inst, fn, arg) { - var path = []; + const path = []; while (inst) { path.push(inst); inst = getParent(inst); } - var i; + let i; for (i = path.length; i-- > 0; ) { fn(path[i], 'captured', arg); } diff --git a/packages/shared/__tests__/ReactErrorUtils-test.internal.js b/packages/shared/__tests__/ReactErrorUtils-test.internal.js index 9a064e4312af..b0a6b5813758 100644 --- a/packages/shared/__tests__/ReactErrorUtils-test.internal.js +++ b/packages/shared/__tests__/ReactErrorUtils-test.internal.js @@ -9,7 +9,7 @@ 'use strict'; -var ReactErrorUtils; +let ReactErrorUtils; describe('ReactErrorUtils', () => { beforeEach(() => { @@ -18,8 +18,8 @@ describe('ReactErrorUtils', () => { }); it(`it should rethrow caught errors`, () => { - var err = new Error('foo'); - var callback = function() { + const err = new Error('foo'); + const callback = function() { throw err; }; ReactErrorUtils.invokeGuardedCallbackAndCatchFirstError( @@ -32,7 +32,7 @@ describe('ReactErrorUtils', () => { }); it(`should call the callback the passed arguments`, () => { - var callback = jest.fn(); + const callback = jest.fn(); ReactErrorUtils.invokeGuardedCallback( 'foo', callback, @@ -44,7 +44,7 @@ describe('ReactErrorUtils', () => { }); it(`should call the callback with the provided context`, () => { - var context = {didCall: false}; + const context = {didCall: false}; ReactErrorUtils.invokeGuardedCallback( 'foo', function() { @@ -72,7 +72,7 @@ describe('ReactErrorUtils', () => { }); it(`should return false from clearCaughtError if no error was thrown`, () => { - var callback = jest.fn(); + const callback = jest.fn(); ReactErrorUtils.invokeGuardedCallback('foo', callback, null); expect(ReactErrorUtils.hasCaughtError()).toBe(false); expect(ReactErrorUtils.clearCaughtError).toThrow('no error was captured'); @@ -193,8 +193,8 @@ describe('ReactErrorUtils', () => { ReactErrorUtils = require('shared/ReactErrorUtils').default; try { - var err = new Error('foo'); - var callback = function() { + const err = new Error('foo'); + const callback = function() { throw err; }; ReactErrorUtils.invokeGuardedCallbackAndCatchFirstError( diff --git a/packages/shared/__tests__/reactProdInvariant-test.internal.js b/packages/shared/__tests__/reactProdInvariant-test.internal.js index 8c8ce0bcd04b..2263241a503a 100644 --- a/packages/shared/__tests__/reactProdInvariant-test.internal.js +++ b/packages/shared/__tests__/reactProdInvariant-test.internal.js @@ -8,7 +8,7 @@ */ 'use strict'; -var reactProdInvariant; +let reactProdInvariant; describe('reactProdInvariant', () => { let globalErrorMock; diff --git a/packages/shared/isTextInputElement.js b/packages/shared/isTextInputElement.js index 3921bcc052c9..2671c3e3dde2 100644 --- a/packages/shared/isTextInputElement.js +++ b/packages/shared/isTextInputElement.js @@ -10,7 +10,7 @@ /** * @see http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html#input-type-attr-summary */ -var supportedInputTypes: {[key: string]: true | void} = { +const supportedInputTypes: {[key: string]: true | void} = { color: true, date: true, datetime: true, @@ -29,7 +29,7 @@ var supportedInputTypes: {[key: string]: true | void} = { }; function isTextInputElement(elem: ?HTMLElement): boolean { - var nodeName = elem && elem.nodeName && elem.nodeName.toLowerCase(); + const nodeName = elem && elem.nodeName && elem.nodeName.toLowerCase(); if (nodeName === 'input') { return !!supportedInputTypes[((elem: any): HTMLInputElement).type]; diff --git a/packages/shared/lowPriorityWarning.js b/packages/shared/lowPriorityWarning.js index cfc1ef7cae9c..ba2e7ee98715 100644 --- a/packages/shared/lowPriorityWarning.js +++ b/packages/shared/lowPriorityWarning.js @@ -19,12 +19,12 @@ * same logic and follow the same code paths. */ -var lowPriorityWarning = function() {}; +let lowPriorityWarning = function() {}; if (__DEV__) { const printWarning = function(format, ...args) { - var argIndex = 0; - var message = 'Warning: ' + format.replace(/%s/g, () => args[argIndex++]); + let argIndex = 0; + const message = 'Warning: ' + format.replace(/%s/g, () => args[argIndex++]); if (typeof console !== 'undefined') { console.warn(message); } diff --git a/packages/shared/reactProdInvariant.js b/packages/shared/reactProdInvariant.js index e9d63051fccf..56adc77d94f6 100644 --- a/packages/shared/reactProdInvariant.js +++ b/packages/shared/reactProdInvariant.js @@ -14,16 +14,16 @@ * It always throws. */ function reactProdInvariant(code: string): void { - var argCount = arguments.length - 1; + const argCount = arguments.length - 1; - var message = + let message = 'Minified React error #' + code + '; visit ' + 'http://facebook.github.io/react/docs/error-decoder.html?invariant=' + code; - for (var argIdx = 0; argIdx < argCount; argIdx++) { + for (let argIdx = 0; argIdx < argCount; argIdx++) { message += '&args[]=' + encodeURIComponent(arguments[argIdx + 1]); } @@ -31,7 +31,7 @@ function reactProdInvariant(code: string): void { ' for the full message or use the non-minified dev environment' + ' for full errors and additional helpful warnings.'; - var error: Error & {framesToPop?: number} = new Error(message); + const error: Error & {framesToPop?: number} = new Error(message); error.name = 'Invariant Violation'; error.framesToPop = 1; // we don't care about reactProdInvariant's own frame