@@ -11,6 +11,8 @@ import {OMITTED_PROP_ERROR} from 'shared/ReactFlightPropertyAccess';
1111
1212import hasOwnProperty from 'shared/hasOwnProperty' ;
1313import isArray from 'shared/isArray' ;
14+ import { REACT_ELEMENT_TYPE } from './ReactSymbols' ;
15+ import getComponentNameFromType from './getComponentNameFromType' ;
1416
1517const EMPTY_ARRAY = 0 ;
1618const COMPLEX_ARRAY = 1 ;
@@ -73,6 +75,55 @@ export function addValueToProperties(
7375 desc = 'null' ;
7476 break ;
7577 } else {
78+ if ( value . $$typeof === REACT_ELEMENT_TYPE ) {
79+ // JSX
80+ const typeName = getComponentNameFromType ( value . type ) || '\u2026' ;
81+ const key = value . key ;
82+ const props = value . props ;
83+ const propsKeys = Object . keys ( props ) ;
84+ const propsLength = propsKeys . length ;
85+ if ( key == null && propsLength === 0 ) {
86+ desc = '<' + typeName + ' />' ;
87+ break ;
88+ }
89+ if (
90+ indent < 3 ||
91+ ( propsLength === 1 && propsKeys [ 0 ] === 'children' && key == null )
92+ ) {
93+ desc = '<' + typeName + ' \u2026 />' ;
94+ break ;
95+ }
96+ properties . push ( [
97+ '\xa0\xa0' . repeat ( indent ) + propertyName ,
98+ '<' + typeName ,
99+ ] ) ;
100+ let hasChildren = false ;
101+ for ( const propKey in props ) {
102+ if ( propKey === 'children' ) {
103+ if (
104+ props . children != null &&
105+ ( ! isArray ( props . children ) || props . children . length > 0 )
106+ ) {
107+ hasChildren = true ;
108+ }
109+ } else if (
110+ hasOwnProperty . call ( props , propKey ) &&
111+ propKey [ 0 ] !== '_'
112+ ) {
113+ addValueToProperties (
114+ propKey ,
115+ props [ propKey ] ,
116+ properties ,
117+ indent + 1 ,
118+ ) ;
119+ }
120+ }
121+ properties . push ( [
122+ '' ,
123+ hasChildren ? '>\u2026</' + typeName + '>' : '/>' ,
124+ ] ) ;
125+ return ;
126+ }
76127 // $FlowFixMe[method-unbinding]
77128 const objectToString = Object . prototype . toString . call ( value ) ;
78129 let objectName = objectToString . slice ( 8 , objectToString . length - 1 ) ;
@@ -99,7 +150,7 @@ export function addValueToProperties(
99150 }
100151 properties . push ( [
101152 '\xa0\xa0' . repeat ( indent ) + propertyName ,
102- objectName === 'Object' ? '' : objectName ,
153+ objectName === 'Object' ? ( indent < 3 ? '' : '\u2026' ) : objectName ,
103154 ] ) ;
104155 if ( indent < 3 ) {
105156 addObjectToProperties ( value , properties , indent + 1 ) ;
@@ -115,7 +166,7 @@ export function addValueToProperties(
115166 break ;
116167 case 'string' :
117168 if ( value === OMITTED_PROP_ERROR ) {
118- desc = '...' ;
169+ desc = '\u2026' ; // ellipsis
119170 } else {
120171 desc = JSON . stringify ( value ) ;
121172 }
0 commit comments