1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and affiliates.
    
  3.  *
    
  4.  * This source code is licensed under the MIT license found in the
    
  5.  * LICENSE file in the root directory of this source tree.
    
  6.  *
    
  7.  * @flow
    
  8.  */
    
  9. 
    
  10. import type {Fiber} from './ReactInternalTypes';
    
  11. 
    
  12. import {getStackByFiberInDevAndProd} from './ReactFiberComponentStack';
    
  13. 
    
  14. export type CapturedValue<T> = {
    
  15.   value: T,
    
  16.   source: Fiber | null,
    
  17.   stack: string | null,
    
  18.   digest: string | null,
    
  19. };
    
  20. 
    
  21. export function createCapturedValueAtFiber<T>(
    
  22.   value: T,
    
  23.   source: Fiber,
    
  24. ): CapturedValue<T> {
    
  25.   // If the value is an error, call this function immediately after it is thrown
    
  26.   // so the stack is accurate.
    
  27.   return {
    
  28.     value,
    
  29.     source,
    
  30.     stack: getStackByFiberInDevAndProd(source),
    
  31.     digest: null,
    
  32.   };
    
  33. }
    
  34. 
    
  35. export function createCapturedValue<T>(
    
  36.   value: T,
    
  37.   digest: ?string,
    
  38.   stack: ?string,
    
  39. ): CapturedValue<T> {
    
  40.   return {
    
  41.     value,
    
  42.     source: null,
    
  43.     stack: stack != null ? stack : null,
    
  44.     digest: digest != null ? digest : null,
    
  45.   };
    
  46. }