lowerStatement() — react Function Reference
Architecture documentation for the lowerStatement() function in BuildHIR.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD c01b12bd_811d_9f90_f641_fac8e518dbb7["lowerStatement()"] e04c04d6_37a7_1dc3_7fae_7d07660d0af9["BuildHIR.ts"] c01b12bd_811d_9f90_f641_fac8e518dbb7 -->|defined in| e04c04d6_37a7_1dc3_7fae_7d07660d0af9 f214c28b_2f6d_b5a3_71e1_9a69d9b50455["lower()"] f214c28b_2f6d_b5a3_71e1_9a69d9b50455 -->|calls| c01b12bd_811d_9f90_f641_fac8e518dbb7 5bae3f87_1b76_e568_9b44_1d2fb59f73d8["lowerExpressionToTemporary()"] c01b12bd_811d_9f90_f641_fac8e518dbb7 -->|calls| 5bae3f87_1b76_e568_9b44_1d2fb59f73d8 6e09e8c4_b216_0635_0def_0235e002b844["resolveThrowHandler()"] c01b12bd_811d_9f90_f641_fac8e518dbb7 -->|calls| 6e09e8c4_b216_0635_0def_0235e002b844 d0270ab6_a621_bd55_a1b9_a5cad8b406b2["makeInstructionId()"] c01b12bd_811d_9f90_f641_fac8e518dbb7 -->|calls| d0270ab6_a621_bd55_a1b9_a5cad8b406b2 88ff4269_4045_952d_05c0_a73b9bcad451["terminate()"] c01b12bd_811d_9f90_f641_fac8e518dbb7 -->|calls| 88ff4269_4045_952d_05c0_a73b9bcad451 f1f0c182_09ad_b29e_b1ca_56f10046adff["lowerValueToTemporary()"] c01b12bd_811d_9f90_f641_fac8e518dbb7 -->|calls| f1f0c182_09ad_b29e_b1ca_56f10046adff 2a23449a_1dec_0ba3_8f5a_0e9e83d42add["reserve()"] c01b12bd_811d_9f90_f641_fac8e518dbb7 -->|calls| 2a23449a_1dec_0ba3_8f5a_0e9e83d42add 3db1e7ce_1c6f_24e2_3cbb_86c02c29d285["enter()"] c01b12bd_811d_9f90_f641_fac8e518dbb7 -->|calls| 3db1e7ce_1c6f_24e2_3cbb_86c02c29d285 d5e0302e_0924_3d1c_bfcb_bc2180bf984c["hasNode()"] c01b12bd_811d_9f90_f641_fac8e518dbb7 -->|calls| d5e0302e_0924_3d1c_bfcb_bc2180bf984c 43f67b81_ddfd_4289_903f_8e9e60469eb7["terminateWithContinuation()"] c01b12bd_811d_9f90_f641_fac8e518dbb7 -->|calls| 43f67b81_ddfd_4289_903f_8e9e60469eb7 211c5bf6_6e8d_0959_64f1_09503c23dd6f["scope()"] c01b12bd_811d_9f90_f641_fac8e518dbb7 -->|calls| 211c5bf6_6e8d_0959_64f1_09503c23dd6f 041ca752_10c1_3cda_1f5c_02f44a01310e["invariant()"] c01b12bd_811d_9f90_f641_fac8e518dbb7 -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e 129cba6c_ded6_779e_cc49_b175d871418b["isHoistedIdentifier()"] c01b12bd_811d_9f90_f641_fac8e518dbb7 -->|calls| 129cba6c_ded6_779e_cc49_b175d871418b style c01b12bd_811d_9f90_f641_fac8e518dbb7 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts lines 267–1489
function lowerStatement(
builder: HIRBuilder,
stmtPath: NodePath<t.Statement>,
label: string | null = null,
): void {
const stmtNode = stmtPath.node;
switch (stmtNode.type) {
case 'ThrowStatement': {
const stmt = stmtPath as NodePath<t.ThrowStatement>;
const value = lowerExpressionToTemporary(builder, stmt.get('argument'));
const handler = builder.resolveThrowHandler();
if (handler != null) {
/*
* NOTE: we could support this, but a `throw` inside try/catch is using exceptions
* for control-flow and is generally considered an anti-pattern. we can likely
* just not support this pattern, unless it really becomes necessary for some reason.
*/
builder.errors.push({
reason:
'(BuildHIR::lowerStatement) Support ThrowStatement inside of try/catch',
category: ErrorCategory.Todo,
loc: stmt.node.loc ?? null,
suggestions: null,
});
}
const terminal: ThrowTerminal = {
kind: 'throw',
value,
id: makeInstructionId(0),
loc: stmt.node.loc ?? GeneratedSource,
};
builder.terminate(terminal, 'block');
return;
}
case 'ReturnStatement': {
const stmt = stmtPath as NodePath<t.ReturnStatement>;
const argument = stmt.get('argument');
let value;
if (argument.node === null) {
value = lowerValueToTemporary(builder, {
kind: 'Primitive',
value: undefined,
loc: GeneratedSource,
});
} else {
value = lowerExpressionToTemporary(
builder,
argument as NodePath<t.Expression>,
);
}
const terminal: ReturnTerminal = {
kind: 'return',
returnVariant: 'Explicit',
loc: stmt.node.loc ?? GeneratedSource,
value,
id: makeInstructionId(0),
effects: null,
};
builder.terminate(terminal, 'block');
return;
}
case 'IfStatement': {
const stmt = stmtPath as NodePath<t.IfStatement>;
// Block for code following the if
const continuationBlock = builder.reserve('block');
// Block for the consequent (if the test is truthy)
const consequentBlock = builder.enter('block', _blockId => {
const consequent = stmt.get('consequent');
lowerStatement(builder, consequent);
return {
kind: 'goto',
block: continuationBlock.id,
variant: GotoVariant.Break,
id: makeInstructionId(0),
loc: consequent.node.loc ?? GeneratedSource,
};
});
// Block for the alternate (if the test is not truthy)
let alternateBlock: BlockId;
const alternate = stmt.get('alternate');
if (hasNode(alternate)) {
Domain
Subdomains
Calls
- addHoistedIdentifier()
- assertExhaustive()
- buildTemporaryPlace()
- enter()
- enterTryCatch()
- hasNode()
- invariant()
- isContextIdentifier()
- isHoistedIdentifier()
- label()
- lookupBreak()
- lookupContinue()
- loop()
- lowerAssignment()
- lowerExpressionToTemporary()
- lowerFunctionToValue()
- lowerReorderableExpression()
- lowerValueToTemporary()
- makeInstructionId()
- makeTemporary()
- promoteTemporary()
- push()
- reserve()
- resolveIdentifier()
- resolveThrowHandler()
- scope()
- terminate()
- terminateWithContinuation()
Called By
Source
Frequently Asked Questions
What does lowerStatement() do?
lowerStatement() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts.
Where is lowerStatement() defined?
lowerStatement() is defined in compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts at line 267.
What does lowerStatement() call?
lowerStatement() calls 28 function(s): addHoistedIdentifier, assertExhaustive, buildTemporaryPlace, enter, enterTryCatch, hasNode, invariant, isContextIdentifier, and 20 more.
What calls lowerStatement()?
lowerStatement() is called by 1 function(s): lower.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free