Skip to content

Commit e65d324

Browse files
committed
Use const/let in more places (facebook#11467)
* Convert ReactDOMFiberTextarea to const/let * Convert ReactDOMSelection to const/let * Convert setTextContent to const/let * Convert validateDOMNesting to const/let
1 parent 2fe3494 commit e65d324

File tree

5 files changed

+44
-44
lines changed

5 files changed

+44
-44
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import React from 'react';
1111
import warning from 'fbjs/lib/warning';
1212

1313
function flattenChildren(children) {
14-
var content = '';
14+
let content = '';
1515

1616
// Flatten children and warn if they aren't strings or numbers;
1717
// invalid types are ignored.
@@ -52,9 +52,8 @@ export function postMountWrapper(element: Element, props: Object) {
5252
}
5353

5454
export function getHostProps(element: Element, props: Object) {
55-
var hostProps = Object.assign({children: undefined}, props);
56-
57-
var content = flattenChildren(props.children);
55+
const hostProps = {...{children: undefined}, ...props};
56+
const content = flattenChildren(props.children);
5857

5958
if (content) {
6059
hostProps.children = content;

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import ReactDebugCurrentFiber from 'react-reconciler/src/ReactDebugCurrentFiber'
1414

1515
import ReactControlledValuePropTypes from '../shared/ReactControlledValuePropTypes';
1616

17-
var {getCurrentFiberStackAddendum} = ReactDebugCurrentFiber;
18-
var didWarnValDefaultVal = false;
17+
const {getCurrentFiberStackAddendum} = ReactDebugCurrentFiber;
18+
let didWarnValDefaultVal = false;
1919

2020
type TextAreaWithWrapperState = HTMLTextAreaElement & {
2121
_wrapperState: {
@@ -40,7 +40,7 @@ type TextAreaWithWrapperState = HTMLTextAreaElement & {
4040
*/
4141

4242
export function getHostProps(element: Element, props: Object) {
43-
var node = ((element: any): TextAreaWithWrapperState);
43+
const node = ((element: any): TextAreaWithWrapperState);
4444
invariant(
4545
props.dangerouslySetInnerHTML == null,
4646
'`dangerouslySetInnerHTML` does not make sense on <textarea>.',
@@ -62,7 +62,7 @@ export function getHostProps(element: Element, props: Object) {
6262
}
6363

6464
export function initWrapperState(element: Element, props: Object) {
65-
var node = ((element: any): TextAreaWithWrapperState);
65+
const node = ((element: any): TextAreaWithWrapperState);
6666
if (__DEV__) {
6767
ReactControlledValuePropTypes.checkPropTypes(
6868
'textarea',
@@ -86,14 +86,13 @@ export function initWrapperState(element: Element, props: Object) {
8686
}
8787
}
8888

89-
var value = props.value;
90-
var initialValue = value;
89+
let initialValue = props.value;
9190

9291
// Only bother fetching default value if we're going to use it
93-
if (value == null) {
94-
var defaultValue = props.defaultValue;
92+
if (initialValue == null) {
93+
let defaultValue = props.defaultValue;
9594
// TODO (yungsters): Remove support for children content in <textarea>.
96-
var children = props.children;
95+
let children = props.children;
9796
if (children != null) {
9897
if (__DEV__) {
9998
warning(
@@ -128,12 +127,12 @@ export function initWrapperState(element: Element, props: Object) {
128127
}
129128

130129
export function updateWrapper(element: Element, props: Object) {
131-
var node = ((element: any): TextAreaWithWrapperState);
132-
var value = props.value;
130+
const node = ((element: any): TextAreaWithWrapperState);
131+
const value = props.value;
133132
if (value != null) {
134133
// Cast `value` to a string to ensure the value is set correctly. While
135134
// browsers typically do this as necessary, jsdom doesn't.
136-
var newValue = '' + value;
135+
const newValue = '' + value;
137136

138137
// To avoid side effects (such as losing text selection), only set value if changed
139138
if (newValue !== node.value) {
@@ -149,10 +148,10 @@ export function updateWrapper(element: Element, props: Object) {
149148
}
150149

151150
export function postMountWrapper(element: Element, props: Object) {
152-
var node = ((element: any): TextAreaWithWrapperState);
151+
const node = ((element: any): TextAreaWithWrapperState);
153152
// This is in postMount because we need access to the DOM node, which is not
154153
// available until after the component has mounted.
155-
var textContent = node.textContent;
154+
const textContent = node.textContent;
156155

157156
// Only set node.value if textContent is equal to the expected
158157
// initial value. In IE10/IE11 there is a bug where the placeholder attribute

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@ import {TEXT_NODE} from '../shared/HTMLNodeType';
1414
* @return {?object}
1515
*/
1616
export function getOffsets(outerNode) {
17-
var selection = window.getSelection && window.getSelection();
17+
const selection = window.getSelection && window.getSelection();
1818

1919
if (!selection || selection.rangeCount === 0) {
2020
return null;
2121
}
2222

23-
var anchorNode = selection.anchorNode;
24-
var anchorOffset = selection.anchorOffset;
25-
var focusNode = selection.focusNode;
26-
var focusOffset = selection.focusOffset;
23+
const {
24+
anchorNode,
25+
anchorOffset,
26+
focusNode,
27+
focusOffset,
28+
} = selection;
2729

2830
// In Firefox, anchorNode and focusNode can be "anonymous divs", e.g. the
2931
// up/down buttons on an <input type="number">. Anonymous divs do not seem to
@@ -157,21 +159,21 @@ export function setOffsets(node, offsets) {
157159
return;
158160
}
159161

160-
var selection = window.getSelection();
161-
var length = node[getTextContentAccessor()].length;
162-
var start = Math.min(offsets.start, length);
163-
var end = offsets.end === undefined ? start : Math.min(offsets.end, length);
162+
const selection = window.getSelection();
163+
const length = node[getTextContentAccessor()].length;
164+
let start = Math.min(offsets.start, length);
165+
let end = offsets.end === undefined ? start : Math.min(offsets.end, length);
164166

165167
// IE 11 uses modern selection, but doesn't support the extend method.
166168
// Flip backward selections, so we can set with a single range.
167169
if (!selection.extend && start > end) {
168-
var temp = end;
170+
let temp = end;
169171
end = start;
170172
start = temp;
171173
}
172174

173-
var startMarker = getNodeForCharacterOffset(node, start);
174-
var endMarker = getNodeForCharacterOffset(node, end);
175+
const startMarker = getNodeForCharacterOffset(node, start);
176+
const endMarker = getNodeForCharacterOffset(node, end);
175177

176178
if (startMarker && endMarker) {
177179
if (
@@ -183,7 +185,7 @@ export function setOffsets(node, offsets) {
183185
) {
184186
return;
185187
}
186-
var range = document.createRange();
188+
const range = document.createRange();
187189
range.setStart(startMarker.node, startMarker.offset);
188190
selection.removeAllRanges();
189191

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {TEXT_NODE} from '../shared/HTMLNodeType';
2121
* @param {string} text
2222
* @internal
2323
*/
24-
var setTextContent = function(node, text) {
24+
let setTextContent = function(node, text) {
2525
if (text) {
2626
let firstChild = node.firstChild;
2727

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import warning from 'fbjs/lib/warning';
1111
import ReactDebugCurrentFiber from 'react-reconciler/src/ReactDebugCurrentFiber';
1212

1313
const {getCurrentFiberStackAddendum} = ReactDebugCurrentFiber;
14-
var validateDOMNesting = emptyFunction;
14+
let validateDOMNesting = emptyFunction;
1515

1616
if (__DEV__) {
1717
// This validation code was written based on the HTML5 parsing spec:
@@ -26,7 +26,7 @@ if (__DEV__) {
2626
// first, causing a confusing mess.
2727

2828
// https://html.spec.whatwg.org/multipage/syntax.html#special
29-
var specialTags = [
29+
let specialTags = [
3030
'address',
3131
'applet',
3232
'area',
@@ -113,7 +113,7 @@ if (__DEV__) {
113113
];
114114

115115
// https://html.spec.whatwg.org/multipage/syntax.html#has-an-element-in-scope
116-
var inScopeTags = [
116+
const inScopeTags = [
117117
'applet',
118118
'caption',
119119
'html',
@@ -133,10 +133,10 @@ if (__DEV__) {
133133
];
134134

135135
// https://html.spec.whatwg.org/multipage/syntax.html#has-an-element-in-button-scope
136-
var buttonScopeTags = inScopeTags.concat(['button']);
136+
const buttonScopeTags = inScopeTags.concat(['button']);
137137

138138
// https://html.spec.whatwg.org/multipage/syntax.html#generate-implied-end-tags
139-
var impliedEndTags = [
139+
const impliedEndTags = [
140140
'dd',
141141
'dt',
142142
'li',
@@ -147,7 +147,7 @@ if (__DEV__) {
147147
'rt',
148148
];
149149

150-
var emptyAncestorInfo = {
150+
const emptyAncestorInfo = {
151151
current: null,
152152

153153
formTag: null,
@@ -160,9 +160,9 @@ if (__DEV__) {
160160
dlItemTagAutoclosing: null,
161161
};
162162

163-
var updatedAncestorInfo = function(oldInfo, tag, instance) {
164-
var ancestorInfo = Object.assign({}, oldInfo || emptyAncestorInfo);
165-
var info = {tag: tag, instance: instance};
163+
const updatedAncestorInfo = function(oldInfo, tag, instance) {
164+
let ancestorInfo = Object.assign({}, oldInfo || emptyAncestorInfo);
165+
let info = {tag: tag, instance: instance};
166166

167167
if (inScopeTags.indexOf(tag) !== -1) {
168168
ancestorInfo.aTagInScope = null;
@@ -215,7 +215,7 @@ if (__DEV__) {
215215
/**
216216
* Returns whether
217217
*/
218-
var isTagValidWithParent = function(tag, parentTag) {
218+
const isTagValidWithParent = function(tag, parentTag) {
219219
// First, let's check if we're in an unusual parsing mode...
220220
switch (parentTag) {
221221
// https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inselect
@@ -337,7 +337,7 @@ if (__DEV__) {
337337
/**
338338
* Returns whether
339339
*/
340-
var findInvalidAncestorForTag = function(tag, ancestorInfo) {
340+
const findInvalidAncestorForTag = function(tag, ancestorInfo) {
341341
switch (tag) {
342342
case 'address':
343343
case 'article':
@@ -401,7 +401,7 @@ if (__DEV__) {
401401
return null;
402402
};
403403

404-
var didWarn = {};
404+
let didWarn = {};
405405

406406
validateDOMNesting = function(childTag, childText, ancestorInfo) {
407407
ancestorInfo = ancestorInfo || emptyAncestorInfo;

0 commit comments

Comments
 (0)