Skip to content

Commit

Permalink
Remove vars (#11780)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
raphamorim authored and gaearon committed Dec 6, 2017
1 parent 3145639 commit 5bd2321
Show file tree
Hide file tree
Showing 53 changed files with 563 additions and 536 deletions.
2 changes: 1 addition & 1 deletion packages/react-dom/index.fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

'use strict';

var ReactDOMFB = require('./src/client/ReactDOMFB');
const ReactDOMFB = require('./src/client/ReactDOMFB');

// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest.
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

'use strict';

var ReactDOM = require('./src/client/ReactDOM');
const ReactDOM = require('./src/client/ReactDOM');

// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest.
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/server.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

'use strict';

var ReactDOMServer = require('./src/server/ReactDOMServerBrowser');
const ReactDOMServer = require('./src/server/ReactDOMServerBrowser');

// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/server.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

'use strict';

var ReactDOMServer = require('./src/server/ReactDOMServerNode');
const ReactDOMServer = require('./src/server/ReactDOMServerNode');

// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest
Expand Down
10 changes: 5 additions & 5 deletions packages/react-dom/src/__tests__/ReactDOM-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ describe('ReactDOM', () => {
// supports real submit events.
/*
it('should bubble onSubmit', function() {
var count = 0;
var form;
var Parent = React.createClass({
const count = 0;
const form;
const Parent = React.createClass({
handleSubmit: function() {
count++;
return false;
Expand All @@ -29,15 +29,15 @@ describe('ReactDOM', () => {
return <Child />;
}
});
var Child = React.createClass({
const Child = React.createClass({
render: function() {
return <form><input type="submit" value="Submit" /></form>;
},
componentDidMount: function() {
form = ReactDOM.findDOMNode(this);
}
});
var instance = ReactTestUtils.renderIntoDocument(<Parent />);
const instance = ReactTestUtils.renderIntoDocument(<Parent />);
form.submit();
expect(count).toEqual(1);
});
Expand Down
48 changes: 24 additions & 24 deletions packages/react-dom/src/__tests__/ReactDOMInput-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ describe('ReactDOMInput', () => {
}
}

var stub = ReactTestUtils.renderIntoDocument(<Stub />);
var node = ReactDOM.findDOMNode(stub);
const stub = ReactTestUtils.renderIntoDocument(<Stub />);
const node = ReactDOM.findDOMNode(stub);
stub.setState({value: 0});

expect(node.value).toEqual('0');
Expand Down Expand Up @@ -628,36 +628,36 @@ describe('ReactDOMInput', () => {
});

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

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

var node = container.firstChild;
const node = container.firstChild;

expect(node.value).toBe('0.0');
expect(node.defaultValue).toBe('0.0');
});

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

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

var node = container.firstChild;
const node = container.firstChild;

expect(node.value).toBe('0');
expect(node.defaultValue).toBe('0');
});

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

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

var node = container.firstChild;
const node = container.firstChild;

expect(node.value).toBe('0');
expect(node.defaultValue).toBe('0');
Expand Down Expand Up @@ -1644,12 +1644,12 @@ describe('ReactDOMInput', () => {
describe('When given a Symbol value', function() {
it('treats initial Symbol value as an empty string', function() {
spyOnDev(console, 'error');
var container = document.createElement('div');
const container = document.createElement('div');
ReactDOM.render(
<input value={Symbol('foobar')} onChange={() => {}} />,
container,
);
var node = container.firstChild;
const node = container.firstChild;

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

it('treats updated Symbol value as an empty string', function() {
spyOnDev(console, 'error');
var container = document.createElement('div');
const container = document.createElement('div');
ReactDOM.render(<input value="foo" onChange={() => {}} />, container);
ReactDOM.render(
<input value={Symbol('foobar')} onChange={() => {}} />,
container,
);
var node = container.firstChild;
const node = container.firstChild;

expect(node.value).toBe('');
expect(node.getAttribute('value')).toBe('');
Expand All @@ -1684,20 +1684,20 @@ describe('ReactDOMInput', () => {
});

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

expect(node.value).toBe('');
expect(node.getAttribute('value')).toBe('');
// TODO: we should warn here.
});

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

expect(node.value).toBe('foo');
expect(node.getAttribute('value')).toBe('');
Expand All @@ -1708,12 +1708,12 @@ describe('ReactDOMInput', () => {
describe('When given a function value', function() {
it('treats initial function value as an empty string', function() {
spyOnDev(console, 'error');
var container = document.createElement('div');
const container = document.createElement('div');
ReactDOM.render(
<input value={() => {}} onChange={() => {}} />,
container,
);
var node = container.firstChild;
const node = container.firstChild;

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

it('treats updated function value as an empty string', function() {
spyOnDev(console, 'error');
var container = document.createElement('div');
const container = document.createElement('div');
ReactDOM.render(<input value="foo" onChange={() => {}} />, container);
ReactDOM.render(
<input value={() => {}} onChange={() => {}} />,
container,
);
var node = container.firstChild;
const node = container.firstChild;

expect(node.value).toBe('');
expect(node.getAttribute('value')).toBe('');
Expand All @@ -1748,20 +1748,20 @@ describe('ReactDOMInput', () => {
});

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

expect(node.value).toBe('');
expect(node.getAttribute('value')).toBe('');
// TODO: we should warn here.
});

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

expect(node.value).toBe('foo');
expect(node.getAttribute('value')).toBe('');
Expand Down
26 changes: 13 additions & 13 deletions packages/react-dom/src/client/DOMPropertyOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import warning from 'fbjs/lib/warning';

// isAttributeNameSafe() is currently duplicated in DOMMarkupOperations.
// TODO: Find a better place for this.
var VALID_ATTRIBUTE_NAME_REGEX = new RegExp(
const VALID_ATTRIBUTE_NAME_REGEX = new RegExp(
'^[' + ATTRIBUTE_NAME_START_CHAR + '][' + ATTRIBUTE_NAME_CHAR + ']*$',
);
var illegalAttributeNameCache = {};
var validatedAttributeNameCache = {};
const illegalAttributeNameCache = {};
const validatedAttributeNameCache = {};
function isAttributeNameSafe(attributeName) {
if (validatedAttributeNameCache.hasOwnProperty(attributeName)) {
return true;
Expand Down Expand Up @@ -71,18 +71,18 @@ export function setAttributeForRoot(node) {
*/
export function getValueForProperty(node, name, expected) {
if (__DEV__) {
var propertyInfo = getPropertyInfo(name);
const propertyInfo = getPropertyInfo(name);
if (propertyInfo) {
if (propertyInfo.mustUseProperty) {
return node[propertyInfo.propertyName];
} else {
var attributeName = propertyInfo.attributeName;
const attributeName = propertyInfo.attributeName;

var stringValue = null;
let stringValue = null;

if (propertyInfo.hasOverloadedBooleanValue) {
if (node.hasAttribute(attributeName)) {
var value = node.getAttribute(attributeName);
const value = node.getAttribute(attributeName);
if (value === '') {
return true;
}
Expand Down Expand Up @@ -137,7 +137,7 @@ export function getValueForAttribute(node, name, expected) {
if (!node.hasAttribute(name)) {
return expected === undefined ? undefined : null;
}
var value = node.getAttribute(name);
const value = node.getAttribute(name);
if (value === '' + expected) {
return expected;
}
Expand All @@ -153,7 +153,7 @@ export function getValueForAttribute(node, name, expected) {
* @param {*} value
*/
export function setValueForProperty(node, name, value) {
var propertyInfo = getPropertyInfo(name);
const propertyInfo = getPropertyInfo(name);

if (propertyInfo && shouldSetAttribute(name, value)) {
if (shouldIgnoreValue(propertyInfo, value)) {
Expand All @@ -164,8 +164,8 @@ export function setValueForProperty(node, name, value) {
// `toString`ed by IE8/9.
node[propertyInfo.propertyName] = value;
} else {
var attributeName = propertyInfo.attributeName;
var namespace = propertyInfo.attributeNamespace;
const attributeName = propertyInfo.attributeName;
const namespace = propertyInfo.attributeNamespace;
// `setAttribute` with objects becomes only `[object]` in IE8/9,
// ('' + value) makes it output the correct toString()-value.
if (namespace) {
Expand Down Expand Up @@ -217,10 +217,10 @@ export function deleteValueForAttribute(node, name) {
* @param {string} name
*/
export function deleteValueForProperty(node, name) {
var propertyInfo = getPropertyInfo(name);
const propertyInfo = getPropertyInfo(name);
if (propertyInfo) {
if (propertyInfo.mustUseProperty) {
var propName = propertyInfo.propertyName;
const propName = propertyInfo.propertyName;
if (propertyInfo.hasBooleanValue) {
node[propName] = false;
} else {
Expand Down
10 changes: 7 additions & 3 deletions packages/react-dom/src/client/ReactDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ const {
const {updatedAncestorInfo} = validateDOMNesting;
const {precacheFiberNode, updateFiberProps} = ReactDOMComponentTree;

let SUPPRESS_HYDRATION_WARNING;
let topLevelUpdateWarnings;
let warnOnInvalidCallback;

if (__DEV__) {
var SUPPRESS_HYDRATION_WARNING = 'suppressHydrationWarning';
SUPPRESS_HYDRATION_WARNING = 'suppressHydrationWarning';
if (
typeof Map !== 'function' ||
Map.prototype == null ||
Expand All @@ -90,7 +94,7 @@ if (__DEV__) {
);
}

var topLevelUpdateWarnings = (container: DOMContainer) => {
topLevelUpdateWarnings = (container: DOMContainer) => {
if (__DEV__) {
if (
container._reactRootContainer &&
Expand Down Expand Up @@ -137,7 +141,7 @@ if (__DEV__) {
}
};

var warnOnInvalidCallback = function(callback: mixed, callerName: string) {
warnOnInvalidCallback = function(callback: mixed, callerName: string) {
warning(
callback === null || typeof callback === 'function',
'%s(...): Expected the last optional `callback` argument to be a ' +
Expand Down
Loading

0 comments on commit 5bd2321

Please sign in to comment.