lowerOptionalCallExpression() — react Function Reference
Architecture documentation for the lowerOptionalCallExpression() function in BuildHIR.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD e401a324_13b9_af8a_12c7_b731c9f220a3["lowerOptionalCallExpression()"] e04c04d6_37a7_1dc3_7fae_7d07660d0af9["BuildHIR.ts"] e401a324_13b9_af8a_12c7_b731c9f220a3 -->|defined in| e04c04d6_37a7_1dc3_7fae_7d07660d0af9 ace1177a_10b2_b870_31fd_da4aa845554c["lowerExpression()"] ace1177a_10b2_b870_31fd_da4aa845554c -->|calls| e401a324_13b9_af8a_12c7_b731c9f220a3 bb81d73c_5996_9609_94fe_e0f8ad5e876d["lowerOptionalMemberExpression()"] bb81d73c_5996_9609_94fe_e0f8ad5e876d -->|calls| e401a324_13b9_af8a_12c7_b731c9f220a3 147a0e7f_dab2_6a99_0c59_2eb8b07f70d5["buildTemporaryPlace()"] e401a324_13b9_af8a_12c7_b731c9f220a3 -->|calls| 147a0e7f_dab2_6a99_0c59_2eb8b07f70d5 2a23449a_1dec_0ba3_8f5a_0e9e83d42add["reserve()"] e401a324_13b9_af8a_12c7_b731c9f220a3 -->|calls| 2a23449a_1dec_0ba3_8f5a_0e9e83d42add 012a7acd_73d1_2699_77e8_481232bb47c8["currentBlockKind()"] e401a324_13b9_af8a_12c7_b731c9f220a3 -->|calls| 012a7acd_73d1_2699_77e8_481232bb47c8 3db1e7ce_1c6f_24e2_3cbb_86c02c29d285["enter()"] e401a324_13b9_af8a_12c7_b731c9f220a3 -->|calls| 3db1e7ce_1c6f_24e2_3cbb_86c02c29d285 f1f0c182_09ad_b29e_b1ca_56f10046adff["lowerValueToTemporary()"] e401a324_13b9_af8a_12c7_b731c9f220a3 -->|calls| f1f0c182_09ad_b29e_b1ca_56f10046adff d0270ab6_a621_bd55_a1b9_a5cad8b406b2["makeInstructionId()"] e401a324_13b9_af8a_12c7_b731c9f220a3 -->|calls| d0270ab6_a621_bd55_a1b9_a5cad8b406b2 bb81d73c_5996_9609_94fe_e0f8ad5e876d["lowerOptionalMemberExpression()"] e401a324_13b9_af8a_12c7_b731c9f220a3 -->|calls| bb81d73c_5996_9609_94fe_e0f8ad5e876d d3430316_6bb4_9d91_4539_1bff5c189f83["lowerMemberExpression()"] e401a324_13b9_af8a_12c7_b731c9f220a3 -->|calls| d3430316_6bb4_9d91_4539_1bff5c189f83 5bae3f87_1b76_e568_9b44_1d2fb59f73d8["lowerExpressionToTemporary()"] e401a324_13b9_af8a_12c7_b731c9f220a3 -->|calls| 5bae3f87_1b76_e568_9b44_1d2fb59f73d8 10c63c7e_e339_2c92_cb9e_11d13186c6a7["enterReserved()"] e401a324_13b9_af8a_12c7_b731c9f220a3 -->|calls| 10c63c7e_e339_2c92_cb9e_11d13186c6a7 a1ea0998_17ee_ee03_aad6_a8367893b004["lowerArguments()"] e401a324_13b9_af8a_12c7_b731c9f220a3 -->|calls| a1ea0998_17ee_ee03_aad6_a8367893b004 43f67b81_ddfd_4289_903f_8e9e60469eb7["terminateWithContinuation()"] e401a324_13b9_af8a_12c7_b731c9f220a3 -->|calls| 43f67b81_ddfd_4289_903f_8e9e60469eb7 style e401a324_13b9_af8a_12c7_b731c9f220a3 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts lines 2787–2947
function lowerOptionalCallExpression(
builder: HIRBuilder,
expr: NodePath<t.OptionalCallExpression>,
parentAlternate: BlockId | null,
): InstructionValue {
const optional = expr.node.optional;
const calleePath = expr.get('callee');
const loc = expr.node.loc ?? GeneratedSource;
const place = buildTemporaryPlace(builder, loc);
const continuationBlock = builder.reserve(builder.currentBlockKind());
const consequent = builder.reserve('value');
/*
* block to evaluate if the callee is null/undefined, this sets the result of the call to undefined.
* note that we only create an alternate when first entering an optional subtree of the ast: if this
* is a child of an optional node, we use the alterate created by the parent.
*/
const alternate =
parentAlternate !== null
? parentAlternate
: builder.enter('value', () => {
const temp = lowerValueToTemporary(builder, {
kind: 'Primitive',
value: undefined,
loc,
});
lowerValueToTemporary(builder, {
kind: 'StoreLocal',
lvalue: {kind: InstructionKind.Const, place: {...place}},
value: {...temp},
type: null,
loc,
});
return {
kind: 'goto',
variant: GotoVariant.Break,
block: continuationBlock.id,
id: makeInstructionId(0),
loc,
};
});
/*
* Lower the callee within the test block to represent the fact that the code for the callee is
* scoped within the optional
*/
let callee:
| {kind: 'CallExpression'; callee: Place}
| {kind: 'MethodCall'; receiver: Place; property: Place};
const testBlock = builder.enter('value', () => {
if (calleePath.isOptionalCallExpression()) {
// Recursively call lowerOptionalCallExpression to thread down the alternate block
const value = lowerOptionalCallExpression(builder, calleePath, alternate);
const valuePlace = lowerValueToTemporary(builder, value);
callee = {
kind: 'CallExpression',
callee: valuePlace,
};
} else if (calleePath.isOptionalMemberExpression()) {
const {object, value} = lowerOptionalMemberExpression(
builder,
calleePath,
alternate,
);
callee = {
kind: 'MethodCall',
receiver: object,
property: value,
};
} else if (calleePath.isMemberExpression()) {
const memberExpr = lowerMemberExpression(builder, calleePath);
const propertyPlace = lowerValueToTemporary(builder, memberExpr.value);
callee = {
kind: 'MethodCall',
receiver: memberExpr.object,
property: propertyPlace,
};
} else {
callee = {
kind: 'CallExpression',
callee: lowerExpressionToTemporary(builder, calleePath),
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does lowerOptionalCallExpression() do?
lowerOptionalCallExpression() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts.
Where is lowerOptionalCallExpression() defined?
lowerOptionalCallExpression() is defined in compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts at line 2787.
What does lowerOptionalCallExpression() call?
lowerOptionalCallExpression() calls 13 function(s): buildTemporaryPlace, currentBlockKind, enter, enterReserved, lowerArguments, lowerExpressionToTemporary, lowerMemberExpression, lowerOptionalMemberExpression, and 5 more.
What calls lowerOptionalCallExpression()?
lowerOptionalCallExpression() is called by 2 function(s): lowerExpression, lowerOptionalMemberExpression.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free