@@ -122,32 +122,43 @@ function traverseAllChildrenImpl(
122
122
) {
123
123
var type = typeof children ;
124
124
125
- if ( type === 'undefined' || type === 'boolean' ) {
126
- // All of the above are perceived as null.
127
- children = null ;
128
- }
129
-
130
- if (
131
- children === null ||
132
- type === 'string' ||
133
- type === 'number' ||
134
- // The following is inlined from ReactElement. This means we can optimize
135
- // some checks. React Fiber also inlines this logic for similar purposes.
136
- ( type === 'object' && children . $$typeof === REACT_ELEMENT_TYPE ) ||
137
- ( type === 'object' && children . $$typeof === REACT_CALL_TYPE ) ||
138
- ( type === 'object' && children . $$typeof === REACT_RETURN_TYPE ) ||
139
- ( type === 'object' && children . $$typeof === REACT_PORTAL_TYPE )
140
- ) {
125
+ const invokeCallback = ( ) => {
141
126
callback (
142
127
traverseContext ,
143
128
children ,
144
129
// If it's the only child, treat the name as if it was wrapped in an array
145
130
// so that it's consistent if the number of children grows.
146
131
nameSoFar === '' ? SEPARATOR + getComponentKey ( children , 0 ) : nameSoFar ,
147
132
) ;
133
+ } ;
134
+
135
+ if ( children === null ) {
136
+ invokeCallback ( ) ;
148
137
return 1 ;
149
138
}
150
139
140
+ switch ( type ) {
141
+ // All of the below are perceived as null.
142
+ case 'undefined' :
143
+ case 'boolean' :
144
+ children = null ;
145
+ case 'string' :
146
+ case 'number' :
147
+ invokeCallback ( ) ;
148
+ return 1 ;
149
+ // The following is inlined from ReactElement. This means we can optimize
150
+ // some checks. React Fiber also inlines this logic for similar purposes.
151
+ case 'object' :
152
+ switch ( children . $$typeof ) {
153
+ case REACT_ELEMENT_TYPE :
154
+ case REACT_CALL_TYPE :
155
+ case REACT_RETURN_TYPE :
156
+ case REACT_PORTAL_TYPE :
157
+ invokeCallback ( ) ;
158
+ return 1 ;
159
+ }
160
+ }
161
+
151
162
var child ;
152
163
var nextName ;
153
164
var subtreeCount = 0 ; // Count of children found in the current subtree.
0 commit comments