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. 
    
  8. // This refers to a WWW module.
    
  9. const warningWWW = require('warning');
    
  10. 
    
  11. let suppressWarning = false;
    
  12. export function setSuppressWarning(newSuppressWarning) {
    
  13.   if (__DEV__) {
    
  14.     suppressWarning = newSuppressWarning;
    
  15.   }
    
  16. }
    
  17. 
    
  18. export function warn(format, ...args) {
    
  19.   if (__DEV__) {
    
  20.     if (!suppressWarning) {
    
  21.       printWarning('warn', format, args);
    
  22.     }
    
  23.   }
    
  24. }
    
  25. 
    
  26. export function error(format, ...args) {
    
  27.   if (__DEV__) {
    
  28.     if (!suppressWarning) {
    
  29.       printWarning('error', format, args);
    
  30.     }
    
  31.   }
    
  32. }
    
  33. 
    
  34. function printWarning(level, format, args) {
    
  35.   if (__DEV__) {
    
  36.     const React = require('react');
    
  37.     const ReactSharedInternals =
    
  38.       React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
    
  39.     // Defensive in case this is fired before React is initialized.
    
  40.     if (ReactSharedInternals != null) {
    
  41.       const ReactDebugCurrentFrame =
    
  42.         ReactSharedInternals.ReactDebugCurrentFrame;
    
  43.       const stack = ReactDebugCurrentFrame.getStackAddendum();
    
  44.       if (stack !== '') {
    
  45.         format += '%s';
    
  46.         args.push(stack);
    
  47.       }
    
  48.     }
    
  49.     // TODO: don't ignore level and pass it down somewhere too.
    
  50.     args.unshift(format);
    
  51.     args.unshift(false);
    
  52.     warningWWW.apply(null, args);
    
  53.   }
    
  54. }