Home / Function/ popChoiceContext() — react Function Reference

popChoiceContext() — react Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  5da27dd3_9948_dd4b_f283_32a2cdeec34e["popChoiceContext()"]
  d3cee22c_5e2d_f853_c075_2c7c55e5d22c["CodePathState"]
  5da27dd3_9948_dd4b_f283_32a2cdeec34e -->|defined in| d3cee22c_5e2d_f853_c075_2c7c55e5d22c
  f484a4fe_6d7c_eb36_3a2e_fa3ad9a875b7["popChainContext()"]
  f484a4fe_6d7c_eb36_3a2e_fa3ad9a875b7 -->|calls| 5da27dd3_9948_dd4b_f283_32a2cdeec34e
  941f950b_cd48_1b4b_82f0_a7c8f79c78b6["popLoopContext()"]
  941f950b_cd48_1b4b_82f0_a7c8f79c78b6 -->|calls| 5da27dd3_9948_dd4b_f283_32a2cdeec34e
  941f950b_cd48_1b4b_82f0_a7c8f79c78b6["popLoopContext()"]
  5da27dd3_9948_dd4b_f283_32a2cdeec34e -->|calls| 941f950b_cd48_1b4b_82f0_a7c8f79c78b6
  style 5da27dd3_9948_dd4b_f283_32a2cdeec34e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

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

  popChoiceContext() {
    const context = this.choiceContext;

    this.choiceContext = context.upper;

    const forkContext = this.forkContext;
    const headSegments = forkContext.head;

    switch (context.kind) {
      case '&&':
      case '||':
      case '??':
        /*
         * If any result were not transferred from child contexts,
         * this sets the head segments to both cases.
         * The head segments are the path of the right-hand operand.
         */
        if (!context.processed) {
          context.trueForkContext.add(headSegments);
          context.falseForkContext.add(headSegments);
          context.qqForkContext.add(headSegments);
        }

        /*
         * Transfers results to upper context if this context is in
         * test chunk.
         */
        if (context.isForkingAsResult) {
          const parentContext = this.choiceContext;

          parentContext.trueForkContext.addAll(context.trueForkContext);
          parentContext.falseForkContext.addAll(context.falseForkContext);
          parentContext.qqForkContext.addAll(context.qqForkContext);
          parentContext.processed = true;

          return context;
        }

        break;

      case 'test':
        if (!context.processed) {
          /*
           * The head segments are the path of the `if` block here.
           * Updates the `true` path with the end of the `if` block.
           */
          context.trueForkContext.clear();
          context.trueForkContext.add(headSegments);
        } else {
          /*
           * The head segments are the path of the `else` block here.
           * Updates the `false` path with the end of the `else`
           * block.
           */
          context.falseForkContext.clear();
          context.falseForkContext.add(headSegments);
        }

        break;

      case 'loop':
        /*
         * Loops are addressed in popLoopContext().
         * This is called from popLoopContext().
         */
        return context;

      /* c8 ignore next */
      default:
        throw new Error('unreachable');
    }

    // Merges all paths.
    const prevForkContext = context.trueForkContext;

    prevForkContext.addAll(context.falseForkContext);
    forkContext.replaceHead(prevForkContext.makeNext(0, -1));

    return context;
  }

Domain

Subdomains

Frequently Asked Questions

What does popChoiceContext() do?
popChoiceContext() is a function in the react codebase, defined in packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js.
Where is popChoiceContext() defined?
popChoiceContext() is defined in packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js at line 363.
What does popChoiceContext() call?
popChoiceContext() calls 1 function(s): popLoopContext.
What calls popChoiceContext()?
popChoiceContext() is called by 2 function(s): popChainContext, popLoopContext.

Analyze Your Own Codebase

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

Try Supermodel Free