Skip to content

Commit 5bd2321

Browse files
raphamorimgaearon
authored andcommitted
Remove vars (#11780)
* react-dom: convert packages/react-dom/src/client * react-dom: convert packages/react-dom/src/events * react-dom: convert packages/react-dom/src/test-utils * react-dom: convert files on root * react-dom: convert updated ReactDOM-test.js
1 parent 3145639 commit 5bd2321

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+563
-536
lines changed

packages/react-dom/index.fb.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
'use strict';
99

10-
var ReactDOMFB = require('./src/client/ReactDOMFB');
10+
const ReactDOMFB = require('./src/client/ReactDOMFB');
1111

1212
// TODO: decide on the top-level export form.
1313
// This is hacky but makes it work with both Rollup and Jest.

packages/react-dom/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
'use strict';
1111

12-
var ReactDOM = require('./src/client/ReactDOM');
12+
const ReactDOM = require('./src/client/ReactDOM');
1313

1414
// TODO: decide on the top-level export form.
1515
// This is hacky but makes it work with both Rollup and Jest.

packages/react-dom/server.browser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
'use strict';
1111

12-
var ReactDOMServer = require('./src/server/ReactDOMServerBrowser');
12+
const ReactDOMServer = require('./src/server/ReactDOMServerBrowser');
1313

1414
// TODO: decide on the top-level export form.
1515
// This is hacky but makes it work with both Rollup and Jest

packages/react-dom/server.node.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
'use strict';
1111

12-
var ReactDOMServer = require('./src/server/ReactDOMServerNode');
12+
const ReactDOMServer = require('./src/server/ReactDOMServerNode');
1313

1414
// TODO: decide on the top-level export form.
1515
// This is hacky but makes it work with both Rollup and Jest

packages/react-dom/src/__tests__/ReactDOM-test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ describe('ReactDOM', () => {
1818
// supports real submit events.
1919
/*
2020
it('should bubble onSubmit', function() {
21-
var count = 0;
22-
var form;
23-
var Parent = React.createClass({
21+
const count = 0;
22+
const form;
23+
const Parent = React.createClass({
2424
handleSubmit: function() {
2525
count++;
2626
return false;
@@ -29,15 +29,15 @@ describe('ReactDOM', () => {
2929
return <Child />;
3030
}
3131
});
32-
var Child = React.createClass({
32+
const Child = React.createClass({
3333
render: function() {
3434
return <form><input type="submit" value="Submit" /></form>;
3535
},
3636
componentDidMount: function() {
3737
form = ReactDOM.findDOMNode(this);
3838
}
3939
});
40-
var instance = ReactTestUtils.renderIntoDocument(<Parent />);
40+
const instance = ReactTestUtils.renderIntoDocument(<Parent />);
4141
form.submit();
4242
expect(count).toEqual(1);
4343
});

packages/react-dom/src/__tests__/ReactDOMInput-test.js

+24-24
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ describe('ReactDOMInput', () => {
258258
}
259259
}
260260

261-
var stub = ReactTestUtils.renderIntoDocument(<Stub />);
262-
var node = ReactDOM.findDOMNode(stub);
261+
const stub = ReactTestUtils.renderIntoDocument(<Stub />);
262+
const node = ReactDOM.findDOMNode(stub);
263263
stub.setState({value: 0});
264264

265265
expect(node.value).toEqual('0');
@@ -628,36 +628,36 @@ describe('ReactDOMInput', () => {
628628
});
629629

630630
it('should properly transition a text input from 0 to an empty 0.0', function() {
631-
var container = document.createElement('div');
631+
const container = document.createElement('div');
632632

633633
ReactDOM.render(<input type="text" value={0} />, container);
634634
ReactDOM.render(<input type="text" value="0.0" />, container);
635635

636-
var node = container.firstChild;
636+
const node = container.firstChild;
637637

638638
expect(node.value).toBe('0.0');
639639
expect(node.defaultValue).toBe('0.0');
640640
});
641641

642642
it('should properly transition a number input from "" to 0', function() {
643-
var container = document.createElement('div');
643+
const container = document.createElement('div');
644644

645645
ReactDOM.render(<input type="number" value="" />, container);
646646
ReactDOM.render(<input type="number" value={0} />, container);
647647

648-
var node = container.firstChild;
648+
const node = container.firstChild;
649649

650650
expect(node.value).toBe('0');
651651
expect(node.defaultValue).toBe('0');
652652
});
653653

654654
it('should properly transition a number input from "" to "0"', function() {
655-
var container = document.createElement('div');
655+
const container = document.createElement('div');
656656

657657
ReactDOM.render(<input type="number" value="" />, container);
658658
ReactDOM.render(<input type="number" value="0" />, container);
659659

660-
var node = container.firstChild;
660+
const node = container.firstChild;
661661

662662
expect(node.value).toBe('0');
663663
expect(node.defaultValue).toBe('0');
@@ -1644,12 +1644,12 @@ describe('ReactDOMInput', () => {
16441644
describe('When given a Symbol value', function() {
16451645
it('treats initial Symbol value as an empty string', function() {
16461646
spyOnDev(console, 'error');
1647-
var container = document.createElement('div');
1647+
const container = document.createElement('div');
16481648
ReactDOM.render(
16491649
<input value={Symbol('foobar')} onChange={() => {}} />,
16501650
container,
16511651
);
1652-
var node = container.firstChild;
1652+
const node = container.firstChild;
16531653

16541654
expect(node.value).toBe('');
16551655
expect(node.getAttribute('value')).toBe('');
@@ -1664,13 +1664,13 @@ describe('ReactDOMInput', () => {
16641664

16651665
it('treats updated Symbol value as an empty string', function() {
16661666
spyOnDev(console, 'error');
1667-
var container = document.createElement('div');
1667+
const container = document.createElement('div');
16681668
ReactDOM.render(<input value="foo" onChange={() => {}} />, container);
16691669
ReactDOM.render(
16701670
<input value={Symbol('foobar')} onChange={() => {}} />,
16711671
container,
16721672
);
1673-
var node = container.firstChild;
1673+
const node = container.firstChild;
16741674

16751675
expect(node.value).toBe('');
16761676
expect(node.getAttribute('value')).toBe('');
@@ -1684,20 +1684,20 @@ describe('ReactDOMInput', () => {
16841684
});
16851685

16861686
it('treats initial Symbol defaultValue as an empty string', function() {
1687-
var container = document.createElement('div');
1687+
const container = document.createElement('div');
16881688
ReactDOM.render(<input defaultValue={Symbol('foobar')} />, container);
1689-
var node = container.firstChild;
1689+
const node = container.firstChild;
16901690

16911691
expect(node.value).toBe('');
16921692
expect(node.getAttribute('value')).toBe('');
16931693
// TODO: we should warn here.
16941694
});
16951695

16961696
it('treats updated Symbol defaultValue as an empty string', function() {
1697-
var container = document.createElement('div');
1697+
const container = document.createElement('div');
16981698
ReactDOM.render(<input defaultValue="foo" />, container);
16991699
ReactDOM.render(<input defaultValue={Symbol('foobar')} />, container);
1700-
var node = container.firstChild;
1700+
const node = container.firstChild;
17011701

17021702
expect(node.value).toBe('foo');
17031703
expect(node.getAttribute('value')).toBe('');
@@ -1708,12 +1708,12 @@ describe('ReactDOMInput', () => {
17081708
describe('When given a function value', function() {
17091709
it('treats initial function value as an empty string', function() {
17101710
spyOnDev(console, 'error');
1711-
var container = document.createElement('div');
1711+
const container = document.createElement('div');
17121712
ReactDOM.render(
17131713
<input value={() => {}} onChange={() => {}} />,
17141714
container,
17151715
);
1716-
var node = container.firstChild;
1716+
const node = container.firstChild;
17171717

17181718
expect(node.value).toBe('');
17191719
expect(node.getAttribute('value')).toBe('');
@@ -1728,13 +1728,13 @@ describe('ReactDOMInput', () => {
17281728

17291729
it('treats updated function value as an empty string', function() {
17301730
spyOnDev(console, 'error');
1731-
var container = document.createElement('div');
1731+
const container = document.createElement('div');
17321732
ReactDOM.render(<input value="foo" onChange={() => {}} />, container);
17331733
ReactDOM.render(
17341734
<input value={() => {}} onChange={() => {}} />,
17351735
container,
17361736
);
1737-
var node = container.firstChild;
1737+
const node = container.firstChild;
17381738

17391739
expect(node.value).toBe('');
17401740
expect(node.getAttribute('value')).toBe('');
@@ -1748,20 +1748,20 @@ describe('ReactDOMInput', () => {
17481748
});
17491749

17501750
it('treats initial function defaultValue as an empty string', function() {
1751-
var container = document.createElement('div');
1751+
const container = document.createElement('div');
17521752
ReactDOM.render(<input defaultValue={() => {}} />, container);
1753-
var node = container.firstChild;
1753+
const node = container.firstChild;
17541754

17551755
expect(node.value).toBe('');
17561756
expect(node.getAttribute('value')).toBe('');
17571757
// TODO: we should warn here.
17581758
});
17591759

17601760
it('treats updated function defaultValue as an empty string', function() {
1761-
var container = document.createElement('div');
1761+
const container = document.createElement('div');
17621762
ReactDOM.render(<input defaultValue="foo" />, container);
17631763
ReactDOM.render(<input defaultValue={() => {}} />, container);
1764-
var node = container.firstChild;
1764+
const node = container.firstChild;
17651765

17661766
expect(node.value).toBe('foo');
17671767
expect(node.getAttribute('value')).toBe('');

packages/react-dom/src/client/DOMPropertyOperations.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import warning from 'fbjs/lib/warning';
1717

1818
// isAttributeNameSafe() is currently duplicated in DOMMarkupOperations.
1919
// TODO: Find a better place for this.
20-
var VALID_ATTRIBUTE_NAME_REGEX = new RegExp(
20+
const VALID_ATTRIBUTE_NAME_REGEX = new RegExp(
2121
'^[' + ATTRIBUTE_NAME_START_CHAR + '][' + ATTRIBUTE_NAME_CHAR + ']*$',
2222
);
23-
var illegalAttributeNameCache = {};
24-
var validatedAttributeNameCache = {};
23+
const illegalAttributeNameCache = {};
24+
const validatedAttributeNameCache = {};
2525
function isAttributeNameSafe(attributeName) {
2626
if (validatedAttributeNameCache.hasOwnProperty(attributeName)) {
2727
return true;
@@ -71,18 +71,18 @@ export function setAttributeForRoot(node) {
7171
*/
7272
export function getValueForProperty(node, name, expected) {
7373
if (__DEV__) {
74-
var propertyInfo = getPropertyInfo(name);
74+
const propertyInfo = getPropertyInfo(name);
7575
if (propertyInfo) {
7676
if (propertyInfo.mustUseProperty) {
7777
return node[propertyInfo.propertyName];
7878
} else {
79-
var attributeName = propertyInfo.attributeName;
79+
const attributeName = propertyInfo.attributeName;
8080

81-
var stringValue = null;
81+
let stringValue = null;
8282

8383
if (propertyInfo.hasOverloadedBooleanValue) {
8484
if (node.hasAttribute(attributeName)) {
85-
var value = node.getAttribute(attributeName);
85+
const value = node.getAttribute(attributeName);
8686
if (value === '') {
8787
return true;
8888
}
@@ -137,7 +137,7 @@ export function getValueForAttribute(node, name, expected) {
137137
if (!node.hasAttribute(name)) {
138138
return expected === undefined ? undefined : null;
139139
}
140-
var value = node.getAttribute(name);
140+
const value = node.getAttribute(name);
141141
if (value === '' + expected) {
142142
return expected;
143143
}
@@ -153,7 +153,7 @@ export function getValueForAttribute(node, name, expected) {
153153
* @param {*} value
154154
*/
155155
export function setValueForProperty(node, name, value) {
156-
var propertyInfo = getPropertyInfo(name);
156+
const propertyInfo = getPropertyInfo(name);
157157

158158
if (propertyInfo && shouldSetAttribute(name, value)) {
159159
if (shouldIgnoreValue(propertyInfo, value)) {
@@ -164,8 +164,8 @@ export function setValueForProperty(node, name, value) {
164164
// `toString`ed by IE8/9.
165165
node[propertyInfo.propertyName] = value;
166166
} else {
167-
var attributeName = propertyInfo.attributeName;
168-
var namespace = propertyInfo.attributeNamespace;
167+
const attributeName = propertyInfo.attributeName;
168+
const namespace = propertyInfo.attributeNamespace;
169169
// `setAttribute` with objects becomes only `[object]` in IE8/9,
170170
// ('' + value) makes it output the correct toString()-value.
171171
if (namespace) {
@@ -217,10 +217,10 @@ export function deleteValueForAttribute(node, name) {
217217
* @param {string} name
218218
*/
219219
export function deleteValueForProperty(node, name) {
220-
var propertyInfo = getPropertyInfo(name);
220+
const propertyInfo = getPropertyInfo(name);
221221
if (propertyInfo) {
222222
if (propertyInfo.mustUseProperty) {
223-
var propName = propertyInfo.propertyName;
223+
const propName = propertyInfo.propertyName;
224224
if (propertyInfo.hasBooleanValue) {
225225
node[propName] = false;
226226
} else {

packages/react-dom/src/client/ReactDOM.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,12 @@ const {
7272
const {updatedAncestorInfo} = validateDOMNesting;
7373
const {precacheFiberNode, updateFiberProps} = ReactDOMComponentTree;
7474

75+
let SUPPRESS_HYDRATION_WARNING;
76+
let topLevelUpdateWarnings;
77+
let warnOnInvalidCallback;
78+
7579
if (__DEV__) {
76-
var SUPPRESS_HYDRATION_WARNING = 'suppressHydrationWarning';
80+
SUPPRESS_HYDRATION_WARNING = 'suppressHydrationWarning';
7781
if (
7882
typeof Map !== 'function' ||
7983
Map.prototype == null ||
@@ -90,7 +94,7 @@ if (__DEV__) {
9094
);
9195
}
9296

93-
var topLevelUpdateWarnings = (container: DOMContainer) => {
97+
topLevelUpdateWarnings = (container: DOMContainer) => {
9498
if (__DEV__) {
9599
if (
96100
container._reactRootContainer &&
@@ -137,7 +141,7 @@ if (__DEV__) {
137141
}
138142
};
139143

140-
var warnOnInvalidCallback = function(callback: mixed, callerName: string) {
144+
warnOnInvalidCallback = function(callback: mixed, callerName: string) {
141145
warning(
142146
callback === null || typeof callback === 'function',
143147
'%s(...): Expected the last optional `callback` argument to be a ' +

0 commit comments

Comments
 (0)