Home / Function/ simplifySingleStatementBlocks() — react Function Reference

simplifySingleStatementBlocks() — react Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

compiler/packages/snap/src/minimize.ts lines 1272–1312

function* simplifySingleStatementBlocks(ast: t.File): Generator<t.File> {
  // Count block statements with exactly one statement
  let blockCount = 0;
  t.traverseFast(ast, node => {
    if (t.isBlockStatement(node) && node.body.length === 1) {
      blockCount++;
    }
  });

  for (let targetIdx = 0; targetIdx < blockCount; targetIdx++) {
    const cloned = cloneAst(ast);
    let idx = 0;
    let modified = false;

    traverse(cloned, {
      BlockStatement(path) {
        if (modified) return;
        if (path.node.body.length === 1 && idx === targetIdx) {
          // Don't unwrap blocks that require BlockStatement syntax
          if (
            t.isFunction(path.parent) ||
            t.isCatchClause(path.parent) ||
            t.isClassMethod(path.parent) ||
            t.isObjectMethod(path.parent) ||
            t.isTryStatement(path.parent)
          ) {
            idx++;
            return;
          }
          path.replaceWith(path.node.body[0]);
          modified = true;
        }
        idx++;
      },
    });

    if (modified) {
      yield cloned;
    }
  }
}

Domain

Subdomains

Calls

Frequently Asked Questions

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