mirror of
https://github.com/hanzoai/react.git
synced 2026-09-24 17:02:27 +00:00
shared: convert vars into let/const (#11730)
This commit is contained in:
committed by
Dan Abramov
parent
f102556640
commit
dc1ff96410
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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__
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var reactProdInvariant;
|
||||
let reactProdInvariant;
|
||||
|
||||
describe('reactProdInvariant', () => {
|
||||
let globalErrorMock;
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user