Home / Function/ removeArrayElements() — react Function Reference

removeArrayElements() — react Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

compiler/packages/snap/src/minimize.ts lines 1317–1351

function* removeArrayElements(ast: t.File): Generator<t.File> {
  // Collect all array expressions with their element counts
  const arraySites: Array<{arrayIndex: number; elementCount: number}> = [];
  let arrayIndex = 0;
  t.traverseFast(ast, node => {
    if (t.isArrayExpression(node) && node.elements.length > 0) {
      arraySites.push({arrayIndex, elementCount: node.elements.length});
      arrayIndex++;
    }
  });

  // For each array, try removing each element one at a time (from end to start)
  for (const {arrayIndex: targetArrayIdx, elementCount} of arraySites) {
    for (let elemIdx = elementCount - 1; elemIdx >= 0; elemIdx--) {
      const cloned = cloneAst(ast);
      let idx = 0;
      let modified = false;

      t.traverseFast(cloned, node => {
        if (modified) return;
        if (t.isArrayExpression(node) && node.elements.length > 0) {
          if (idx === targetArrayIdx && elemIdx < node.elements.length) {
            node.elements.splice(elemIdx, 1);
            modified = true;
          }
          idx++;
        }
      });

      if (modified) {
        yield cloned;
      }
    }
  }
}

Domain

Subdomains

Calls

Frequently Asked Questions

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