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