(
this:
| {+[key: string | number]: ReactServerValue}
| $ReadOnlyArray<ReactServerValue>,
key: string,
value: ReactServerValue,
)
| 355 | } |
| 356 | |
| 357 | function resolveToJSON( |
| 358 | this: |
| 359 | | {+[key: string | number]: ReactServerValue} |
| 360 | | $ReadOnlyArray<ReactServerValue>, |
| 361 | key: string, |
| 362 | value: ReactServerValue, |
| 363 | ): ReactJSONValue { |
| 364 | const parent = this; |
| 365 | |
| 366 | if (__DEV__) { |
| 367 | if (key === __PROTO__) { |
| 368 | console.error( |
| 369 | class="st">'Expected not to serialize an object with own property `__proto__`. When parsed this property will be omitted.%s', |
| 370 | describeObjectForErrorMessage(parent, key), |
| 371 | ); |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | class="cm">// Make sure that `parent[key]` wasn't JSONified before `value` was passed to us |
| 376 | if (__DEV__) { |
| 377 | class="cm">// $FlowFixMe[incompatible-use] |
| 378 | const originalValue = parent[key]; |
| 379 | if ( |
| 380 | typeof originalValue === class="st">'object' && |
| 381 | originalValue !== value && |
| 382 | !(originalValue instanceof Date) |
| 383 | ) { |
| 384 | if (objectName(originalValue) !== class="st">'Object') { |
| 385 | console.error( |
| 386 | class="st">'Only plain objects can be passed to Server Functions from the Client. ' + |
| 387 | class="st">'%s objects are not supported.%s', |
| 388 | objectName(originalValue), |
| 389 | describeObjectForErrorMessage(parent, key), |
| 390 | ); |
| 391 | } else { |
| 392 | console.error( |
| 393 | class="st">'Only plain objects can be passed to Server Functions from the Client. ' + |
| 394 | class="st">'Objects with toJSON methods are not supported. Convert it manually ' + |
| 395 | class="st">'to a simple value before passing it to props.%s', |
| 396 | describeObjectForErrorMessage(parent, key), |
| 397 | ); |
| 398 | } |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | if (value === null) { |
| 403 | return null; |
| 404 | } |
| 405 | |
| 406 | if (typeof value === class="st">'object') { |
| 407 | switch ((value: any).$$typeof) { |
| 408 | case REACT_ELEMENT_TYPE: { |
| 409 | if (temporaryReferences !== undefined && key.indexOf(class="st">':') === -1) { |
| 410 | class="cm">// TODO: If the property name contains a colon, we don't dedupe. Escape instead. |
| 411 | const parentReference = writtenObjects.get(parent); |
| 412 | if (parentReference !== undefined) { |
| 413 | class="cm">// If the parent has a reference, we can refer to this object indirectly |
| 414 | class="cm">// through the property name inside that parent. |
nothing calls this directly
no test coverage detected