transformDestructuring() — react Function Reference
Architecture documentation for the transformDestructuring() function in ExtractScopeDeclarationsFromDestructuring.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD fb7d5dbf_1b8e_624d_5b62_7b7a22eeb272["transformDestructuring()"] 791ee72b_8a79_10a6_5a13_5297a1e50d89["ExtractScopeDeclarationsFromDestructuring.ts"] fb7d5dbf_1b8e_624d_5b62_7b7a22eeb272 -->|defined in| 791ee72b_8a79_10a6_5a13_5297a1e50d89 cc0d3b4e_a169_bc13_335d_35432b193034["transformInstruction()"] cc0d3b4e_a169_bc13_335d_35432b193034 -->|calls| fb7d5dbf_1b8e_624d_5b62_7b7a22eeb272 f5637d03_fd91_50b8_9da7_b2a24c91bab7["eachPatternOperand()"] fb7d5dbf_1b8e_624d_5b62_7b7a22eeb272 -->|calls| f5637d03_fd91_50b8_9da7_b2a24c91bab7 f6e40907_93a0_cbc4_14eb_4d0ec248c01a["mapPatternOperands()"] fb7d5dbf_1b8e_624d_5b62_7b7a22eeb272 -->|calls| f6e40907_93a0_cbc4_14eb_4d0ec248c01a 105d3afd_b3ee_3f37_2c92_eed7c3d1a5a0["clonePlaceToTemporary()"] fb7d5dbf_1b8e_624d_5b62_7b7a22eeb272 -->|calls| 105d3afd_b3ee_3f37_2c92_eed7c3d1a5a0 53244187_914c_cc90_5880_7bfc1fc9c0bb["push()"] fb7d5dbf_1b8e_624d_5b62_7b7a22eeb272 -->|calls| 53244187_914c_cc90_5880_7bfc1fc9c0bb style fb7d5dbf_1b8e_624d_5b62_7b7a22eeb272 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/ExtractScopeDeclarationsFromDestructuring.ts lines 154–208
function transformDestructuring(
state: State,
instr: ReactiveInstruction,
destructure: Destructure,
): null | Array<ReactiveInstruction> {
let reassigned: Set<IdentifierId> = new Set();
let hasDeclaration = false;
for (const place of eachPatternOperand(destructure.lvalue.pattern)) {
const isDeclared = state.declared.has(place.identifier.declarationId);
if (isDeclared) {
reassigned.add(place.identifier.id);
} else {
hasDeclaration = true;
}
}
if (!hasDeclaration) {
// all reassignments
destructure.lvalue.kind = InstructionKind.Reassign;
return null;
}
/*
* Else it's a mix, replace the reassigned items in the destructuring with temporary
* variables and emit separate assignment statements for them
*/
const instructions: Array<ReactiveInstruction> = [];
const renamed: Map<Place, Place> = new Map();
mapPatternOperands(destructure.lvalue.pattern, place => {
if (!reassigned.has(place.identifier.id)) {
return place;
}
const temporary = clonePlaceToTemporary(state.env, place);
promoteTemporary(temporary.identifier);
renamed.set(place, temporary);
return temporary;
});
instructions.push(instr);
for (const [original, temporary] of renamed) {
instructions.push({
id: instr.id,
lvalue: null,
value: {
kind: 'StoreLocal',
lvalue: {
kind: InstructionKind.Reassign,
place: original,
},
value: temporary,
type: null,
loc: destructure.loc,
},
loc: instr.loc,
});
}
return instructions;
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does transformDestructuring() do?
transformDestructuring() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/ExtractScopeDeclarationsFromDestructuring.ts.
Where is transformDestructuring() defined?
transformDestructuring() is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/ExtractScopeDeclarationsFromDestructuring.ts at line 154.
What does transformDestructuring() call?
transformDestructuring() calls 4 function(s): clonePlaceToTemporary, eachPatternOperand, mapPatternOperands, push.
What calls transformDestructuring()?
transformDestructuring() is called by 1 function(s): transformInstruction.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free