Home / File/ ReactClientConsoleConfigPlain.js — react Source File

ReactClientConsoleConfigPlain.js — react Source File

Architecture documentation for ReactClientConsoleConfigPlain.js, a javascript file in the react codebase.

Entity Profile

Relationship Graph

Source Code

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow
 */

// Keep in sync with ReactServerConsoleConfig
const badgeFormat = '[%s]';
const pad = ' ';

const bind = Function.prototype.bind;

export function bindToConsole(
  methodName: string,
  args: Array<any>,
  badgeName: string,
): () => any {
  let offset = 0;
  switch (methodName) {
    case 'dir':
    case 'dirxml':
    case 'groupEnd':
    case 'table': {
      // These methods cannot be colorized because they don't take a formatting string.
      // $FlowFixMe
      return bind.apply(console[methodName], [console].concat(args)); // eslint-disable-line react-internal/no-production-logging
    }
    case 'assert': {
      // assert takes formatting options as the second argument.
      offset = 1;
    }
  }

  const newArgs = args.slice(0);
  if (typeof newArgs[offset] === 'string') {
    newArgs.splice(
      offset,
      1,
      badgeFormat + ' ' + newArgs[offset],
      pad + badgeName + pad,
    );
  } else {
    newArgs.splice(offset, 0, badgeFormat, pad + badgeName + pad);
  }

  // The "this" binding in the "bind";
  newArgs.unshift(console);

  // $FlowFixMe
  return bind.apply(console[methodName], newArgs); // eslint-disable-line react-internal/no-production-logging
}

Domain

Subdomains

Functions

Frequently Asked Questions

What does ReactClientConsoleConfigPlain.js do?
ReactClientConsoleConfigPlain.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in ReactClientConsoleConfigPlain.js?
ReactClientConsoleConfigPlain.js defines 1 function(s): bindToConsole.
Where is ReactClientConsoleConfigPlain.js in the architecture?
ReactClientConsoleConfigPlain.js is located at packages/react-client/src/ReactClientConsoleConfigPlain.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-client/src).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free