Home / Function/ processCodePathToEnter() — react Function Reference

processCodePathToEnter() — react Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  161c28ff_1683_8239_7d98_2beab93199f8["processCodePathToEnter()"]
  09a1c78a_21af_9be8_1cc6_22cf0ceb9f8f["code-path-analyzer.js"]
  161c28ff_1683_8239_7d98_2beab93199f8 -->|defined in| 09a1c78a_21af_9be8_1cc6_22cf0ceb9f8f
  d082f1e7_4eef_c1db_f99e_4cfec174190f["enterNode()"]
  d082f1e7_4eef_c1db_f99e_4cfec174190f -->|calls| 161c28ff_1683_8239_7d98_2beab93199f8
  9f2557e7_03e4_e785_ae54_43d9e4959750["forwardCurrentToHead()"]
  161c28ff_1683_8239_7d98_2beab93199f8 -->|calls| 9f2557e7_03e4_e785_ae54_43d9e4959750
  e0bbc1ce_8e9f_12d8_263b_769599e99847["isPropertyDefinitionValue()"]
  161c28ff_1683_8239_7d98_2beab93199f8 -->|calls| e0bbc1ce_8e9f_12d8_263b_769599e99847
  8f9baede_3c74_c103_bf16_8ed6896c980e["isHandledLogicalOperator()"]
  161c28ff_1683_8239_7d98_2beab93199f8 -->|calls| 8f9baede_3c74_c103_bf16_8ed6896c980e
  8afc3bb2_5464_ead5_2449_8dcf575067a4["isForkingByTrueOrFalse()"]
  161c28ff_1683_8239_7d98_2beab93199f8 -->|calls| 8afc3bb2_5464_ead5_2449_8dcf575067a4
  1b797861_fe3d_e47c_ac86_c6dca04010f2["isLogicalAssignmentOperator()"]
  161c28ff_1683_8239_7d98_2beab93199f8 -->|calls| 1b797861_fe3d_e47c_ac86_c6dca04010f2
  e61e0ee9_5e0f_bbda_e4d0_e5db51f705d6["getLabel()"]
  161c28ff_1683_8239_7d98_2beab93199f8 -->|calls| e61e0ee9_5e0f_bbda_e4d0_e5db51f705d6
  style 161c28ff_1683_8239_7d98_2beab93199f8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js lines 380–520

function processCodePathToEnter(analyzer, node) {
  let codePath = analyzer.codePath;
  let state = codePath && CodePath.getState(codePath);
  const parent = node.parent;

  /**
   * Creates a new code path and trigger the onCodePathStart event
   * based on the currently selected node.
   * @param {string} origin The reason the code path was started.
   * @returns {void}
   */
  function startCodePath(origin) {
    if (codePath) {
      // Emits onCodePathSegmentStart events if updated.
      forwardCurrentToHead(analyzer, node);
    }

    // Create the code path of this scope.
    codePath = analyzer.codePath = new CodePath({
      id: analyzer.idGenerator.next(),
      origin,
      upper: codePath,
      onLooped: analyzer.onLooped,
    });
    state = CodePath.getState(codePath);

    // Emits onCodePathStart events.
    analyzer.emitter.emit('onCodePathStart', codePath, node);
  }

  /*
   * Special case: The right side of class field initializer is considered
   * to be its own function, so we need to start a new code path in this
   * case.
   */
  if (isPropertyDefinitionValue(node)) {
    startCodePath('class-field-initializer');

    /*
     * Intentional fall through because `node` needs to also be
     * processed by the code below. For example, if we have:
     *
     * class Foo {
     *     a = () => {}
     * }
     *
     * In this case, we also need start a second code path.
     */
  }

  switch (node.type) {
    case 'Program':
      startCodePath('program');
      break;

    case 'FunctionDeclaration':
    case 'ComponentDeclaration':
    case 'HookDeclaration':
    case 'FunctionExpression':
    case 'ArrowFunctionExpression':
      startCodePath('function');
      break;

    case 'StaticBlock':
      startCodePath('class-static-block');
      break;

    case 'ChainExpression':
      state.pushChainContext();
      break;
    case 'CallExpression':
      if (node.optional === true) {
        state.makeOptionalNode();
      }
      break;
    case 'MemberExpression':
      if (node.optional === true) {
        state.makeOptionalNode();
      }
      break;

Domain

Subdomains

Called By

Frequently Asked Questions

What does processCodePathToEnter() do?
processCodePathToEnter() is a function in the react codebase, defined in packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js.
Where is processCodePathToEnter() defined?
processCodePathToEnter() is defined in packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js at line 380.
What does processCodePathToEnter() call?
processCodePathToEnter() calls 6 function(s): forwardCurrentToHead, getLabel, isForkingByTrueOrFalse, isHandledLogicalOperator, isLogicalAssignmentOperator, isPropertyDefinitionValue.
What calls processCodePathToEnter()?
processCodePathToEnter() is called by 1 function(s): enterNode.

Analyze Your Own Codebase

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

Try Supermodel Free