Home / Function/ removeStatements() — react Function Reference

removeStatements() — react Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

compiler/packages/snap/src/minimize.ts lines 143–186

function* removeStatements(ast: t.File): Generator<t.File> {
  // Collect all statement locations: which container (by index) and which statement index
  const statementLocations: Array<{containerIndex: number; stmtIndex: number}> =
    [];
  let containerIndex = 0;

  t.traverseFast(ast, node => {
    if (t.isBlockStatement(node) || t.isProgram(node)) {
      const body = node.body as t.Statement[];
      // Iterate in reverse order so removing later statements first
      for (let i = body.length - 1; i >= 0; i--) {
        statementLocations.push({containerIndex, stmtIndex: i});
      }
      containerIndex++;
    }
  });

  for (const {
    containerIndex: targetContainerIdx,
    stmtIndex,
  } of statementLocations) {
    const cloned = cloneAst(ast);
    let idx = 0;
    let modified = false;

    t.traverseFast(cloned, node => {
      if (modified) return;
      if (t.isBlockStatement(node) || t.isProgram(node)) {
        if (idx === targetContainerIdx) {
          const body = node.body as t.Statement[];
          if (stmtIndex < body.length) {
            body.splice(stmtIndex, 1);
            modified = true;
          }
        }
        idx++;
      }
    });

    if (modified) {
      yield cloned;
    }
  }
}

Domain

Subdomains

Calls

Frequently Asked Questions

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