Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

shared: convert vars into let/const #11730

Merged
merged 1 commit into from
Dec 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions packages/shared/ReactDOMFrameScheduling.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}
Expand Down Expand Up @@ -146,7 +146,7 @@ if (!ExecutionEnvironment.canUseDOM) {
}

timeoutTime = -1;
var callback = scheduledRICCallback;
const callback = scheduledRICCallback;
scheduledRICCallback = null;
if (callback !== null) {
callback(frameDeadlineObject);
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions packages/shared/ReactFiberComponentTreeHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/ReactGlobalSharedState.js
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down
14 changes: 7 additions & 7 deletions packages/shared/ReactTreeTraversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}

Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
16 changes: 8 additions & 8 deletions packages/shared/__tests__/ReactErrorUtils-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

'use strict';

var ReactErrorUtils;
let ReactErrorUtils;

describe('ReactErrorUtils', () => {
beforeEach(() => {
Expand All @@ -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(
Expand All @@ -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,
Expand All @@ -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() {
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
'use strict';

var reactProdInvariant;
let reactProdInvariant;

describe('reactProdInvariant', () => {
let globalErrorMock;
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/isTextInputElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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];
Expand Down
6 changes: 3 additions & 3 deletions packages/shared/lowPriorityWarning.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions packages/shared/reactProdInvariant.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@
* 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]);
}

message +=
' 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

Expand Down