evaluateInstruction() — react Function Reference
Architecture documentation for the evaluateInstruction() function in ConstantPropagation.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 7da3db63_9dcc_8c1f_be1f_66f4e99b59ea["evaluateInstruction()"] ee83ff7b_e532_0fd6_0eae_7fe885ffe129["ConstantPropagation.ts"] 7da3db63_9dcc_8c1f_be1f_66f4e99b59ea -->|defined in| ee83ff7b_e532_0fd6_0eae_7fe885ffe129 4419ef20_4b5f_b18c_6237_57b76d298666["applyConstantPropagation()"] 4419ef20_4b5f_b18c_6237_57b76d298666 -->|calls| 7da3db63_9dcc_8c1f_be1f_66f4e99b59ea 3a755420_8f69_0883_ccd1_2cfb88e3627e["read()"] 7da3db63_9dcc_8c1f_be1f_66f4e99b59ea -->|calls| 3a755420_8f69_0883_ccd1_2cfb88e3627e fbdc3953_3621_331c_a5b1_d3199bea5254["constantPropagationImpl()"] 7da3db63_9dcc_8c1f_be1f_66f4e99b59ea -->|calls| fbdc3953_3621_331c_a5b1_d3199bea5254 style 7da3db63_9dcc_8c1f_be1f_66f4e99b59ea fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/Optimization/ConstantPropagation.ts lines 224–615
function evaluateInstruction(
constants: Constants,
instr: Instruction,
): Constant | null {
const value = instr.value;
switch (value.kind) {
case 'Primitive': {
return value;
}
case 'LoadGlobal': {
return value;
}
case 'ComputedLoad': {
const property = read(constants, value.property);
if (
property !== null &&
property.kind === 'Primitive' &&
((typeof property.value === 'string' &&
isValidIdentifier(property.value)) ||
typeof property.value === 'number')
) {
const nextValue: InstructionValue = {
kind: 'PropertyLoad',
loc: value.loc,
property: makePropertyLiteral(property.value),
object: value.object,
};
instr.value = nextValue;
}
return null;
}
case 'ComputedStore': {
const property = read(constants, value.property);
if (
property !== null &&
property.kind === 'Primitive' &&
((typeof property.value === 'string' &&
isValidIdentifier(property.value)) ||
typeof property.value === 'number')
) {
const nextValue: InstructionValue = {
kind: 'PropertyStore',
loc: value.loc,
property: makePropertyLiteral(property.value),
object: value.object,
value: value.value,
};
instr.value = nextValue;
}
return null;
}
case 'PostfixUpdate': {
const previous = read(constants, value.value);
if (
previous !== null &&
previous.kind === 'Primitive' &&
typeof previous.value === 'number'
) {
const next =
value.operation === '++' ? previous.value + 1 : previous.value - 1;
// Store the updated value
constants.set(value.lvalue.identifier.id, {
kind: 'Primitive',
value: next,
loc: value.loc,
});
// But return the value prior to the update
return previous;
}
return null;
}
case 'PrefixUpdate': {
const previous = read(constants, value.value);
if (
previous !== null &&
previous.kind === 'Primitive' &&
typeof previous.value === 'number'
) {
const next: Primitive = {
kind: 'Primitive',
value:
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does evaluateInstruction() do?
evaluateInstruction() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Optimization/ConstantPropagation.ts.
Where is evaluateInstruction() defined?
evaluateInstruction() is defined in compiler/packages/babel-plugin-react-compiler/src/Optimization/ConstantPropagation.ts at line 224.
What does evaluateInstruction() call?
evaluateInstruction() calls 2 function(s): constantPropagationImpl, read.
What calls evaluateInstruction()?
evaluateInstruction() is called by 1 function(s): applyConstantPropagation.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free