simplifyForInStatements() — react Function Reference
Architecture documentation for the simplifyForInStatements() function in minimize.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD a5373566_163f_e160_e8d1_151eb543500a["simplifyForInStatements()"] 9c061da8_dbf8_4168_823d_991654a3c55d["minimize.ts"] a5373566_163f_e160_e8d1_151eb543500a -->|defined in| 9c061da8_dbf8_4168_823d_991654a3c55d 7a9af496_ef6a_d9e8_8eaf_1f386f49e4b3["cloneAst()"] a5373566_163f_e160_e8d1_151eb543500a -->|calls| 7a9af496_ef6a_d9e8_8eaf_1f386f49e4b3 style a5373566_163f_e160_e8d1_151eb543500a fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/snap/src/minimize.ts lines 969–1048
function* simplifyForInStatements(ast: t.File): Generator<t.File> {
// Count for-in statements
let forInCount = 0;
t.traverseFast(ast, node => {
if (t.isForInStatement(node)) {
forInCount++;
}
});
// Try replacing with left
for (let targetIdx = 0; targetIdx < forInCount; targetIdx++) {
const cloned = cloneAst(ast);
let idx = 0;
let modified = false;
traverse(cloned, {
ForInStatement(path) {
if (modified) return;
if (idx === targetIdx) {
const left = path.node.left;
if (t.isExpression(left)) {
path.replaceWith(t.expressionStatement(left));
} else {
path.replaceWith(left);
}
modified = true;
}
idx++;
},
});
if (modified) {
yield cloned;
}
}
// Try replacing with right
for (let targetIdx = 0; targetIdx < forInCount; targetIdx++) {
const cloned = cloneAst(ast);
let idx = 0;
let modified = false;
traverse(cloned, {
ForInStatement(path) {
if (modified) return;
if (idx === targetIdx) {
path.replaceWith(t.expressionStatement(path.node.right));
modified = true;
}
idx++;
},
});
if (modified) {
yield cloned;
}
}
// Try replacing with body
for (let targetIdx = 0; targetIdx < forInCount; targetIdx++) {
const cloned = cloneAst(ast);
let idx = 0;
let modified = false;
traverse(cloned, {
ForInStatement(path) {
if (modified) return;
if (idx === targetIdx) {
path.replaceWith(path.node.body);
modified = true;
}
idx++;
},
});
if (modified) {
yield cloned;
}
}
}
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does simplifyForInStatements() do?
simplifyForInStatements() is a function in the react codebase, defined in compiler/packages/snap/src/minimize.ts.
Where is simplifyForInStatements() defined?
simplifyForInStatements() is defined in compiler/packages/snap/src/minimize.ts at line 969.
What does simplifyForInStatements() call?
simplifyForInStatements() 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