simplifyCallExpressions() — react Function Reference
Architecture documentation for the simplifyCallExpressions() function in minimize.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 419eed56_01c0_226f_ca7c_a1513713ffae["simplifyCallExpressions()"] 9c061da8_dbf8_4168_823d_991654a3c55d["minimize.ts"] 419eed56_01c0_226f_ca7c_a1513713ffae -->|defined in| 9c061da8_dbf8_4168_823d_991654a3c55d 7a9af496_ef6a_d9e8_8eaf_1f386f49e4b3["cloneAst()"] 419eed56_01c0_226f_ca7c_a1513713ffae -->|calls| 7a9af496_ef6a_d9e8_8eaf_1f386f49e4b3 style 419eed56_01c0_226f_ca7c_a1513713ffae fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/snap/src/minimize.ts lines 271–356
function* simplifyCallExpressions(ast: t.File): Generator<t.File> {
// Count call expressions with arguments
let callCount = 0;
t.traverseFast(ast, node => {
if (t.isCallExpression(node) && node.arguments.length > 0) {
callCount++;
}
});
// For each call, try replacing with arguments
for (let targetIdx = 0; targetIdx < callCount; targetIdx++) {
const cloned = cloneAst(ast);
let idx = 0;
let modified = false;
traverse(cloned, {
CallExpression(path) {
if (modified) return;
if (path.node.arguments.length > 0 && idx === targetIdx) {
const args = path.node.arguments;
// Filter to only Expression arguments (not SpreadElement)
const exprArgs = args.filter((arg): arg is t.Expression =>
t.isExpression(arg),
);
if (exprArgs.length === 0) {
idx++;
return;
}
if (exprArgs.length === 1) {
// Single argument: replace call with the argument
path.replaceWith(exprArgs[0]);
} else {
// Multiple arguments: replace call with array of arguments
path.replaceWith(t.arrayExpression(exprArgs));
}
modified = true;
}
idx++;
},
});
if (modified) {
yield cloned;
}
}
// Also try replacing with each individual argument for multi-arg calls
for (let targetIdx = 0; targetIdx < callCount; targetIdx++) {
// First, find the arg count for this call
let argCount = 0;
let currentIdx = 0;
t.traverseFast(ast, node => {
if (t.isCallExpression(node) && node.arguments.length > 0) {
if (currentIdx === targetIdx) {
argCount = node.arguments.length;
}
currentIdx++;
}
});
// Try replacing with each argument individually
for (let argIdx = 0; argIdx < argCount; argIdx++) {
const cloned = cloneAst(ast);
let idx = 0;
let modified = false;
traverse(cloned, {
CallExpression(path) {
if (modified) return;
if (path.node.arguments.length > 0 && idx === targetIdx) {
const arg = path.node.arguments[argIdx];
if (t.isExpression(arg)) {
path.replaceWith(arg);
modified = true;
}
}
idx++;
},
});
if (modified) {
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does simplifyCallExpressions() do?
simplifyCallExpressions() is a function in the react codebase, defined in compiler/packages/snap/src/minimize.ts.
Where is simplifyCallExpressions() defined?
simplifyCallExpressions() is defined in compiler/packages/snap/src/minimize.ts at line 271.
What does simplifyCallExpressions() call?
simplifyCallExpressions() 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