Home / Function/ simplifyLogicalExpressions() — react Function Reference

simplifyLogicalExpressions() — react Function Reference

Architecture documentation for the simplifyLogicalExpressions() function in minimize.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  f6405ea9_e21c_412c_2e34_035c3ec5ad54["simplifyLogicalExpressions()"]
  9c061da8_dbf8_4168_823d_991654a3c55d["minimize.ts"]
  f6405ea9_e21c_412c_2e34_035c3ec5ad54 -->|defined in| 9c061da8_dbf8_4168_823d_991654a3c55d
  7a9af496_ef6a_d9e8_8eaf_1f386f49e4b3["cloneAst()"]
  f6405ea9_e21c_412c_2e34_035c3ec5ad54 -->|calls| 7a9af496_ef6a_d9e8_8eaf_1f386f49e4b3
  style f6405ea9_e21c_412c_2e34_035c3ec5ad54 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/snap/src/minimize.ts lines 440–492

function* simplifyLogicalExpressions(ast: t.File): Generator<t.File> {
  // Count logical expressions
  let logicalCount = 0;
  t.traverseFast(ast, node => {
    if (t.isLogicalExpression(node)) {
      logicalCount++;
    }
  });

  // Try replacing with left side
  for (let targetIdx = 0; targetIdx < logicalCount; targetIdx++) {
    const cloned = cloneAst(ast);
    let idx = 0;
    let modified = false;

    traverse(cloned, {
      LogicalExpression(path) {
        if (modified) return;
        if (idx === targetIdx) {
          path.replaceWith(path.node.left);
          modified = true;
        }
        idx++;
      },
    });

    if (modified) {
      yield cloned;
    }
  }

  // Try replacing with right side
  for (let targetIdx = 0; targetIdx < logicalCount; targetIdx++) {
    const cloned = cloneAst(ast);
    let idx = 0;
    let modified = false;

    traverse(cloned, {
      LogicalExpression(path) {
        if (modified) return;
        if (idx === targetIdx) {
          path.replaceWith(path.node.right);
          modified = true;
        }
        idx++;
      },
    });

    if (modified) {
      yield cloned;
    }
  }
}

Domain

Subdomains

Calls

Frequently Asked Questions

What does simplifyLogicalExpressions() do?
simplifyLogicalExpressions() is a function in the react codebase, defined in compiler/packages/snap/src/minimize.ts.
Where is simplifyLogicalExpressions() defined?
simplifyLogicalExpressions() is defined in compiler/packages/snap/src/minimize.ts at line 440.
What does simplifyLogicalExpressions() call?
simplifyLogicalExpressions() calls 1 function(s): cloneAst.

Analyze Your Own Codebase

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

Try Supermodel Free