Home / File/ CollectReferencedGlobals.ts — react Source File

CollectReferencedGlobals.ts — react Source File

Architecture documentation for CollectReferencedGlobals.ts, a typescript file in the react codebase. 4 imports, 1 dependents.

File typescript BabelCompiler Validation 4 imports 1 dependents 1 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  912711a8_8fb0_c4ab_294c_3ee046affe17["CollectReferencedGlobals.ts"]
  0423f759_97e0_9101_4634_ed555abc5ca9["index.ts"]
  912711a8_8fb0_c4ab_294c_3ee046affe17 --> 0423f759_97e0_9101_4634_ed555abc5ca9
  21609915_b03a_fd75_b58a_4cb86ef9315b["visitors.ts"]
  912711a8_8fb0_c4ab_294c_3ee046affe17 --> 21609915_b03a_fd75_b58a_4cb86ef9315b
  171a5d22_bb6b_1c99_05a4_6ad897438a35["ReactiveFunctionVisitor"]
  912711a8_8fb0_c4ab_294c_3ee046affe17 --> 171a5d22_bb6b_1c99_05a4_6ad897438a35
  9dc3e5f8_0649_d981_e520_38c0ab672d18["."]
  912711a8_8fb0_c4ab_294c_3ee046affe17 --> 9dc3e5f8_0649_d981_e520_38c0ab672d18
  a67a8ce3_d9a8_a740_fb57_bc90354f75e7["RenameVariables.ts"]
  a67a8ce3_d9a8_a740_fb57_bc90354f75e7 --> 912711a8_8fb0_c4ab_294c_3ee046affe17
  style 912711a8_8fb0_c4ab_294c_3ee046affe17 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.
 */

import {visitReactiveFunction} from '.';
import {InstructionId, Place, ReactiveFunction, ReactiveValue} from '../HIR';
import {ReactiveFunctionVisitor} from './visitors';

/**
 * Returns a set of unique globals (by name) that are referenced transitively within the function.
 */
export function collectReferencedGlobals(fn: ReactiveFunction): Set<string> {
  const identifiers = new Set<string>();
  visitReactiveFunction(fn, new Visitor(), identifiers);
  return identifiers;
}

class Visitor extends ReactiveFunctionVisitor<Set<string>> {
  override visitValue(
    id: InstructionId,
    value: ReactiveValue,
    state: Set<string>,
  ): void {
    this.traverseValue(id, value, state);
    if (value.kind === 'FunctionExpression' || value.kind === 'ObjectMethod') {
      this.visitHirFunction(value.loweredFunc.func, state);
    } else if (value.kind === 'LoadGlobal') {
      state.add(value.binding.name);
    }
  }

  override visitReactiveFunctionValue(
    _id: InstructionId,
    _dependencies: Array<Place>,
    fn: ReactiveFunction,
    state: Set<string>,
  ): void {
    visitReactiveFunction(fn, this, state);
  }
}

Domain

Subdomains

Classes

Frequently Asked Questions

What does CollectReferencedGlobals.ts do?
CollectReferencedGlobals.ts is a source file in the react codebase, written in typescript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in CollectReferencedGlobals.ts?
CollectReferencedGlobals.ts defines 1 function(s): collectReferencedGlobals.
What does CollectReferencedGlobals.ts depend on?
CollectReferencedGlobals.ts imports 4 module(s): ., ReactiveFunctionVisitor, index.ts, visitors.ts.
What files import CollectReferencedGlobals.ts?
CollectReferencedGlobals.ts is imported by 1 file(s): RenameVariables.ts.
Where is CollectReferencedGlobals.ts in the architecture?
CollectReferencedGlobals.ts is located at compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CollectReferencedGlobals.ts (domain: BabelCompiler, subdomain: Validation, directory: compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes).

Analyze Your Own Codebase

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

Try Supermodel Free