Home / Class/ SourceMapMetadataConsumer Class — react Architecture

SourceMapMetadataConsumer Class — react Architecture

Architecture documentation for the SourceMapMetadataConsumer class in SourceMapMetadataConsumer.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  c91679b7_c93e_6e95_410e_81e24076c30a["SourceMapMetadataConsumer"]
  5751162b_425a_76d9_4373_4cf5cde09b49["SourceMapMetadataConsumer.js"]
  c91679b7_c93e_6e95_410e_81e24076c30a -->|defined in| 5751162b_425a_76d9_4373_4cf5cde09b49
  4aecfa60_baad_378b_b692_5a3e21b20080["constructor()"]
  c91679b7_c93e_6e95_410e_81e24076c30a -->|method| 4aecfa60_baad_378b_b692_5a3e21b20080
  53395c34_7472_4850_0d26_5722d5c6d970["hookNameFor()"]
  c91679b7_c93e_6e95_410e_81e24076c30a -->|method| 53395c34_7472_4850_0d26_5722d5c6d970
  31b4a475_0699_69a6_a66b_1b98c50a5785["hasHookMap()"]
  c91679b7_c93e_6e95_410e_81e24076c30a -->|method| 31b4a475_0699_69a6_a66b_1b98c50a5785
  c02a4f80_a820_866d_445a_6951aae599f7["_getMetadataBySource()"]
  c91679b7_c93e_6e95_410e_81e24076c30a -->|method| c02a4f80_a820_866d_445a_6951aae599f7
  8436bb82_dab4_7302_5fc5_eff8d217773c["_getMetadataObjectsBySourceNames()"]
  c91679b7_c93e_6e95_410e_81e24076c30a -->|method| 8436bb82_dab4_7302_5fc5_eff8d217773c
  8363e8e9_bb7f_f116_6160_65e0851ee4a9["_getHookMapForSource()"]
  c91679b7_c93e_6e95_410e_81e24076c30a -->|method| 8363e8e9_bb7f_f116_6160_65e0851ee4a9

Relationship Graph

Source Code

packages/react-devtools-shared/src/hooks/SourceMapMetadataConsumer.js lines 62–207

export class SourceMapMetadataConsumer {
  _sourceMap: MixedSourceMap;
  _decodedHookMapCache: Map<string, HookMap>;
  _metadataBySource: ?MetadataMap;

  constructor(sourcemap: MixedSourceMap) {
    this._sourceMap = sourcemap;
    this._decodedHookMapCache = new Map();
    this._metadataBySource = null;
  }

  /**
   * Returns the Hook name assigned to a given location in the source code,
   * and a HookMap extracted from an extended source map.
   * See `getHookNameForLocation` for more details on implementation.
   *
   * When used with the `source-map` package, you'll first use
   * `SourceMapConsumer#originalPositionFor` to retrieve a source location,
   * then pass that location to `hookNameFor`.
   */
  hookNameFor({
    line,
    column,
    source,
  }: {
    ...Position,
    +source: ?string,
  }): ?string {
    if (source == null) {
      return null;
    }

    const hookMap = this._getHookMapForSource(source);
    if (hookMap == null) {
      return null;
    }

    return getHookNameForLocation({line, column}, hookMap);
  }

  hasHookMap(source: ?string): boolean {
    if (source == null) {
      return false;
    }
    return this._getHookMapForSource(source) != null;
  }

  /**
   * Prepares and caches a lookup table of metadata by source name.
   */
  _getMetadataBySource(): MetadataMap {
    if (this._metadataBySource == null) {
      this._metadataBySource = this._getMetadataObjectsBySourceNames(
        this._sourceMap,
      );
    }

    return this._metadataBySource;
  }

  /**
   * Collects source metadata from the given map using the current source name
   * normalization function. Handles both index maps (with sections) and plain
   * maps.
   *
   * NOTE: If any sources are repeated in the map (which shouldn't usually happen,
   * but is technically possible because of index maps) we only keep the
   * metadata from the last occurrence of any given source.
   */
  _getMetadataObjectsBySourceNames(sourcemap: MixedSourceMap): MetadataMap {
    if (sourcemap.mappings === undefined) {
      const indexSourceMap: IndexSourceMap = sourcemap;
      const metadataMap = new Map<string, ?ReactSourceMetadata>();
      indexSourceMap.sections.forEach(section => {
        const metadataMapForIndexMap = this._getMetadataObjectsBySourceNames(
          section.map,
        );
        metadataMapForIndexMap.forEach((value, key) => {
          metadataMap.set(key, value);
        });
      });

Domain

Frequently Asked Questions

What is the SourceMapMetadataConsumer class?
SourceMapMetadataConsumer is a class in the react codebase, defined in packages/react-devtools-shared/src/hooks/SourceMapMetadataConsumer.js.
Where is SourceMapMetadataConsumer defined?
SourceMapMetadataConsumer is defined in packages/react-devtools-shared/src/hooks/SourceMapMetadataConsumer.js at line 62.

Analyze Your Own Codebase

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

Try Supermodel Free