Home / Function/ popSwitchContext() — react Function Reference

popSwitchContext() — react Function Reference

Architecture documentation for the popSwitchContext() function in code-path-state.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  998aa69c_660b_1912_c7d1_55b3eb1f45b7["popSwitchContext()"]
  d3cee22c_5e2d_f853_c075_2c7c55e5d22c["CodePathState"]
  998aa69c_660b_1912_c7d1_55b3eb1f45b7 -->|defined in| d3cee22c_5e2d_f853_c075_2c7c55e5d22c
  eaeeec6b_36c1_6d87_b602_172b094af25b["popBreakContext()"]
  998aa69c_660b_1912_c7d1_55b3eb1f45b7 -->|calls| eaeeec6b_36c1_6d87_b602_172b094af25b
  c9bd3fa0_9a37_6446_ae50_3ac0a70bdaf1["forkBypassPath()"]
  998aa69c_660b_1912_c7d1_55b3eb1f45b7 -->|calls| c9bd3fa0_9a37_6446_ae50_3ac0a70bdaf1
  69cf1ae8_5861_dded_861c_6feeee9c0fbf["removeConnection()"]
  998aa69c_660b_1912_c7d1_55b3eb1f45b7 -->|calls| 69cf1ae8_5861_dded_861c_6feeee9c0fbf
  340594f4_b9ab_167e_55a5_90de76787b13["makeLooped()"]
  998aa69c_660b_1912_c7d1_55b3eb1f45b7 -->|calls| 340594f4_b9ab_167e_55a5_90de76787b13
  style 998aa69c_660b_1912_c7d1_55b3eb1f45b7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js lines 640–704

  popSwitchContext() {
    const context = this.switchContext;

    this.switchContext = context.upper;

    const forkContext = this.forkContext;
    const brokenForkContext = this.popBreakContext().brokenForkContext;

    if (context.countForks === 0) {
      /*
       * When there is only one `default` chunk and there is one or more
       * `break` statements, even if forks are nothing, it needs to merge
       * those.
       */
      if (!brokenForkContext.empty) {
        brokenForkContext.add(forkContext.makeNext(-1, -1));
        forkContext.replaceHead(brokenForkContext.makeNext(0, -1));
      }

      return;
    }

    const lastSegments = forkContext.head;

    this.forkBypassPath();
    const lastCaseSegments = forkContext.head;

    /*
     * `brokenForkContext` is used to make the next segment.
     * It must add the last segment into `brokenForkContext`.
     */
    brokenForkContext.add(lastSegments);

    /*
     * A path which is failed in all case test should be connected to path
     * of `default` chunk.
     */
    if (!context.lastIsDefault) {
      if (context.defaultBodySegments) {
        /*
         * Remove a link from `default` label to its chunk.
         * It's false route.
         */
        removeConnection(context.defaultSegments, context.defaultBodySegments);
        makeLooped(this, lastCaseSegments, context.defaultBodySegments);
      } else {
        /*
         * It handles the last case body as broken if `default` chunk
         * does not exist.
         */
        brokenForkContext.add(lastCaseSegments);
      }
    }

    // Pops the segment context stack until the entry segment.
    for (let i = 0; i < context.countForks; ++i) {
      this.forkContext = this.forkContext.upper;
    }

    /*
     * Creates a path from all brokenForkContext paths.
     * This is a path after switch statement.
     */
    this.forkContext.replaceHead(brokenForkContext.makeNext(0, -1));
  }

Domain

Subdomains

Frequently Asked Questions

What does popSwitchContext() do?
popSwitchContext() is a function in the react codebase, defined in packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js.
Where is popSwitchContext() defined?
popSwitchContext() is defined in packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js at line 640.
What does popSwitchContext() call?
popSwitchContext() calls 4 function(s): forkBypassPath, makeLooped, popBreakContext, removeConnection.

Analyze Your Own Codebase

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

Try Supermodel Free