Home / File/ formatLocationForDisplay.js — react Source File

formatLocationForDisplay.js — react Source File

Architecture documentation for formatLocationForDisplay.js, a javascript file in the react codebase. 1 imports, 2 dependents.

File javascript BabelCompiler Validation 1 imports 2 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  b2ae7acd_23fc_8be6_1598_6a4162c47a7b["formatLocationForDisplay.js"]
  cf3e3a16_b870_20e1_be29_29ab03c50337["jsc-safe-url"]
  b2ae7acd_23fc_8be6_1598_6a4162c47a7b --> cf3e3a16_b870_20e1_be29_29ab03c50337
  50c39210_7831_dde4_3a12_fc8ea644bc38["InspectedElementSourcePanel.js"]
  50c39210_7831_dde4_3a12_fc8ea644bc38 --> b2ae7acd_23fc_8be6_1598_6a4162c47a7b
  7db6a3fc_5457_73ae_9df6_4bd78494320f["StackTraceView.js"]
  7db6a3fc_5457_73ae_9df6_4bd78494320f --> b2ae7acd_23fc_8be6_1598_6a4162c47a7b
  style b2ae7acd_23fc_8be6_1598_6a4162c47a7b fill:#6366f1,stroke:#818cf8,color:#fff

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
 */

import {toNormalUrl} from 'jsc-safe-url';

// This function is based on describeComponentFrame() in packages/shared/ReactComponentStackFrame
export default function formatLocationForDisplay(
  sourceURL: string,
  line: number,
  column: number,
): string {
  // Metro can return JSC-safe URLs, which have `//&` as a delimiter
  // https://www.npmjs.com/package/jsc-safe-url
  const sanitizedSourceURL = sourceURL.includes('//&')
    ? toNormalUrl(sourceURL)
    : sourceURL;

  // Note: this RegExp doesn't work well with URLs from Metro,
  // which provides bundle URL with query parameters prefixed with /&
  const BEFORE_SLASH_RE = /^(.*)[\\\/]/;

  let nameOnly = sanitizedSourceURL.replace(BEFORE_SLASH_RE, '');

  // In DEV, include code for a common special case:
  // prefer "folder/index.js" instead of just "index.js".
  if (/^index\./.test(nameOnly)) {
    const match = sanitizedSourceURL.match(BEFORE_SLASH_RE);
    if (match) {
      const pathBeforeSlash = match[1];
      if (pathBeforeSlash) {
        const folderName = pathBeforeSlash.replace(BEFORE_SLASH_RE, '');
        nameOnly = folderName + '/' + nameOnly;
      }
    }
  }

  if (line === 0) {
    return nameOnly;
  }

  return `${nameOnly}:${line}`;
}

Domain

Subdomains

Dependencies

  • jsc-safe-url

Frequently Asked Questions

What does formatLocationForDisplay.js do?
formatLocationForDisplay.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 formatLocationForDisplay.js?
formatLocationForDisplay.js defines 1 function(s): formatLocationForDisplay.
What does formatLocationForDisplay.js depend on?
formatLocationForDisplay.js imports 1 module(s): jsc-safe-url.
What files import formatLocationForDisplay.js?
formatLocationForDisplay.js is imported by 2 file(s): InspectedElementSourcePanel.js, StackTraceView.js.
Where is formatLocationForDisplay.js in the architecture?
formatLocationForDisplay.js is located at packages/react-devtools-shared/src/devtools/views/Components/formatLocationForDisplay.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-devtools-shared/src/devtools/views/Components).

Analyze Your Own Codebase

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

Try Supermodel Free