@@ -19,8 +19,8 @@ import {
1919import { isValidElement , cloneAndReplaceKey } from './ReactElement' ;
2020import ReactDebugCurrentFrame from './ReactDebugCurrentFrame' ;
2121
22- var SEPARATOR = '.' ;
23- var SUBSEPARATOR = ':' ;
22+ const SEPARATOR = '.' ;
23+ const SUBSEPARATOR = ':' ;
2424
2525/**
2626 * Escape and wrap key so it is safe to use as a reactid
@@ -29,12 +29,12 @@ var SUBSEPARATOR = ':';
2929 * @return {string } the escaped key.
3030 */
3131function escape ( key ) {
32- var escapeRegex = / [ = : ] / g;
33- var escaperLookup = {
32+ const escapeRegex = / [ = : ] / g;
33+ const escaperLookup = {
3434 '=' : '=0' ,
3535 ':' : '=2' ,
3636 } ;
37- var escapedString = ( '' + key ) . replace ( escapeRegex , function ( match ) {
37+ const escapedString = ( '' + key ) . replace ( escapeRegex , function ( match ) {
3838 return escaperLookup [ match ] ;
3939 } ) ;
4040
@@ -46,23 +46,23 @@ function escape(key) {
4646 * pattern.
4747 */
4848
49- var didWarnAboutMaps = false ;
49+ let didWarnAboutMaps = false ;
5050
51- var userProvidedKeyEscapeRegex = / \/ + / g;
51+ const userProvidedKeyEscapeRegex = / \/ + / g;
5252function escapeUserProvidedKey ( text ) {
5353 return ( '' + text ) . replace ( userProvidedKeyEscapeRegex , '$&/' ) ;
5454}
5555
56- var POOL_SIZE = 10 ;
57- var traverseContextPool = [ ] ;
56+ const POOL_SIZE = 10 ;
57+ const traverseContextPool = [ ] ;
5858function getPooledTraverseContext (
5959 mapResult ,
6060 keyPrefix ,
6161 mapFunction ,
6262 mapContext ,
6363) {
6464 if ( traverseContextPool . length ) {
65- var traverseContext = traverseContextPool . pop ( ) ;
65+ const traverseContext = traverseContextPool . pop ( ) ;
6666 traverseContext . result = mapResult ;
6767 traverseContext . keyPrefix = keyPrefix ;
6868 traverseContext . func = mapFunction ;
@@ -105,7 +105,7 @@ function traverseAllChildrenImpl(
105105 callback ,
106106 traverseContext ,
107107) {
108- var type = typeof children ;
108+ const type = typeof children ;
109109
110110 if ( type === 'undefined' || type === 'boolean' ) {
111111 // All of the above are perceived as null.
@@ -144,13 +144,14 @@ function traverseAllChildrenImpl(
144144 return 1 ;
145145 }
146146
147- var child ;
148- var nextName ;
149- var subtreeCount = 0 ; // Count of children found in the current subtree.
150- var nextNamePrefix = nameSoFar === '' ? SEPARATOR : nameSoFar + SUBSEPARATOR ;
147+ let child ;
148+ let nextName ;
149+ let subtreeCount = 0 ; // Count of children found in the current subtree.
150+ const nextNamePrefix =
151+ nameSoFar === '' ? SEPARATOR : nameSoFar + SUBSEPARATOR ;
151152
152153 if ( Array . isArray ( children ) ) {
153- for ( var i = 0 ; i < children . length ; i ++ ) {
154+ for ( let i = 0 ; i < children . length ; i ++ ) {
154155 child = children [ i ] ;
155156 nextName = nextNamePrefix + getComponentKey ( child , i ) ;
156157 subtreeCount += traverseAllChildrenImpl (
@@ -161,7 +162,7 @@ function traverseAllChildrenImpl(
161162 ) ;
162163 }
163164 } else {
164- var iteratorFn = getIteratorFn ( children ) ;
165+ const iteratorFn = getIteratorFn ( children ) ;
165166 if ( typeof iteratorFn === 'function' ) {
166167 if ( __DEV__ ) {
167168 // Warn about using Maps as children
@@ -177,9 +178,9 @@ function traverseAllChildrenImpl(
177178 }
178179 }
179180
180- var iterator = iteratorFn . call ( children ) ;
181- var step ;
182- var ii = 0 ;
181+ const iterator = iteratorFn . call ( children ) ;
182+ let step ;
183+ let ii = 0 ;
183184 while ( ! ( step = iterator . next ( ) ) . done ) {
184185 child = step . value ;
185186 nextName = nextNamePrefix + getComponentKey ( child , ii ++ ) ;
@@ -191,14 +192,14 @@ function traverseAllChildrenImpl(
191192 ) ;
192193 }
193194 } else if ( type === 'object' ) {
194- var addendum = '' ;
195+ let addendum = '' ;
195196 if ( __DEV__ ) {
196197 addendum =
197198 ' If you meant to render a collection of children, use an array ' +
198199 'instead.' +
199200 ReactDebugCurrentFrame . getStackAddendum ( ) ;
200201 }
201- var childrenString = '' + children ;
202+ const childrenString = '' + children ;
202203 invariant (
203204 false ,
204205 'Objects are not valid as a React child (found: %s).%s' ,
@@ -260,7 +261,7 @@ function getComponentKey(component, index) {
260261}
261262
262263function forEachSingleChild ( bookKeeping , child , name ) {
263- var { func, context} = bookKeeping ;
264+ const { func, context} = bookKeeping ;
264265 func . call ( context , child , bookKeeping . count ++ ) ;
265266}
266267
@@ -280,7 +281,7 @@ function forEachChildren(children, forEachFunc, forEachContext) {
280281 if ( children == null ) {
281282 return children ;
282283 }
283- var traverseContext = getPooledTraverseContext (
284+ const traverseContext = getPooledTraverseContext (
284285 null ,
285286 null ,
286287 forEachFunc ,
@@ -291,9 +292,9 @@ function forEachChildren(children, forEachFunc, forEachContext) {
291292}
292293
293294function mapSingleChildIntoContext ( bookKeeping , child , childKey ) {
294- var { result, keyPrefix, func, context} = bookKeeping ;
295+ const { result, keyPrefix, func, context} = bookKeeping ;
295296
296- var mappedChild = func . call ( context , child , bookKeeping . count ++ ) ;
297+ let mappedChild = func . call ( context , child , bookKeeping . count ++ ) ;
297298 if ( Array . isArray ( mappedChild ) ) {
298299 mapIntoWithKeyPrefixInternal (
299300 mappedChild ,
@@ -319,11 +320,11 @@ function mapSingleChildIntoContext(bookKeeping, child, childKey) {
319320}
320321
321322function mapIntoWithKeyPrefixInternal ( children , array , prefix , func , context ) {
322- var escapedPrefix = '' ;
323+ let escapedPrefix = '' ;
323324 if ( prefix != null ) {
324325 escapedPrefix = escapeUserProvidedKey ( prefix ) + '/' ;
325326 }
326- var traverseContext = getPooledTraverseContext (
327+ const traverseContext = getPooledTraverseContext (
327328 array ,
328329 escapedPrefix ,
329330 func ,
@@ -350,7 +351,7 @@ function mapChildren(children, func, context) {
350351 if ( children == null ) {
351352 return children ;
352353 }
353- var result = [ ] ;
354+ const result = [ ] ;
354355 mapIntoWithKeyPrefixInternal ( children , result , null , func , context ) ;
355356 return result ;
356357}
@@ -375,7 +376,7 @@ function countChildren(children, context) {
375376 * See https://reactjs.org/docs/react-api.html#react.children.toarray
376377 */
377378function toArray ( children ) {
378- var result = [ ] ;
379+ const result = [ ] ;
379380 mapIntoWithKeyPrefixInternal (
380381 children ,
381382 result ,
0 commit comments