Home / Function/ simplifyWhileStatements() — react Function Reference

simplifyWhileStatements() — react Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

compiler/packages/snap/src/minimize.ts lines 740–792

function* simplifyWhileStatements(ast: t.File): Generator<t.File> {
  // Count while statements
  let whileCount = 0;
  t.traverseFast(ast, node => {
    if (t.isWhileStatement(node)) {
      whileCount++;
    }
  });

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

    traverse(cloned, {
      WhileStatement(path) {
        if (modified) return;
        if (idx === targetIdx) {
          path.replaceWith(t.expressionStatement(path.node.test));
          modified = true;
        }
        idx++;
      },
    });

    if (modified) {
      yield cloned;
    }
  }

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

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

    if (modified) {
      yield cloned;
    }
  }
}

Domain

Subdomains

Calls

Frequently Asked Questions

What does simplifyWhileStatements() do?
simplifyWhileStatements() is a function in the react codebase, defined in compiler/packages/snap/src/minimize.ts.
Where is simplifyWhileStatements() defined?
simplifyWhileStatements() is defined in compiler/packages/snap/src/minimize.ts at line 740.
What does simplifyWhileStatements() call?
simplifyWhileStatements() 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