transformInstruction() — react Function Reference
Architecture documentation for the transformInstruction() function in PruneNonEscapingScopes.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 2211ab1f_a4ba_c853_54e3_d906ac4af6fe["transformInstruction()"] 49ee75e7_6b19_52e6_3867_ae2c90149d13["PruneScopesTransform"] 2211ab1f_a4ba_c853_54e3_d906ac4af6fe -->|defined in| 49ee75e7_6b19_52e6_3867_ae2c90149d13 40802d10_d9f1_10c2_2fff_626026f88fb4["transformInstruction()"] 2211ab1f_a4ba_c853_54e3_d906ac4af6fe -->|calls| 40802d10_d9f1_10c2_2fff_626026f88fb4 14f2e51a_d755_814e_2f56_72d3ed119459["getOrInsertDefault()"] 2211ab1f_a4ba_c853_54e3_d906ac4af6fe -->|calls| 14f2e51a_d755_814e_2f56_72d3ed119459 940018a6_e890_d3b5_6044_cb8053953421["traverseInstruction()"] 2211ab1f_a4ba_c853_54e3_d906ac4af6fe -->|calls| 940018a6_e890_d3b5_6044_cb8053953421 style 2211ab1f_a4ba_c853_54e3_d906ac4af6fe fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneNonEscapingScopes.ts lines 1067–1122
override transformInstruction(
instruction: ReactiveInstruction,
state: Set<DeclarationId>,
): Transformed<ReactiveStatement> {
this.traverseInstruction(instruction, state);
const value = instruction.value;
if (value.kind === 'StoreLocal' && value.lvalue.kind === 'Reassign') {
// Complex cases of useMemo inlining result in a temporary that is reassigned
const ids = getOrInsertDefault(
this.reassignments,
value.lvalue.place.identifier.declarationId,
new Set(),
);
ids.add(value.value.identifier);
} else if (
value.kind === 'LoadLocal' &&
value.place.identifier.scope != null &&
instruction.lvalue != null &&
instruction.lvalue.identifier.scope == null
) {
/*
* Simpler cases result in a direct assignment to the original lvalue, with a
* LoadLocal
*/
const ids = getOrInsertDefault(
this.reassignments,
instruction.lvalue.identifier.declarationId,
new Set(),
);
ids.add(value.place.identifier);
} else if (value.kind === 'FinishMemoize') {
let decls;
if (value.decl.identifier.scope == null) {
/**
* If the manual memo was a useMemo that got inlined, iterate through
* all reassignments to the iife temporary to ensure they're memoized.
*/
decls = this.reassignments.get(value.decl.identifier.declarationId) ?? [
value.decl.identifier,
];
} else {
decls = [value.decl.identifier];
}
if (
[...decls].every(
decl => decl.scope == null || this.prunedScopes.has(decl.scope.id),
)
) {
value.pruned = true;
}
}
return {kind: 'keep'};
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does transformInstruction() do?
transformInstruction() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneNonEscapingScopes.ts.
Where is transformInstruction() defined?
transformInstruction() is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneNonEscapingScopes.ts at line 1067.
What does transformInstruction() call?
transformInstruction() calls 3 function(s): getOrInsertDefault, transformInstruction, traverseInstruction.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free