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