@samitouri / QOS-React / commits / 37e4329bc8

Remove vars (#11766)

* react: convert packages/react * react-reconciler: convert packages/react-reconciler * react-noop-renderer: convert packages/react-noop-renderer * react-dom: convert packages/react-dom/src/shared * react-dom: convert packages/react-dom/src/server

Raphael Amorim committed Dec 5, 2017 at 11:47 UTC 37e4329bc81def4695211d6e3795a654ef4d84f5
36 files changed +318 -252
packages/react-dom/src/server/DOMMarkupOperations.js
+5 -5
@@ -19,11 +19,11 @@ import warning from 'fbjs/lib/warning';
19
20 // isAttributeNameSafe() is currently duplicated in DOMPropertyOperations.
21 // TODO: Find a better place for this.
22 -var VALID_ATTRIBUTE_NAME_REGEX = new RegExp(
22 +const VALID_ATTRIBUTE_NAME_REGEX = new RegExp(
23 '^[' + ATTRIBUTE_NAME_START_CHAR + '][' + ATTRIBUTE_NAME_CHAR + ']*$',
24 );
25 -var illegalAttributeNameCache = {};
26 -var validatedAttributeNameCache = {};
25 +const illegalAttributeNameCache = {};
26 +const validatedAttributeNameCache = {};
27 function isAttributeNameSafe(attributeName) {
28 if (validatedAttributeNameCache.hasOwnProperty(attributeName)) {
29 return true;
@@ -80,12 +80,12 @@ export function createMarkupForRoot() {
80 * @return {?string} Markup string, or null if the property was invalid.
81 */
82 export function createMarkupForProperty(name, value) {
83 - var propertyInfo = getPropertyInfo(name);
83 + const propertyInfo = getPropertyInfo(name);
84 if (propertyInfo) {
85 if (shouldIgnoreValue(propertyInfo, value)) {
86 return '';
87 }
88 - var attributeName = propertyInfo.attributeName;
88 + const attributeName = propertyInfo.attributeName;
89 if (
90 propertyInfo.hasBooleanValue ||
91 (propertyInfo.hasOverloadedBooleanValue && value === true)
packages/react-dom/src/server/ReactDOMStringRenderer.js
+4 -4
@@ -13,8 +13,8 @@ import ReactPartialRenderer from './ReactPartialRenderer';
13 * See https://reactjs.org/docs/react-dom-server.html#rendertostring
14 */
15 export function renderToString(element) {
16 - var renderer = new ReactPartialRenderer(element, false);
17 - var markup = renderer.read(Infinity);
16 + const renderer = new ReactPartialRenderer(element, false);
17 + const markup = renderer.read(Infinity);
18 return markup;
19 }
20
@@ -24,7 +24,7 @@ export function renderToString(element) {
24 * See https://reactjs.org/docs/react-dom-server.html#rendertostaticmarkup
25 */
26 export function renderToStaticMarkup(element) {
27 - var renderer = new ReactPartialRenderer(element, true);
28 - var markup = renderer.read(Infinity);
27 + const renderer = new ReactPartialRenderer(element, true);
28 + const markup = renderer.read(Infinity);
29 return markup;
30 }
packages/react-dom/src/server/ReactPartialRenderer.js
+113 -90
@@ -51,41 +51,50 @@ import {validateProperties as validateUnknownProperties} from '../shared/ReactDO
51 type ReactNode = string | number | ReactElement;
52 type FlatReactChildren = Array<null | ReactNode>;
53 type toArrayType = (children: mixed) => FlatReactChildren;
54 -var toArray = ((React.Children.toArray: any): toArrayType);
54 +const toArray = ((React.Children.toArray: any): toArrayType);
55
56 -var getStackAddendum = emptyFunction.thatReturns('');
56 +let currentDebugStack;
57 +let currentDebugElementStack;
58 +
59 +let getStackAddendum = emptyFunction.thatReturns('');
60 +let describeStackFrame = emptyFunction.thatReturns('');
61 +
62 +let validatePropertiesInDevelopment = (type, props) => {};
63 +let setCurrentDebugStack = (stack: Array<Frame>) => {};
64 +let pushElementToDebugStack = (element: ReactElement) => {};
65 +let resetCurrentDebugStack = () => {};
66
67 if (__DEV__) {
59 - var validatePropertiesInDevelopment = function(type, props) {
68 + validatePropertiesInDevelopment = function(type, props) {
69 validateARIAProperties(type, props);
70 validateInputProperties(type, props);
71 validateUnknownProperties(type, props, /* canUseEventSystem */ false);
72 };
73
65 - var describeStackFrame = function(element): string {
66 - var source = element._source;
67 - var type = element.type;
68 - var name = getComponentName(type);
69 - var ownerName = null;
74 + describeStackFrame = function(element): string {
75 + const source = element._source;
76 + const type = element.type;
77 + const name = getComponentName(type);
78 + const ownerName = null;
79 return describeComponentFrame(name, source, ownerName);
80 };
81
73 - var currentDebugStack = null;
74 - var currentDebugElementStack = null;
75 - var setCurrentDebugStack = function(stack: Array<Frame>) {
76 - var frame: Frame = stack[stack.length - 1];
82 + currentDebugStack = null;
83 + currentDebugElementStack = null;
84 + setCurrentDebugStack = function(stack: Array<Frame>) {
85 + const frame: Frame = stack[stack.length - 1];
86 currentDebugElementStack = ((frame: any): FrameDev).debugElementStack;
87 // We are about to enter a new composite stack, reset the array.
88 currentDebugElementStack.length = 0;
89 currentDebugStack = stack;
90 ReactDebugCurrentFrame.getCurrentStack = getStackAddendum;
91 };
83 - var pushElementToDebugStack = function(element: ReactElement) {
92 + pushElementToDebugStack = function(element: ReactElement) {
93 if (currentDebugElementStack !== null) {
94 currentDebugElementStack.push(element);
95 }
96 };
88 - var resetCurrentDebugStack = function() {
97 + resetCurrentDebugStack = function() {
98 currentDebugElementStack = null;
99 currentDebugStack = null;
100 ReactDebugCurrentFrame.getCurrentStack = null;
@@ -107,14 +116,14 @@ if (__DEV__) {
116 };
117 }
118
110 -var didWarnDefaultInputValue = false;
111 -var didWarnDefaultChecked = false;
112 -var didWarnDefaultSelectValue = false;
113 -var didWarnDefaultTextareaValue = false;
114 -var didWarnInvalidOptionChildren = false;
115 -var didWarnAboutNoopUpdateForComponent = {};
116 -var valuePropNames = ['value', 'defaultValue'];
117 -var newlineEatingTags = {
119 +let didWarnDefaultInputValue = false;
120 +let didWarnDefaultChecked = false;
121 +let didWarnDefaultSelectValue = false;
122 +let didWarnDefaultTextareaValue = false;
123 +let didWarnInvalidOptionChildren = false;
124 +const didWarnAboutNoopUpdateForComponent = {};
125 +const valuePropNames = ['value', 'defaultValue'];
126 +const newlineEatingTags = {
127 listing: true,
128 pre: true,
129 textarea: true,
@@ -129,8 +138,8 @@ function getComponentName(type) {
138 // We accept any tag to be rendered but since this gets injected into arbitrary
139 // HTML, we want to make sure that it's a safe tag.
140 // http://www.w3.org/TR/REC-xml/#NT-Name
132 -var VALID_TAG_REGEX = /^[a-zA-Z][a-zA-Z:_\.\-\d]*$/; // Simplified subset
133 -var validatedTagCache = {};
141 +const VALID_TAG_REGEX = /^[a-zA-Z][a-zA-Z:_\.\-\d]*$/; // Simplified subset
142 +const validatedTagCache = {};
143 function validateDangerousTag(tag) {
144 if (!validatedTagCache.hasOwnProperty(tag)) {
145 invariant(VALID_TAG_REGEX.test(tag), 'Invalid tag: %s', tag);
@@ -138,19 +147,19 @@ function validateDangerousTag(tag) {
147 }
148 }
149
141 -var processStyleName = memoizeStringOnly(function(styleName) {
150 +const processStyleName = memoizeStringOnly(function(styleName) {
151 return hyphenateStyleName(styleName);
152 });
153
154 function createMarkupForStyles(styles): string | null {
146 - var serialized = '';
147 - var delimiter = '';
148 - for (var styleName in styles) {
155 + let serialized = '';
156 + let delimiter = '';
157 + for (const styleName in styles) {
158 if (!styles.hasOwnProperty(styleName)) {
159 continue;
160 }
152 - var isCustomProperty = styleName.indexOf('--') === 0;
153 - var styleValue = styles[styleName];
161 + const isCustomProperty = styleName.indexOf('--') === 0;
162 + const styleValue = styles[styleName];
163 if (__DEV__) {
164 if (!isCustomProperty) {
165 warnValidStyle(styleName, styleValue, getStackAddendum);
@@ -175,7 +184,7 @@ function warnNoop(
184 callerName: string,
185 ) {
186 if (__DEV__) {
178 - var constructor = publicInstance.constructor;
187 + const constructor = publicInstance.constructor;
188 const componentName =
189 (constructor && getComponentName(constructor)) || 'ReactClass';
190 const warningKey = `${componentName}.${callerName}`;
@@ -201,13 +210,13 @@ function shouldConstruct(Component) {
210 }
211
212 function getNonChildrenInnerMarkup(props) {
204 - var innerHTML = props.dangerouslySetInnerHTML;
213 + const innerHTML = props.dangerouslySetInnerHTML;
214 if (innerHTML != null) {
215 if (innerHTML.__html != null) {
216 return innerHTML.__html;
217 }
218 } else {
210 - var content = props.children;
219 + const content = props.children;
220 if (typeof content === 'string' || typeof content === 'number') {
221 return escapeTextForBrowser(content);
222 }
@@ -232,7 +241,7 @@ function flattenTopLevelChildren(children: mixed): FlatReactChildren {
241 }
242
243 function flattenOptionChildren(children: mixed): string {
235 - var content = '';
244 + let content = '';
245 // Flatten children and warn if they aren't strings or numbers;
246 // invalid types are ignored.
247 React.Children.forEach(children, function(child) {
@@ -257,12 +266,12 @@ function flattenOptionChildren(children: mixed): string {
266 }
267
268 function maskContext(type, context) {
260 - var contextTypes = type.contextTypes;
269 + const contextTypes = type.contextTypes;
270 if (!contextTypes) {
271 return emptyObject;
272 }
264 - var maskedContext = {};
265 - for (var contextName in contextTypes) {
273 + const maskedContext = {};
274 + for (const contextName in contextTypes) {
275 maskedContext[contextName] = context[contextName];
276 }
277 return maskedContext;
@@ -275,7 +284,7 @@ function checkContextTypes(typeSpecs, values, location: string) {
284 }
285
286 function processContext(type, context) {
278 - var maskedContext = maskContext(type, context);
287 + const maskedContext = maskContext(type, context);
288 if (__DEV__) {
289 if (type.contextTypes) {
290 checkContextTypes(type.contextTypes, maskedContext, 'context');
@@ -284,8 +293,8 @@ function processContext(type, context) {
293 return maskedContext;
294 }
295
287 -var STYLE = 'style';
288 -var RESERVED_PROPS = {
296 +const STYLE = 'style';
297 +const RESERVED_PROPS = {
298 children: null,
299 dangerouslySetInnerHTML: null,
300 suppressContentEditableWarning: null,
@@ -300,20 +309,20 @@ function createOpenTagMarkup(
309 makeStaticMarkup: boolean,
310 isRootElement: boolean,
311 ): string {
303 - var ret = '<' + tagVerbatim;
312 + let ret = '<' + tagVerbatim;
313
305 - for (var propKey in props) {
314 + for (const propKey in props) {
315 if (!props.hasOwnProperty(propKey)) {
316 continue;
317 }
309 - var propValue = props[propKey];
318 + let propValue = props[propKey];
319 if (propValue == null) {
320 continue;
321 }
322 if (propKey === STYLE) {
323 propValue = createMarkupForStyles(propValue);
324 }
316 - var markup = null;
325 + let markup = null;
326 if (isCustomComponent(tagLowercase, props)) {
327 if (!RESERVED_PROPS.hasOwnProperty(propKey)) {
328 markup = createMarkupForCustomAttribute(propKey, propValue);
@@ -357,21 +366,36 @@ function resolve(
366 child: mixed,
367 context: Object,
368 |} {
369 + let element: ReactElement;
370 +
371 + let Component;
372 + let publicContext;
373 + let inst, queue, replace;
374 + let updater;
375 +
376 + let initialState;
377 + let oldQueue, oldReplace;
378 + let nextState, dontMutate;
379 + let partial, partialState;
380 +
381 + let childContext;
382 + let childContextTypes, contextKey;
383 +
384 while (React.isValidElement(child)) {
385 // Safe because we just checked it's an element.
362 - var element: ReactElement = ((child: any): ReactElement);
386 + element = ((child: any): ReactElement);
387 if (__DEV__) {
388 pushElementToDebugStack(element);
389 }
366 - var Component = element.type;
390 + Component = element.type;
391 if (typeof Component !== 'function') {
392 break;
393 }
370 - var publicContext = processContext(Component, context);
371 - var inst;
372 - var queue = [];
373 - var replace = false;
374 - var updater = {
394 + publicContext = processContext(Component, context);
395 +
396 + queue = [];
397 + replace = false;
398 + updater = {
399 isMounted: function(publicInstance) {
400 return false;
401 },
@@ -385,12 +409,12 @@ function resolve(
409 replace = true;
410 queue = [completeState];
411 },
388 - enqueueSetState: function(publicInstance, partialState) {
412 + enqueueSetState: function(publicInstance, currentPartialState) {
413 if (queue === null) {
414 warnNoop(publicInstance, 'setState');
415 return null;
416 }
393 - queue.push(partialState);
417 + queue.push(currentPartialState);
418 },
419 };
420
@@ -409,26 +433,26 @@ function resolve(
433 inst.context = publicContext;
434 inst.updater = updater;
435
412 - var initialState = inst.state;
436 + initialState = inst.state;
437 if (initialState === undefined) {
438 inst.state = initialState = null;
439 }
440 if (inst.componentWillMount) {
441 inst.componentWillMount();
442 if (queue.length) {
419 - var oldQueue = queue;
420 - var oldReplace = replace;
443 + oldQueue = queue;
444 + oldReplace = replace;
445 queue = null;
446 replace = false;
447
448 if (oldReplace && oldQueue.length === 1) {
449 inst.state = oldQueue[0];
450 } else {
427 - var nextState = oldReplace ? oldQueue[0] : inst.state;
428 - var dontMutate = true;
429 - for (var i = oldReplace ? 1 : 0; i < oldQueue.length; i++) {
430 - var partial = oldQueue[i];
431 - var partialState =
451 + nextState = oldReplace ? oldQueue[0] : inst.state;
452 + dontMutate = true;
453 + for (let i = oldReplace ? 1 : 0; i < oldQueue.length; i++) {
454 + partial = oldQueue[i];
455 + partialState =
456 typeof partial === 'function'
457 ? partial.call(inst, nextState, element.props, publicContext)
458 : partial;
@@ -458,12 +482,11 @@ function resolve(
482 }
483 validateRenderResult(child, Component);
484
461 - var childContext;
485 if (typeof inst.getChildContext === 'function') {
463 - var childContextTypes = Component.childContextTypes;
486 + childContextTypes = Component.childContextTypes;
487 if (typeof childContextTypes === 'object') {
488 childContext = inst.getChildContext();
466 - for (let contextKey in childContext) {
489 + for (contextKey in childContext) {
490 invariant(
491 contextKey in childContextTypes,
492 '%s.getChildContext(): key "%s" is not defined in childContextTypes.',
@@ -510,7 +533,7 @@ class ReactDOMServerRenderer {
533 constructor(children: mixed, makeStaticMarkup: boolean) {
534 const flatChildren = flattenTopLevelChildren(children);
535
513 - var topFrame: Frame = {
536 + const topFrame: Frame = {
537 // Assume all trees start in the HTML namespace (not totally true, but
538 // this is what we did historically)
539 domNamespace: Namespaces.html,
@@ -534,15 +557,15 @@ class ReactDOMServerRenderer {
557 return null;
558 }
559
537 - var out = '';
560 + let out = '';
561 while (out.length < bytes) {
562 if (this.stack.length === 0) {
563 this.exhausted = true;
564 break;
565 }
543 - var frame: Frame = this.stack[this.stack.length - 1];
566 + const frame: Frame = this.stack[this.stack.length - 1];
567 if (frame.childIndex >= frame.children.length) {
545 - var footer = frame.footer;
568 + const footer = frame.footer;
569 out += footer;
570 if (footer !== '') {
571 this.previousWasTextNode = false;
@@ -553,7 +576,7 @@ class ReactDOMServerRenderer {
576 }
577 continue;
578 }
556 - var child = frame.children[frame.childIndex++];
579 + const child = frame.children[frame.childIndex++];
580 if (__DEV__) {
581 setCurrentDebugStack(this.stack);
582 }
@@ -572,7 +595,7 @@ class ReactDOMServerRenderer {
595 parentNamespace: string,
596 ): string {
597 if (typeof child === 'string' || typeof child === 'number') {
575 - var text = '' + child;
598 + const text = '' + child;
599 if (text === '') {
600 return '';
601 }
@@ -585,7 +608,7 @@ class ReactDOMServerRenderer {
608 this.previousWasTextNode = true;
609 return escapeTextForBrowser(text);
610 } else {
588 - var nextChild;
611 + let nextChild;
612 ({child: nextChild, context} = resolve(child, context));
613 if (nextChild === null || nextChild === false) {
614 return '';
@@ -644,7 +667,7 @@ class ReactDOMServerRenderer {
667 return '';
668 } else {
669 // Safe because we just checked it's an element.
647 - var nextElement = ((nextChild: any): ReactElement);
670 + const nextElement = ((nextChild: any): ReactElement);
671 return this.renderDOM(nextElement, context, parentNamespace);
672 }
673 }
@@ -655,7 +678,7 @@ class ReactDOMServerRenderer {
678 context: Object,
679 parentNamespace: string,
680 ): string {
658 - var tag = element.type.toLowerCase();
681 + const tag = element.type.toLowerCase();
682
683 let namespace = parentNamespace;
684 if (parentNamespace === Namespaces.html) {
@@ -677,7 +700,7 @@ class ReactDOMServerRenderer {
700
701 validateDangerousTag(tag);
702
680 - var props = element.props;
703 + let props = element.props;
704 if (tag === 'input') {
705 if (__DEV__) {
706 ReactControlledValuePropTypes.checkPropTypes(
@@ -760,11 +783,11 @@ class ReactDOMServerRenderer {
783 }
784 }
785
763 - var initialValue = props.value;
786 + let initialValue = props.value;
787 if (initialValue == null) {
765 - var defaultValue = props.defaultValue;
788 + let defaultValue = props.defaultValue;
789 // TODO (yungsters): Remove support for children content in <textarea>.
767 - var textareaChildren = props.children;
790 + let textareaChildren = props.children;
791 if (textareaChildren != null) {
792 if (__DEV__) {
793 warning(
@@ -805,12 +828,12 @@ class ReactDOMServerRenderer {
828 getStackAddendum,
829 );
830
808 - for (var i = 0; i < valuePropNames.length; i++) {
809 - var propName = valuePropNames[i];
831 + for (let i = 0; i < valuePropNames.length; i++) {
832 + const propName = valuePropNames[i];
833 if (props[propName] == null) {
834 continue;
835 }
813 - var isArray = Array.isArray(props[propName]);
836 + const isArray = Array.isArray(props[propName]);
837 if (props.multiple && !isArray) {
838 warning(
839 false,
@@ -852,11 +875,11 @@ class ReactDOMServerRenderer {
875 value: undefined,
876 });
877 } else if (tag === 'option') {
855 - var selected = null;
856 - var selectValue = this.currentSelectValue;
857 - var optionChildren = flattenOptionChildren(props.children);
878 + let selected = null;
879 + const selectValue = this.currentSelectValue;
880 + const optionChildren = flattenOptionChildren(props.children);
881 if (selectValue != null) {
859 - var value;
882 + let value;
883 if (props.value != null) {
884 value = props.value + '';
885 } else {
@@ -865,7 +888,7 @@ class ReactDOMServerRenderer {
888 selected = false;
889 if (Array.isArray(selectValue)) {
890 // multiple
868 - for (var j = 0; j < selectValue.length; j++) {
891 + for (let j = 0; j < selectValue.length; j++) {
892 if ('' + selectValue[j] === value) {
893 selected = true;
894 break;
@@ -895,7 +918,7 @@ class ReactDOMServerRenderer {
918
919 assertValidProps(tag, props, getStackAddendum);
920
898 - var out = createOpenTagMarkup(
921 + let out = createOpenTagMarkup(
922 element.type,
923 tag,
924 props,
@@ -903,15 +926,15 @@ class ReactDOMServerRenderer {
926 this.makeStaticMarkup,
927 this.stack.length === 1,
928 );
906 - var footer = '';
929 + let footer = '';
930 if (omittedCloseTags.hasOwnProperty(tag)) {
931 out += '/>';
932 } else {
933 out += '>';
934 footer = '</' + element.type + '>';
935 }
913 - var children;
914 - var innerMarkup = getNonChildrenInnerMarkup(props);
936 + let children;
937 + const innerMarkup = getNonChildrenInnerMarkup(props);
938 if (innerMarkup != null) {
939 children = [];
940 if (newlineEatingTags[tag] && innerMarkup.charAt(0) === '\n') {
@@ -931,7 +954,7 @@ class ReactDOMServerRenderer {
954 } else {
955 children = toArray(props.children);
956 }
934 - var frame = {
957 + const frame = {
958 domNamespace: getChildNamespace(parentNamespace, element.type),
959 tag,
960 children,
packages/react-dom/src/server/escapeTextForBrowser.js
+7 -7
@@ -36,7 +36,7 @@
36 * @private
37 */
38
39 -var matchHtmlRegExp = /["'&<>]/;
39 +const matchHtmlRegExp = /["'&<>]/;
40
41 /**
42 * Escapes special characters and HTML entities in a given html string.
@@ -47,17 +47,17 @@ var matchHtmlRegExp = /["'&<>]/;
47 */
48
49 function escapeHtml(string) {
50 - var str = '' + string;
51 - var match = matchHtmlRegExp.exec(str);
50 + const str = '' + string;
51 + const match = matchHtmlRegExp.exec(str);
52
53 if (!match) {
54 return str;
55 }
56
57 - var escape;
58 - var html = '';
59 - var index = 0;
60 - var lastIndex = 0;
57 + let escape;
58 + let html = '';
59 + let index = 0;
60 + let lastIndex = 0;
61
62 for (index = match.index; index < str.length; index++) {
63 switch (str.charCodeAt(index)) {
packages/react-dom/src/shared/CSSProperty.js
+1 -1
@@ -68,7 +68,7 @@ function prefixKey(prefix, key) {
68 * Support style names that may come passed in prefixed by adding permutations
69 * of vendor prefixes.
70 */
71 -var prefixes = ['Webkit', 'ms', 'Moz', 'O'];
71 +const prefixes = ['Webkit', 'ms', 'Moz', 'O'];
72
73 // Using Object.keys here, or else the vanilla for-in loop makes IE8 go into an
74 // infinite loop, because it iterates over the newly added props too.
packages/react-dom/src/shared/CSSPropertyOperations.js
+9 -9
@@ -21,15 +21,15 @@ import warnValidStyle from './warnValidStyle';
21 */
22 export function createDangerousStringForStyles(styles) {
23 if (__DEV__) {
24 - var serialized = '';
25 - var delimiter = '';
26 - for (var styleName in styles) {
24 + let serialized = '';
25 + let delimiter = '';
26 + for (const styleName in styles) {
27 if (!styles.hasOwnProperty(styleName)) {
28 continue;
29 }
30 - var styleValue = styles[styleName];
30 + const styleValue = styles[styleName];
31 if (styleValue != null) {
32 - var isCustomProperty = styleName.indexOf('--') === 0;
32 + const isCustomProperty = styleName.indexOf('--') === 0;
33 serialized += delimiter + hyphenateStyleName(styleName) + ':';
34 serialized += dangerousStyleValue(
35 styleName,
@@ -52,18 +52,18 @@ export function createDangerousStringForStyles(styles) {
52 * @param {object} styles
53 */
54 export function setValueForStyles(node, styles, getStack) {
55 - var style = node.style;
56 - for (var styleName in styles) {
55 + const style = node.style;
56 + for (let styleName in styles) {
57 if (!styles.hasOwnProperty(styleName)) {
58 continue;
59 }
60 - var isCustomProperty = styleName.indexOf('--') === 0;
60 + const isCustomProperty = styleName.indexOf('--') === 0;
61 if (__DEV__) {
62 if (!isCustomProperty) {
63 warnValidStyle(styleName, styles[styleName], getStack);
64 }
65 }
66 - var styleValue = dangerousStyleValue(
66 + const styleValue = dangerousStyleValue(
67 styleName,
68 styles[styleName],
69 isCustomProperty,
packages/react-dom/src/shared/DOMProperty.js
+17 -17
@@ -9,7 +9,7 @@ import warning from 'fbjs/lib/warning';
9
10 // These attributes should be all lowercase to allow for
11 // case insensitive checks
12 -var RESERVED_PROPS = {
12 +const RESERVED_PROPS = {
13 children: true,
14 dangerouslySetInnerHTML: true,
15 // TODO: This prevents the assignment of defaultValue to regular
@@ -35,11 +35,11 @@ const HAS_OVERLOADED_BOOLEAN_VALUE = 0x20;
35 const HAS_STRING_BOOLEAN_VALUE = 0x40;
36
37 function injectDOMPropertyConfig(domPropertyConfig) {
38 - var Properties = domPropertyConfig.Properties || {};
39 - var DOMAttributeNamespaces = domPropertyConfig.DOMAttributeNamespaces || {};
40 - var DOMAttributeNames = domPropertyConfig.DOMAttributeNames || {};
38 + const Properties = domPropertyConfig.Properties || {};
39 + const DOMAttributeNamespaces = domPropertyConfig.DOMAttributeNamespaces || {};
40 + const DOMAttributeNames = domPropertyConfig.DOMAttributeNames || {};
41
42 - for (var propName in Properties) {
42 + for (const propName in Properties) {
43 if (__DEV__) {
44 warning(
45 !properties.hasOwnProperty(propName),
@@ -51,10 +51,10 @@ function injectDOMPropertyConfig(domPropertyConfig) {
51 );
52 }
53
54 - var lowerCased = propName.toLowerCase();
55 - var propConfig = Properties[propName];
54 + const lowerCased = propName.toLowerCase();
55 + const propConfig = Properties[propName];
56
57 - var propertyInfo = {
57 + const propertyInfo = {
58 attributeName: lowerCased,
59 attributeNamespace: null,
60 propertyName: propName,
@@ -85,7 +85,7 @@ function injectDOMPropertyConfig(domPropertyConfig) {
85 }
86
87 if (DOMAttributeNames.hasOwnProperty(propName)) {
88 - var attributeName = DOMAttributeNames[propName];
88 + const attributeName = DOMAttributeNames[propName];
89
90 propertyInfo.attributeName = attributeName;
91 }
@@ -187,7 +187,7 @@ export function shouldAttributeAcceptBooleanValue(name) {
187 propertyInfo.hasOverloadedBooleanValue
188 );
189 }
190 - var prefix = name.toLowerCase().slice(0, 5);
190 + const prefix = name.toLowerCase().slice(0, 5);
191 return prefix === 'data-' || prefix === 'aria-';
192 }
193
@@ -204,7 +204,7 @@ export function isReservedProp(name) {
204 return RESERVED_PROPS.hasOwnProperty(name);
205 }
206
207 -var HTMLDOMPropertyConfig = {
207 +const HTMLDOMPropertyConfig = {
208 // When adding attributes to this list, be sure to also add them to
209 // the `possibleStandardNames` module to ensure casing and incorrect
210 // name warnings.
@@ -274,7 +274,7 @@ var HTMLDOMPropertyConfig = {
274 },
275 };
276
277 -var NS = {
277 +const NS = {
278 xlink: 'http://www.w3.org/1999/xlink',
279 xml: 'http://www.w3.org/XML/1998/namespace',
280 };
@@ -292,7 +292,7 @@ var NS = {
292 * SMIL Spec:
293 * https://www.w3.org/TR/smil
294 */
295 -var SVG_ATTRS = [
295 +const SVG_ATTRS = [
296 'accent-height',
297 'alignment-baseline',
298 'arabic-form',
@@ -378,7 +378,7 @@ var SVG_ATTRS = [
378 'xml:space',
379 ];
380
381 -var SVGDOMPropertyConfig = {
381 +const SVGDOMPropertyConfig = {
382 Properties: {
383 autoReverse: HAS_STRING_BOOLEAN_VALUE,
384 externalResourcesRequired: HAS_STRING_BOOLEAN_VALUE,
@@ -403,11 +403,11 @@ var SVGDOMPropertyConfig = {
403 },
404 };
405
406 -var CAMELIZE = /[\-\:]([a-z])/g;
407 -var capitalize = token => token[1].toUpperCase();
406 +const CAMELIZE = /[\-\:]([a-z])/g;
407 +const capitalize = token => token[1].toUpperCase();
408
409 SVG_ATTRS.forEach(original => {
410 - var reactName = original.replace(CAMELIZE, capitalize);
410 + const reactName = original.replace(CAMELIZE, capitalize);
411
412 SVGDOMPropertyConfig.Properties[reactName] = 0;
413 SVGDOMPropertyConfig.DOMAttributeNames[reactName] = original;
packages/react-dom/src/shared/ReactControlledValuePropTypes.js
+3 -3
@@ -7,12 +7,12 @@
7
8 import checkPropTypes from 'prop-types/checkPropTypes';
9
10 -var ReactControlledValuePropTypes = {
10 +const ReactControlledValuePropTypes = {
11 checkPropTypes: null,
12 };
13
14 if (__DEV__) {
15 - var hasReadOnlyValue = {
15 + const hasReadOnlyValue = {
16 button: true,
17 checkbox: true,
18 image: true,
@@ -22,7 +22,7 @@ if (__DEV__) {
22 submit: true,
23 };
24
25 - var propTypes = {
25 + const propTypes = {
26 value: function(props, propName, componentName) {
27 if (
28 !props[propName] ||
packages/react-dom/src/shared/ReactDOMInvalidARIAHook.js
+11 -11
@@ -12,14 +12,14 @@ import {ATTRIBUTE_NAME_CHAR} from './DOMProperty';
12 import isCustomComponent from './isCustomComponent';
13 import validAriaProperties from './validAriaProperties';
14
15 -var warnedProperties = {};
16 -var rARIA = new RegExp('^(aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$');
17 -var rARIACamel = new RegExp('^(aria)[A-Z][' + ATTRIBUTE_NAME_CHAR + ']*$');
15 +const warnedProperties = {};
16 +const rARIA = new RegExp('^(aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$');
17 +const rARIACamel = new RegExp('^(aria)[A-Z][' + ATTRIBUTE_NAME_CHAR + ']*$');
18
19 -var hasOwnProperty = Object.prototype.hasOwnProperty;
19 +const hasOwnProperty = Object.prototype.hasOwnProperty;
20
21 function getStackAddendum() {
22 - var stack = ReactDebugCurrentFrame.getStackAddendum();
22 + const stack = ReactDebugCurrentFrame.getStackAddendum();
23 return stack != null ? stack : '';
24 }
25
@@ -29,8 +29,8 @@ function validateProperty(tagName, name) {
29 }
30
31 if (rARIACamel.test(name)) {
32 - var ariaName = 'aria-' + name.slice(4).toLowerCase();
33 - var correctName = validAriaProperties.hasOwnProperty(ariaName)
32 + const ariaName = 'aria-' + name.slice(4).toLowerCase();
33 + const correctName = validAriaProperties.hasOwnProperty(ariaName)
34 ? ariaName
35 : null;
36
@@ -61,8 +61,8 @@ function validateProperty(tagName, name) {
61 }
62
63 if (rARIA.test(name)) {
64 - var lowerCasedName = name.toLowerCase();
65 - var standardName = validAriaProperties.hasOwnProperty(lowerCasedName)
64 + const lowerCasedName = name.toLowerCase();
65 + const standardName = validAriaProperties.hasOwnProperty(lowerCasedName)
66 ? lowerCasedName
67 : null;
68
@@ -92,8 +92,8 @@ function validateProperty(tagName, name) {
92 function warnInvalidARIAProps(type, props) {
93 const invalidProps = [];
94
95 - for (var key in props) {
96 - var isValid = validateProperty(type, key);
95 + for (const key in props) {
96 + const isValid = validateProperty(type, key);
97 if (!isValid) {
98 invalidProps.push(key);
99 }
packages/react-dom/src/shared/ReactDOMNullInputValuePropHook.js
+2 -2
@@ -8,10 +8,10 @@
8 import {ReactDebugCurrentFrame} from 'shared/ReactGlobalSharedState';
9 import warning from 'fbjs/lib/warning';
10
11 -var didWarnValueNull = false;
11 +let didWarnValueNull = false;
12
13 function getStackAddendum() {
14 - var stack = ReactDebugCurrentFrame.getStackAddendum();
14 + const stack = ReactDebugCurrentFrame.getStackAddendum();
15 return stack != null ? stack : '';
16 }
17
packages/react-dom/src/shared/ReactDOMUnknownPropertyHook.js
+20 -16
@@ -22,24 +22,26 @@ import isCustomComponent from './isCustomComponent';
22 import possibleStandardNames from './possibleStandardNames';
23
24 function getStackAddendum() {
25 - var stack = ReactDebugCurrentFrame.getStackAddendum();
25 + const stack = ReactDebugCurrentFrame.getStackAddendum();
26 return stack != null ? stack : '';
27 }
28
29 +let validateProperty = () => {};
30 +
31 if (__DEV__) {
30 - var warnedProperties = {};
31 - var hasOwnProperty = Object.prototype.hasOwnProperty;
32 - var EVENT_NAME_REGEX = /^on./;
33 - var INVALID_EVENT_NAME_REGEX = /^on[^A-Z]/;
34 - var rARIA = new RegExp('^(aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$');
35 - var rARIACamel = new RegExp('^(aria)[A-Z][' + ATTRIBUTE_NAME_CHAR + ']*$');
32 + const warnedProperties = {};
33 + const hasOwnProperty = Object.prototype.hasOwnProperty;
34 + const EVENT_NAME_REGEX = /^on./;
35 + const INVALID_EVENT_NAME_REGEX = /^on[^A-Z]/;
36 + const rARIA = new RegExp('^(aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$');
37 + const rARIACamel = new RegExp('^(aria)[A-Z][' + ATTRIBUTE_NAME_CHAR + ']*$');
38
37 - var validateProperty = function(tagName, name, value, canUseEventSystem) {
39 + validateProperty = function(tagName, name, value, canUseEventSystem) {
40 if (hasOwnProperty.call(warnedProperties, name) && warnedProperties[name]) {
41 return true;
42 }
43
42 - var lowerCasedName = name.toLowerCase();
44 + const lowerCasedName = name.toLowerCase();
45 if (lowerCasedName === 'onfocusin' || lowerCasedName === 'onfocusout') {
46 warning(
47 false,
@@ -56,7 +58,7 @@ if (__DEV__) {
58 if (registrationNameModules.hasOwnProperty(name)) {
59 return true;
60 }
59 - var registrationName = possibleRegistrationNames.hasOwnProperty(
61 + const registrationName = possibleRegistrationNames.hasOwnProperty(
62 lowerCasedName,
63 )
64 ? possibleRegistrationNames[lowerCasedName]
@@ -157,7 +159,7 @@ if (__DEV__) {
159
160 // Known attributes should match the casing specified in the property config.
161 if (possibleStandardNames.hasOwnProperty(lowerCasedName)) {
160 - var standardName = possibleStandardNames[lowerCasedName];
162 + const standardName = possibleStandardNames[lowerCasedName];
163 if (standardName !== name) {
164 warning(
165 false,
@@ -242,16 +244,18 @@ if (__DEV__) {
244 };
245 }
246
245 -var warnUnknownProperties = function(type, props, canUseEventSystem) {
246 - var unknownProps = [];
247 - for (var key in props) {
248 - var isValid = validateProperty(type, key, props[key], canUseEventSystem);
247 +const warnUnknownProperties = function(type, props, canUseEventSystem) {
248 + const unknownProps = [];
249 + for (const key in props) {
250 + const isValid = validateProperty(type, key, props[key], canUseEventSystem);
251 if (!isValid) {
252 unknownProps.push(key);
253 }
254 }
255
254 - var unknownPropString = unknownProps.map(prop => '`' + prop + '`').join(', ');
256 + const unknownPropString = unknownProps
257 + .map(prop => '`' + prop + '`')
258 + .join(', ');
259 if (unknownProps.length === 1) {
260 warning(
261 false,
packages/react-dom/src/shared/assertValidProps.js
+1 -1
@@ -10,7 +10,7 @@ import warning from 'fbjs/lib/warning';
10
11 import voidElementTags from './voidElementTags';
12
13 -var HTML = '__html';
13 +const HTML = '__html';
14
15 function assertValidProps(tag: string, props: ?Object, getStack: () => string) {
16 if (!props) {
packages/react-dom/src/shared/createMicrosoftUnsafeLocalFunction.js
+1 -1
@@ -10,7 +10,7 @@
10 /**
11 * Create a function which has 'unsafe' privileges (required by windows8 apps)
12 */
13 -var createMicrosoftUnsafeLocalFunction = function(func) {
13 +const createMicrosoftUnsafeLocalFunction = function(func) {
14 if (typeof MSApp !== 'undefined' && MSApp.execUnsafeLocalFunction) {
15 return function(arg0, arg1, arg2, arg3) {
16 MSApp.execUnsafeLocalFunction(function() {
packages/react-dom/src/shared/dangerousStyleValue.js
+1 -1
@@ -27,7 +27,7 @@ function dangerousStyleValue(name, value, isCustomProperty) {
27 // which has lead to a greater discussion about how we're going to
28 // trust URLs moving forward. See #2115901
29
30 - var isEmpty = value == null || typeof value === 'boolean' || value === '';
30 + const isEmpty = value == null || typeof value === 'boolean' || value === '';
31 if (isEmpty) {
32 return '';
33 }
packages/react-dom/src/shared/omittedCloseTags.js
+1 -1
@@ -8,7 +8,7 @@
8 // For HTML, certain tags should omit their close tag. We keep a whitelist for
9 // those special-case tags.
10
11 -var omittedCloseTags = {
11 +const omittedCloseTags = {
12 area: true,
13 base: true,
14 br: true,
packages/react-dom/src/shared/possibleStandardNames.js
+1 -1
@@ -8,7 +8,7 @@
8 // When adding attributes to the HTML or SVG whitelist, be sure to
9 // also add them to this module to ensure casing and incorrect name
10 // warnings.
11 -var possibleStandardNames = {
11 +const possibleStandardNames = {
12 // HTML
13 accept: 'accept',
14 acceptcharset: 'acceptCharset',
packages/react-dom/src/shared/validAriaProperties.js
+1 -1
@@ -5,7 +5,7 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -var ariaProperties = {
8 +const ariaProperties = {
9 'aria-current': 0, // state
10 'aria-details': 0,
11 'aria-disabled': 0, // state
packages/react-dom/src/shared/voidElementTags.js
+1 -1
@@ -10,7 +10,7 @@ import omittedCloseTags from './omittedCloseTags';
10 // For HTML, certain tags cannot have children. This has the same purpose as
11 // `omittedCloseTags` except that `menuitem` should still have its closing tag.
12
13 -var voidElementTags = {
13 +const voidElementTags = {
14 menuitem: true,
15 ...omittedCloseTags,
16 };
packages/react-dom/src/shared/warnValidStyle.js
+12 -12
@@ -9,21 +9,21 @@ import emptyFunction from 'fbjs/lib/emptyFunction';
9 import camelizeStyleName from 'fbjs/lib/camelizeStyleName';
10 import warning from 'fbjs/lib/warning';
11
12 -var warnValidStyle = emptyFunction;
12 +let warnValidStyle = emptyFunction;
13
14 if (__DEV__) {
15 // 'msTransform' is correct, but the other prefixes should be capitalized
16 - var badVendoredStyleNamePattern = /^(?:webkit|moz|o)[A-Z]/;
16 + const badVendoredStyleNamePattern = /^(?:webkit|moz|o)[A-Z]/;
17
18 // style values shouldn't contain a semicolon
19 - var badStyleValueWithSemicolonPattern = /;\s*$/;
19 + const badStyleValueWithSemicolonPattern = /;\s*$/;
20
21 - var warnedStyleNames = {};
22 - var warnedStyleValues = {};
23 - var warnedForNaNValue = false;
24 - var warnedForInfinityValue = false;
21 + const warnedStyleNames = {};
22 + const warnedStyleValues = {};
23 + let warnedForNaNValue = false;
24 + let warnedForInfinityValue = false;
25
26 - var warnHyphenatedStyleName = function(name, getStack) {
26 + const warnHyphenatedStyleName = function(name, getStack) {
27 if (warnedStyleNames.hasOwnProperty(name) && warnedStyleNames[name]) {
28 return;
29 }
@@ -38,7 +38,7 @@ if (__DEV__) {
38 );
39 };
40
41 - var warnBadVendoredStyleName = function(name, getStack) {
41 + const warnBadVendoredStyleName = function(name, getStack) {
42 if (warnedStyleNames.hasOwnProperty(name) && warnedStyleNames[name]) {
43 return;
44 }
@@ -53,7 +53,7 @@ if (__DEV__) {
53 );
54 };
55
56 - var warnStyleValueWithSemicolon = function(name, value, getStack) {
56 + const warnStyleValueWithSemicolon = function(name, value, getStack) {
57 if (warnedStyleValues.hasOwnProperty(value) && warnedStyleValues[value]) {
58 return;
59 }
@@ -69,7 +69,7 @@ if (__DEV__) {
69 );
70 };
71
72 - var warnStyleValueIsNaN = function(name, value, getStack) {
72 + const warnStyleValueIsNaN = function(name, value, getStack) {
73 if (warnedForNaNValue) {
74 return;
75 }
@@ -83,7 +83,7 @@ if (__DEV__) {
83 );
84 };
85
86 - var warnStyleValueIsInfinity = function(name, value, getStack) {
86 + const warnStyleValueIsInfinity = function(name, value, getStack) {
87 if (warnedForInfinityValue) {
88 return;
89 }
packages/react-noop-renderer/index.js
+1 -1
@@ -9,7 +9,7 @@
9
10 'use strict';
11
12 -var ReactNoop = require('./src/ReactNoop');
12 +const ReactNoop = require('./src/ReactNoop');
13
14 // TODO: decide on the top-level export form.
15 // This is hacky but makes it work with both Rollup and Jest.
packages/react-noop-renderer/src/ReactNoop.js
+22 -21
@@ -26,7 +26,7 @@ import expect from 'expect';
26
27 const UPDATE_SIGNAL = {};
28
29 -var scheduledCallback = null;
29 +let scheduledCallback = null;
30
31 type Container = {rootID: string, children: Array<Instance | TextInstance>};
32 type Props = {prop: any, hidden?: boolean};
@@ -38,9 +38,8 @@ type Instance = {|
38 |};
39 type TextInstance = {|text: string, id: number|};
40
41 -var instanceCounter = 0;
42 -
43 -var failInBeginPhase = false;
41 +let instanceCounter = 0;
42 +let failInBeginPhase = false;
43
44 function appendChild(
45 parentInstance: Instance | Container,
@@ -82,7 +81,7 @@ function removeChild(
81
82 let elapsedTimeInMs = 0;
83
85 -var SharedHostConfig = {
84 +let SharedHostConfig = {
85 getRootHostContext() {
86 if (failInBeginPhase) {
87 throw new Error('Error in host config.');
@@ -150,7 +149,7 @@ var SharedHostConfig = {
149 hostContext: Object,
150 internalInstanceHandle: Object,
151 ): TextInstance {
153 - var inst = {text: text, id: instanceCounter++};
152 + const inst = {text: text, id: instanceCounter++};
153 // Hide from unit tests
154 Object.defineProperty(inst, 'id', {value: inst.id, enumerable: false});
155 return inst;
@@ -183,7 +182,7 @@ var SharedHostConfig = {
182 },
183 };
184
186 -var NoopRenderer = ReactFiberReconciler({
185 +const NoopRenderer = ReactFiberReconciler({
186 ...SharedHostConfig,
187 mutation: {
188 commitMount(instance: Instance, type: string, newProps: Props): void {
@@ -219,7 +218,7 @@ var NoopRenderer = ReactFiberReconciler({
218 },
219 });
220
222 -var PersistentNoopRenderer = enablePersistentReconciler
221 +const PersistentNoopRenderer = enablePersistentReconciler
222 ? ReactFiberReconciler({
223 ...SharedHostConfig,
224 persistence: {
@@ -274,20 +273,22 @@ var PersistentNoopRenderer = enablePersistentReconciler
273 })
274 : null;
275
277 -var rootContainers = new Map();
278 -var roots = new Map();
279 -var persistentRoots = new Map();
280 -var DEFAULT_ROOT_ID = '<default>';
276 +const rootContainers = new Map();
277 +const roots = new Map();
278 +const persistentRoots = new Map();
279 +const DEFAULT_ROOT_ID = '<default>';
280
281 let yieldedValues = null;
282
283 +let unitsRemaining;
284 +
285 function* flushUnitsOfWork(n: number): Generator<Array<mixed>, void, void> {
285 - var didStop = false;
286 + let didStop = false;
287 while (!didStop && scheduledCallback !== null) {
287 - var cb = scheduledCallback;
288 + let cb = scheduledCallback;
289 scheduledCallback = null;
290 yieldedValues = null;
290 - var unitsRemaining = n;
291 + unitsRemaining = n;
292 cb({
293 timeRemaining() {
294 if (yieldedValues !== null) {
@@ -309,7 +310,7 @@ function* flushUnitsOfWork(n: number): Generator<Array<mixed>, void, void> {
310 }
311 }
312
312 -var ReactNoop = {
313 +const ReactNoop = {
314 getChildren(rootID: string = DEFAULT_ROOT_ID) {
315 const container = rootContainers.get(rootID);
316 if (container) {
@@ -477,15 +478,15 @@ var ReactNoop = {
478 return;
479 }
480
480 - var bufferedLog = [];
481 + let bufferedLog = [];
482 function log(...args) {
483 bufferedLog.push(...args, '\n');
484 }
485
486 function logHostInstances(children: Array<Instance | TextInstance>, depth) {
486 - for (var i = 0; i < children.length; i++) {
487 - var child = children[i];
488 - var indent = ' '.repeat(depth);
487 + for (let i = 0; i < children.length; i++) {
488 + const child = children[i];
489 + const indent = ' '.repeat(depth);
490 if (typeof child.text === 'string') {
491 log(indent + '- ' + child.text);
492 } else {
@@ -514,7 +515,7 @@ var ReactNoop = {
515 firstUpdate.callback ? 'with callback' : '',
516 '[' + firstUpdate.expirationTime + ']',
517 );
517 - var next;
518 + let next;
519 while ((next = firstUpdate.next)) {
520 log(
521 ' '.repeat(depth + 1) + '~',
packages/react-reconciler/src/ReactChildFiber.js
+10 -5
@@ -47,17 +47,22 @@ import ReactDebugCurrentFiber from './ReactDebugCurrentFiber';
47
48 const {getCurrentFiberStackAddendum} = ReactDebugCurrentFiber;
49
50 +let didWarnAboutMaps;
51 +let ownerHasKeyUseWarning;
52 +let ownerHasFunctionTypeWarning;
53 +let warnForMissingKey = (child: mixed) => {};
54 +
55 if (__DEV__) {
51 - var didWarnAboutMaps = false;
56 + didWarnAboutMaps = false;
57 /**
58 * Warn if there's no key explicitly set on dynamic arrays of children or
59 * object keys are not valid. This allows us to keep track of children between
60 * updates.
61 */
57 - var ownerHasKeyUseWarning = {};
58 - var ownerHasFunctionTypeWarning = {};
62 + ownerHasKeyUseWarning = {};
63 + ownerHasFunctionTypeWarning = {};
64
60 - var warnForMissingKey = (child: mixed) => {
65 + warnForMissingKey = (child: mixed) => {
66 if (child === null || typeof child !== 'object') {
67 return;
68 }
@@ -71,7 +76,7 @@ if (__DEV__) {
76 );
77 child._store.validated = true;
78
74 - var currentComponentErrorInfo =
79 + const currentComponentErrorInfo =
80 'Each child in an array or iterator should have a unique ' +
81 '"key" prop. See https://fb.me/react-warning-keys for ' +
82 'more information.' +
packages/react-reconciler/src/ReactFiber.js
+9 -5
@@ -37,12 +37,14 @@ import getComponentName from 'shared/getComponentName';
37 import {NoWork} from './ReactFiberExpirationTime';
38 import {NoContext, AsyncUpdates} from './ReactTypeOfInternalContext';
39
40 +let hasBadMapPolyfill;
41 +
42 if (__DEV__) {
41 - var hasBadMapPolyfill = false;
43 + hasBadMapPolyfill = false;
44 try {
43 - var nonExtensibleObject = Object.preventExtensions({});
44 - var testMap = new Map([[nonExtensibleObject, null]]);
45 - var testSet = new Set([nonExtensibleObject]);
45 + const nonExtensibleObject = Object.preventExtensions({});
46 + const testMap = new Map([[nonExtensibleObject, null]]);
47 + const testSet = new Set([nonExtensibleObject]);
48 // This is necessary for Rollup to not consider these unused.
49 // https://github.com/rollup/rollup/issues/1771
50 // TODO: we can remove these if Rollup fixes the bug.
@@ -149,8 +151,10 @@ export type Fiber = {|
151 _debugIsCurrentlyTiming?: boolean,
152 |};
153
154 +let debugCounter;
155 +
156 if (__DEV__) {
153 - var debugCounter = 1;
157 + debugCounter = 1;
158 }
159
160 function FiberNode(
packages/react-reconciler/src/ReactFiberBeginWork.js
+3 -1
@@ -60,8 +60,10 @@ import {
60 } from './ReactFiberContext';
61 import {NoWork, Never} from './ReactFiberExpirationTime';
62
63 +let warnedAboutStatelessRefs;
64 +
65 if (__DEV__) {
64 - var warnedAboutStatelessRefs = {};
66 + warnedAboutStatelessRefs = {};
67 }
68
69 export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
packages/react-reconciler/src/ReactFiberClassComponent.js
+5 -2
@@ -40,10 +40,13 @@ import {hasContextChanged} from './ReactFiberContext';
40 const fakeInternalInstance = {};
41 const isArray = Array.isArray;
42
43 +let didWarnAboutStateAssignmentForComponent;
44 +let warnOnInvalidCallback;
45 +
46 if (__DEV__) {
44 - var didWarnAboutStateAssignmentForComponent = {};
47 + didWarnAboutStateAssignmentForComponent = {};
48
46 - var warnOnInvalidCallback = function(callback: mixed, callerName: string) {
49 + warnOnInvalidCallback = function(callback: mixed, callerName: string) {
50 warning(
51 callback === null || typeof callback === 'function',
52 '%s(...): Expected the last optional `callback` argument to be a ' +
packages/react-reconciler/src/ReactFiberCommitWork.js
+3 -1
@@ -271,11 +271,13 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
271 }
272 }
273
274 + let emptyPortalContainer;
275 +
276 if (!mutation) {
277 let commitContainer;
278 if (persistence) {
279 const {replaceContainerChildren, createContainerChildSet} = persistence;
278 - var emptyPortalContainer = function(current: Fiber) {
280 + emptyPortalContainer = function(current: Fiber) {
281 const portal: {containerInfo: C, pendingChildren: CC} =
282 current.stateNode;
283 const {containerInfo} = portal;
packages/react-reconciler/src/ReactFiberContext.js
+3 -1
@@ -22,8 +22,10 @@ import {createCursor, pop, push} from './ReactFiberStack';
22 import ReactDebugCurrentFiber from './ReactDebugCurrentFiber';
23 import {startPhaseTimer, stopPhaseTimer} from './ReactDebugFiberPerf';
24
25 +let warnedAboutMissingGetChildContext;
26 +
27 if (__DEV__) {
26 - var warnedAboutMissingGetChildContext = {};
28 + warnedAboutMissingGetChildContext = {};
29 }
30
31 // A cursor to the current merged context object on the stack.
packages/react-reconciler/src/ReactFiberReconciler.js
+3 -1
@@ -34,8 +34,10 @@ import {insertUpdateIntoFiber} from './ReactFiberUpdateQueue';
34 import ReactFiberInstrumentation from './ReactFiberInstrumentation';
35 import ReactDebugCurrentFiber from './ReactDebugCurrentFiber';
36
37 +let didWarnAboutNestedUpdates;
38 +
39 if (__DEV__) {
38 - var didWarnAboutNestedUpdates = false;
40 + didWarnAboutNestedUpdates = false;
41 }
42
43 export type Deadline = {
packages/react-reconciler/src/ReactFiberScheduler.js
+11 -6
@@ -99,13 +99,18 @@ export type HandleErrorInfo = {
99 componentStack: string,
100 };
101
102 +let didWarnAboutStateTransition;
103 +let didWarnSetStateChildContext;
104 +let warnAboutUpdateOnUnmounted;
105 +let warnAboutInvalidUpdates;
106 +
107 if (__DEV__) {
103 - var didWarnAboutStateTransition = false;
104 - var didWarnSetStateChildContext = false;
105 - var didWarnStateUpdateForUnmountedComponent = {};
108 + didWarnAboutStateTransition = false;
109 + didWarnSetStateChildContext = false;
110 + const didWarnStateUpdateForUnmountedComponent = {};
111
107 - var warnAboutUpdateOnUnmounted = function(fiber: Fiber) {
108 - var componentName = getComponentName(fiber) || 'ReactClass';
112 + warnAboutUpdateOnUnmounted = function(fiber: Fiber) {
113 + const componentName = getComponentName(fiber) || 'ReactClass';
114 if (didWarnStateUpdateForUnmountedComponent[componentName]) {
115 return;
116 }
@@ -120,7 +125,7 @@ if (__DEV__) {
125 didWarnStateUpdateForUnmountedComponent[componentName] = true;
126 };
127
123 - var warnAboutInvalidUpdates = function(instance: React$Component<any>) {
128 + warnAboutInvalidUpdates = function(instance: React$Component<any>) {
129 switch (ReactDebugCurrentFiber.phase) {
130 case 'getChildContext':
131 if (didWarnSetStateChildContext) {
packages/react-reconciler/src/ReactFiberStack.js
+3 -1
@@ -17,8 +17,10 @@ export type StackCursor<T> = {
17
18 const valueStack: Array<any> = [];
19
20 +let fiberStack: Array<Fiber | null>;
21 +
22 if (__DEV__) {
21 - var fiberStack: Array<Fiber | null> = [];
23 + fiberStack = [];
24 }
25
26 let index = -1;
packages/react-reconciler/src/ReactFiberUpdateQueue.js
+3 -1
@@ -18,8 +18,10 @@ import warning from 'fbjs/lib/warning';
18
19 import {NoWork} from './ReactFiberExpirationTime';
20
21 +let didWarnUpdateInsideUpdate;
22 +
23 if (__DEV__) {
22 - var didWarnUpdateInsideUpdate = false;
24 + didWarnUpdateInsideUpdate = false;
25 }
26
27 type PartialState<State, Props> =
packages/react-reconciler/src/__tests__/ReactIncrementalTriangle-test.js
+2 -1
@@ -266,8 +266,9 @@ describe('ReactIncrementalTriangle', () => {
266 let expectedCounterAtEnd = app.state.counter;
267
268 let activeTriangle = null;
269 + let action;
270 while (true) {
270 - var action = yield;
271 + action = yield;
272 if (action === STOP) {
273 break;
274 }
packages/react/src/ReactElementValidator.js
+13 -5
@@ -23,12 +23,20 @@ import ReactCurrentOwner from './ReactCurrentOwner';
23 import {isValidElement, createElement, cloneElement} from './ReactElement';
24 import ReactDebugCurrentFrame from './ReactDebugCurrentFrame';
25
26 +let currentlyValidatingElement;
27 +let propTypesMisspellWarningShown;
28 +
29 +let getDisplayName = () => {};
30 +let getStackAddendum = () => {};
31 +
32 +let VALID_FRAGMENT_PROPS;
33 +
34 if (__DEV__) {
27 - var currentlyValidatingElement = null;
35 + currentlyValidatingElement = null;
36
29 - var propTypesMisspellWarningShown = false;
37 + propTypesMisspellWarningShown = false;
38
31 - var getDisplayName = function(element): string {
39 + getDisplayName = function(element): string {
40 if (element == null) {
41 return '#empty';
42 } else if (typeof element === 'string' || typeof element === 'number') {
@@ -42,7 +50,7 @@ if (__DEV__) {
50 }
51 };
52
45 - var getStackAddendum = function(): string {
53 + getStackAddendum = function(): string {
54 let stack = '';
55 if (currentlyValidatingElement) {
56 const name = getDisplayName(currentlyValidatingElement);
@@ -57,7 +65,7 @@ if (__DEV__) {
65 return stack;
66 };
67
60 - var VALID_FRAGMENT_PROPS = new Map([['children', true], ['key', true]]);
68 + VALID_FRAGMENT_PROPS = new Map([['children', true], ['key', true]]);
69 }
70
71 function getDeclarationErrorAddendum() {
packages/react/src/__tests__/ReactTypeScriptClass-test.ts
+14 -14
@@ -15,9 +15,9 @@ import PropTypes = require('prop-types');
15
16 // Before Each
17
18 -var container;
19 -var attachedListener = null;
20 -var renderedName = null;
18 +let container;
19 +let attachedListener = null;
20 +let renderedName = null;
21
22 class Inner extends React.Component {
23 getName() {
@@ -31,7 +31,7 @@ class Inner extends React.Component {
31 }
32
33 function test(element, expectedTag, expectedClassName) {
34 - var instance = ReactDOM.render(element, container);
34 + const instance = ReactDOM.render(element, container);
35 expect(container.firstChild).not.toBeNull();
36 expect(container.firstChild.tagName).toBe(expectedTag);
37 expect(container.firstChild.className).toBe(expectedClassName);
@@ -93,7 +93,7 @@ class StateBasedOnContext extends React.Component {
93 className: this.context.className
94 };
95 render() {
96 - var Tag = this.state.tag;
96 + const Tag = this.state.tag;
97 return React.createElement(Tag, {className: this.state.className});
98 }
99 }
@@ -112,7 +112,7 @@ class ProvideChildContextTypes extends React.Component {
112 }
113
114 // it renders only once when setting state in componentWillMount
115 -var renderCount = 0;
115 +let renderCount = 0;
116 class RenderOnce extends React.Component {
117 state = {
118 bar: this.props.initialValue
@@ -205,7 +205,7 @@ class ForceUpdateWithNoState extends React.Component {
205 }
206
207 // it will call all the normal life cycle methods
208 -var lifeCycles = [];
208 +let lifeCycles = [];
209 class NormalLifeCycles extends React.Component {
210 props : any;
211 state = {};
@@ -238,8 +238,8 @@ class NormalLifeCycles extends React.Component {
238
239 // warns when classic properties are defined on the instance,
240 // but does not invoke them.
241 -var getInitialStateWasCalled = false;
242 -var getDefaultPropsWasCalled = false;
241 +let getInitialStateWasCalled = false;
242 +let getDefaultPropsWasCalled = false;
243 class ClassicProperties extends React.Component {
244 contextTypes = {};
245 propTypes = {};
@@ -342,7 +342,7 @@ describe('ReactTypeScriptClass', function() {
342 });
343
344 it('renders based on state using props in the constructor', function() {
345 - var instance = test(
345 + const instance = test(
346 React.createElement(StateBasedOnProps, {initialValue: 'foo'}),
347 'DIV',
348 'foo'
@@ -525,7 +525,7 @@ describe('ReactTypeScriptClass', function() {
525
526 it('should throw AND warn when trying to access classic APIs', function() {
527 spyOnDev(console, 'warn');
528 - var instance = test(
528 + const instance = test(
529 React.createElement(Inner, {name: 'foo'}),
530 'DIV','foo'
531 );
@@ -547,17 +547,17 @@ describe('ReactTypeScriptClass', function() {
547 });
548
549 it('supports classic refs', function() {
550 - var instance = test(React.createElement(ClassicRefs), 'DIV', 'foo');
550 + const instance = test(React.createElement(ClassicRefs), 'DIV', 'foo');
551 expect(instance.refs.inner.getName()).toBe('foo');
552 });
553
554 it('supports drilling through to the DOM using findDOMNode', function() {
555 - var instance = test(
555 + const instance = test(
556 React.createElement(Inner, {name: 'foo'}),
557 'DIV',
558 'foo'
559 );
560 - var node = ReactDOM.findDOMNode(instance);
560 + const node = ReactDOM.findDOMNode(instance);
561 expect(node).toBe(container.firstChild);
562 });
563
packages/react/src/__tests__/testDefinitions/PropTypes.d.ts
+1 -1
@@ -13,5 +13,5 @@
13 */
14
15 declare module 'prop-types' {
16 - export var string : any;
16 + export let string : any;
17 }
packages/react/src/__tests__/testDefinitions/React.d.ts
+1 -1
@@ -22,6 +22,6 @@ declare module 'react' {
22 setState(partial : any, callback ?: any) : void;
23 forceUpdate(callback ?: any) : void;
24 }
25 - export var PropTypes : any;
25 + export let PropTypes : any;
26 export function createElement(tag : any, props ?: any, ...children : any[]) : any
27 }