Home / File/ PruneHoistedContexts.ts — react Source File

PruneHoistedContexts.ts — react Source File

Architecture documentation for PruneHoistedContexts.ts, a typescript file in the react codebase. 9 imports, 0 dependents.

File typescript BabelCompiler Validation 9 imports 1 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  3b44eada_4dab_f6ef_3a59_8679cbd297bb["PruneHoistedContexts.ts"]
  0423f759_97e0_9101_4634_ed555abc5ca9["index.ts"]
  3b44eada_4dab_f6ef_3a59_8679cbd297bb --> 0423f759_97e0_9101_4634_ed555abc5ca9
  a4f6856b_1fb6_fbaa_dad2_faf7da011133["Stack.ts"]
  3b44eada_4dab_f6ef_3a59_8679cbd297bb --> a4f6856b_1fb6_fbaa_dad2_faf7da011133
  462d4884_0290_ceb1_b76b_bfb25c49a3cc["empty"]
  3b44eada_4dab_f6ef_3a59_8679cbd297bb --> 462d4884_0290_ceb1_b76b_bfb25c49a3cc
  28b490d0_8cb5_d402_79d3_9d7245a1d4f9["Stack"]
  3b44eada_4dab_f6ef_3a59_8679cbd297bb --> 28b490d0_8cb5_d402_79d3_9d7245a1d4f9
  21609915_b03a_fd75_b58a_4cb86ef9315b["visitors.ts"]
  3b44eada_4dab_f6ef_3a59_8679cbd297bb --> 21609915_b03a_fd75_b58a_4cb86ef9315b
  af3ace55_db6d_865e_92b9_81486f6af1e7["ReactiveFunctionTransform"]
  3b44eada_4dab_f6ef_3a59_8679cbd297bb --> af3ace55_db6d_865e_92b9_81486f6af1e7
  da7ad665_d709_433d_facd_dc3b2c4d34f5["Transformed"]
  3b44eada_4dab_f6ef_3a59_8679cbd297bb --> da7ad665_d709_433d_facd_dc3b2c4d34f5
  2435b5f8_41a6_0458_ba88_4479b965455f["visitReactiveFunction"]
  3b44eada_4dab_f6ef_3a59_8679cbd297bb --> 2435b5f8_41a6_0458_ba88_4479b965455f
  2ed45bcd_6c82_3ccd_0e20_fa96b5111055[".."]
  3b44eada_4dab_f6ef_3a59_8679cbd297bb --> 2ed45bcd_6c82_3ccd_0e20_fa96b5111055
  style 3b44eada_4dab_f6ef_3a59_8679cbd297bb 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 {CompilerError} from '..';
import {
  convertHoistedLValueKind,
  IdentifierId,
  InstructionId,
  InstructionKind,
  Place,
  ReactiveFunction,
  ReactiveInstruction,
  ReactiveScopeBlock,
  ReactiveStatement,
} from '../HIR';
import {empty, Stack} from '../Utils/Stack';
import {
  ReactiveFunctionTransform,
  Transformed,
  visitReactiveFunction,
} from './visitors';

/*
 * Prunes DeclareContexts lowered for HoistedConsts, and transforms any references back to its
 * original instruction kind.
 *
 * Also detects and bails out on context variables which are:
 * - function declarations, which are hoisted by JS engines to the nearest block scope
 * - referenced before they are defined (i.e. having a `DeclareContext HoistedConst`)
 * - declared
 *
 * This is because React Compiler converts a `function foo()` function declaration to
 * 1. a `let foo;` declaration before reactive memo blocks
 * 2. a `foo = function foo() {}` assignment within the block
 *
 * This means references before the assignment are invalid (see fixture
 * error.todo-functiondecl-hoisting)
 */
export function pruneHoistedContexts(fn: ReactiveFunction): void {
  visitReactiveFunction(fn, new Visitor(), {
    activeScopes: empty(),
    uninitialized: new Map(),
  });
}

type VisitorState = {
  activeScopes: Stack<Set<IdentifierId>>;
  uninitialized: Map<
    IdentifierId,
    | {
        kind: 'unknown-kind';
      }
    | {
        kind: 'func';
        definition: Place | null;
      }
// ... (111 more lines)

Domain

Subdomains

Classes

Types

Frequently Asked Questions

What does PruneHoistedContexts.ts do?
PruneHoistedContexts.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 PruneHoistedContexts.ts?
PruneHoistedContexts.ts defines 1 function(s): pruneHoistedContexts.
What does PruneHoistedContexts.ts depend on?
PruneHoistedContexts.ts imports 9 module(s): .., ReactiveFunctionTransform, Stack, Stack.ts, Transformed, empty, index.ts, visitReactiveFunction, and 1 more.
Where is PruneHoistedContexts.ts in the architecture?
PruneHoistedContexts.ts is located at compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneHoistedContexts.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