simplifySinglePropertyObjects() — react Function Reference
Architecture documentation for the simplifySinglePropertyObjects() function in minimize.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD bbbd1edd_0ea0_dd28_5b78_d9f5cade97c0["simplifySinglePropertyObjects()"] 9c061da8_dbf8_4168_823d_991654a3c55d["minimize.ts"] bbbd1edd_0ea0_dd28_5b78_d9f5cade97c0 -->|defined in| 9c061da8_dbf8_4168_823d_991654a3c55d 7a9af496_ef6a_d9e8_8eaf_1f386f49e4b3["cloneAst()"] bbbd1edd_0ea0_dd28_5b78_d9f5cade97c0 -->|calls| 7a9af496_ef6a_d9e8_8eaf_1f386f49e4b3 style bbbd1edd_0ea0_dd28_5b78_d9f5cade97c0 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/snap/src/minimize.ts lines 1512–1574
function* simplifySinglePropertyObjects(ast: t.File): Generator<t.File> {
// Count single-property objects
let objectCount = 0;
t.traverseFast(ast, node => {
if (t.isObjectExpression(node) && node.properties.length === 1) {
objectCount++;
}
});
// Try replacing with value
for (let targetIdx = 0; targetIdx < objectCount; targetIdx++) {
const cloned = cloneAst(ast);
let idx = 0;
let modified = false;
traverse(cloned, {
ObjectExpression(path) {
if (modified) return;
if (path.node.properties.length === 1 && idx === targetIdx) {
const prop = path.node.properties[0];
if (t.isObjectProperty(prop) && t.isExpression(prop.value)) {
path.replaceWith(prop.value);
modified = true;
}
}
idx++;
},
});
if (modified) {
yield cloned;
}
}
// For computed properties, also try replacing with key
for (let targetIdx = 0; targetIdx < objectCount; targetIdx++) {
const cloned = cloneAst(ast);
let idx = 0;
let modified = false;
traverse(cloned, {
ObjectExpression(path) {
if (modified) return;
if (path.node.properties.length === 1 && idx === targetIdx) {
const prop = path.node.properties[0];
if (
t.isObjectProperty(prop) &&
prop.computed &&
t.isExpression(prop.key)
) {
path.replaceWith(prop.key);
modified = true;
}
}
idx++;
},
});
if (modified) {
yield cloned;
}
}
}
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does simplifySinglePropertyObjects() do?
simplifySinglePropertyObjects() is a function in the react codebase, defined in compiler/packages/snap/src/minimize.ts.
Where is simplifySinglePropertyObjects() defined?
simplifySinglePropertyObjects() is defined in compiler/packages/snap/src/minimize.ts at line 1512.
What does simplifySinglePropertyObjects() call?
simplifySinglePropertyObjects() 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