@@ -381,36 +381,26 @@ function resolve(
381
381
child: mixed ,
382
382
context : Object ,
383
383
| } {
384
- let element : ReactElement ;
385
-
386
- let Component ;
387
- let publicContext ;
388
- let inst , queue , replace ;
389
- let updater ;
390
-
391
- let initialState ;
392
- let oldQueue , oldReplace ;
393
- let nextState , dontMutate ;
394
- let partial , partialState ;
395
-
396
- let childContext ;
397
- let childContextTypes , contextKey ;
398
-
399
384
while ( React . isValidElement ( child ) ) {
400
385
// Safe because we just checked it's an element.
401
- element = ( ( child : any ) : ReactElement ) ;
386
+ let element : ReactElement = ( child : any ) ;
387
+ let Component = element . type ;
402
388
if ( __DEV__ ) {
403
389
pushElementToDebugStack ( element ) ;
404
390
}
405
- Component = element . type ;
406
391
if ( typeof Component !== 'function' ) {
407
392
break ;
408
393
}
409
- publicContext = processContext ( Component , context ) ;
394
+ processChild ( element , Component ) ;
395
+ }
396
+
397
+ // Extra closure so queue and replace can be captured properly
398
+ function processChild ( element , Component ) {
399
+ let publicContext = processContext ( Component , context ) ;
410
400
411
- queue = [ ] ;
412
- replace = false ;
413
- updater = {
401
+ let queue = [ ] ;
402
+ let replace = false ;
403
+ let updater = {
414
404
isMounted : function ( publicInstance ) {
415
405
return false ;
416
406
} ,
@@ -433,6 +423,7 @@ function resolve(
433
423
} ,
434
424
} ;
435
425
426
+ let inst ;
436
427
if ( shouldConstruct ( Component ) ) {
437
428
inst = new Component ( element . props , publicContext , updater ) ;
438
429
@@ -453,7 +444,7 @@ function resolve(
453
444
}
454
445
}
455
446
456
- partialState = Component . getDerivedStateFromProps . call (
447
+ let partialState = Component . getDerivedStateFromProps . call (
457
448
null ,
458
449
element . props ,
459
450
inst . state ,
@@ -502,15 +493,15 @@ function resolve(
502
493
if ( inst == null || inst . render == null ) {
503
494
child = inst ;
504
495
validateRenderResult ( child , Component ) ;
505
- continue ;
496
+ return ;
506
497
}
507
498
}
508
499
509
500
inst . props = element . props ;
510
501
inst . context = publicContext ;
511
502
inst . updater = updater ;
512
503
513
- initialState = inst . state ;
504
+ let initialState = inst . state ;
514
505
if ( initialState === undefined ) {
515
506
inst . state = initialState = null ;
516
507
}
@@ -558,19 +549,19 @@ function resolve(
558
549
inst . UNSAFE_componentWillMount ( ) ;
559
550
}
560
551
if ( queue . length ) {
561
- oldQueue = queue ;
562
- oldReplace = replace ;
552
+ let oldQueue = queue ;
553
+ let oldReplace = replace ;
563
554
queue = null ;
564
555
replace = false ;
565
556
566
557
if ( oldReplace && oldQueue . length === 1 ) {
567
558
inst . state = oldQueue [ 0 ] ;
568
559
} else {
569
- nextState = oldReplace ? oldQueue [ 0 ] : inst . state ;
570
- dontMutate = true ;
560
+ let nextState = oldReplace ? oldQueue [ 0 ] : inst . state ;
561
+ let dontMutate = true ;
571
562
for ( let i = oldReplace ? 1 : 0 ; i < oldQueue . length ; i ++ ) {
572
- partial = oldQueue [ i ] ;
573
- partialState =
563
+ let partial = oldQueue [ i ] ;
564
+ let partialState =
574
565
typeof partial === 'function'
575
566
? partial . call ( inst , nextState , element . props , publicContext )
576
567
: partial ;
@@ -600,11 +591,12 @@ function resolve(
600
591
}
601
592
validateRenderResult ( child , Component ) ;
602
593
594
+ let childContext ;
603
595
if ( typeof inst . getChildContext === 'function' ) {
604
- childContextTypes = Component . childContextTypes ;
596
+ let childContextTypes = Component . childContextTypes ;
605
597
if ( typeof childContextTypes === 'object' ) {
606
598
childContext = inst . getChildContext ( ) ;
607
- for ( contextKey in childContext ) {
599
+ for ( let contextKey in childContext ) {
608
600
invariant (
609
601
contextKey in childContextTypes ,
610
602
'%s.getChildContext(): key "%s" is not defined in childContextTypes.' ,
0 commit comments