MCPcopy
hub / github.com/facebook/react / describeObjectForErrorMessage

Function describeObjectForErrorMessage

packages/shared/ReactSerializationErrors.js:177–321  ·  view source on GitHub ↗
(
  objectOrArray: {+[key: string | number]: mixed, ...} | $ReadOnlyArray<mixed>,
  expandedName?: string,
)

Source from the content-addressed store, hash-verified

175}
176
177export function describeObjectForErrorMessage(
178 objectOrArray: {+[key: string | number]: mixed, ...} | $ReadOnlyArray<mixed>,
179 expandedName?: string,
180): string {
181 const objKind = objectName(objectOrArray);
182 if (objKind !== 'Object' && objKind !== 'Array') {
183 return objKind;
184 }
185 let str = '';
186 let start = -1;
187 let length = 0;
188 if (isArray(objectOrArray)) {
189 if (__DEV__ && jsxChildrenParents.has(objectOrArray)) {
190 // Print JSX Children
191 const type = jsxChildrenParents.get(objectOrArray);
192 str = '<' + describeElementType(type) + '>';
193 const array: $ReadOnlyArray<mixed> = objectOrArray;
194 for (let i = 0; i < array.length; i++) {
195 const value = array[i];
196 let substr;
197 if (typeof value === 'string') {
198 substr = value;
199 } else if (typeof value === 'object' && value !== null) {
200 substr = '{' + describeObjectForErrorMessage(value) + '}';
201 } else {
202 substr = '{' + describeValueForErrorMessage(value) + '}';
203 }
204 if ('' + i === expandedName) {
205 start = str.length;
206 length = substr.length;
207 str += substr;
208 } else if (substr.length < 15 && str.length + substr.length < 40) {
209 str += substr;
210 } else {
211 str += '{...}';
212 }
213 }
214 str += '</' + describeElementType(type) + '>';
215 } else {
216 // Print Array
217 str = '[';
218 const array: $ReadOnlyArray<mixed> = objectOrArray;
219 for (let i = 0; i < array.length; i++) {
220 if (i > 0) {
221 str += ', ';
222 }
223 const value = array[i];
224 let substr;
225 if (typeof value === 'object' && value !== null) {
226 substr = describeObjectForErrorMessage(value);
227 } else {
228 substr = describeValueForErrorMessage(value);
229 }
230 if ('' + i === expandedName) {
231 start = str.length;
232 length = substr.length;
233 str += substr;
234 } else if (substr.length < 10 && str.length + substr.length < 40) {

Callers 5

resolveToJSONFunction · 0.90
encodeErrorForBoundaryFunction · 0.90
createTaskFunction · 0.90
renderModelDestructiveFunction · 0.90
emitErrorChunkFunction · 0.90

Calls 9

isArrayFunction · 0.85
describeElementTypeFunction · 0.85
describeClientReferenceFunction · 0.85
keysMethod · 0.80
objectNameFunction · 0.70
hasMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected