codegenReactiveScope() — react Function Reference
Architecture documentation for the codegenReactiveScope() function in CodegenReactiveFunction.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 94638464_4710_0693_528f_4848cf25e876["codegenReactiveScope()"] dc7f10c2_c914_a162_d02b_a10a15c64a5f["CodegenReactiveFunction.ts"] 94638464_4710_0693_528f_4848cf25e876 -->|defined in| dc7f10c2_c914_a162_d02b_a10a15c64a5f 6913ca73_f3c4_9919_bf65_7b95559378b7["codegenBlockNoReset()"] 6913ca73_f3c4_9919_bf65_7b95559378b7 -->|calls| 94638464_4710_0693_528f_4848cf25e876 073c81a5_c389_d108_5b8f_4d6dc6eece83["push()"] 94638464_4710_0693_528f_4848cf25e876 -->|calls| 073c81a5_c389_d108_5b8f_4d6dc6eece83 aebeff4e_7cd5_bdc3_0d8d_cac388c83fb4["printDependencyComment()"] 94638464_4710_0693_528f_4848cf25e876 -->|calls| aebeff4e_7cd5_bdc3_0d8d_cac388c83fb4 a599ee29_a03a_9f21_bb90_a7ef23973fc6["synthesizeName()"] 94638464_4710_0693_528f_4848cf25e876 -->|calls| a599ee29_a03a_9f21_bb90_a7ef23973fc6 9380734b_cfd2_bad5_b83a_eeadc55aca3b["codegenDependency()"] 94638464_4710_0693_528f_4848cf25e876 -->|calls| 9380734b_cfd2_bad5_b83a_eeadc55aca3b 0cd5721d_3385_49af_c06a_4e7b0f6230da["compareScopeDeclaration()"] 94638464_4710_0693_528f_4848cf25e876 -->|calls| 0cd5721d_3385_49af_c06a_4e7b0f6230da 041ca752_10c1_3cda_1f5c_02f44a01310e["invariant()"] 94638464_4710_0693_528f_4848cf25e876 -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e e7a01d7c_c128_be66_a07d_007952a380da["printIdentifier()"] 94638464_4710_0693_528f_4848cf25e876 -->|calls| e7a01d7c_c128_be66_a07d_007952a380da 9bb6f6d9_ff05_0f27_1a27_bc67145db7ba["convertIdentifier()"] 94638464_4710_0693_528f_4848cf25e876 -->|calls| 9bb6f6d9_ff05_0f27_1a27_bc67145db7ba 43b28878_9b1d_6aeb_0d77_25080004044d["hasDeclared()"] 94638464_4710_0693_528f_4848cf25e876 -->|calls| 43b28878_9b1d_6aeb_0d77_25080004044d 6a903108_0a0b_6e52_019e_0b534b909b09["createVariableDeclarator()"] 94638464_4710_0693_528f_4848cf25e876 -->|calls| 6a903108_0a0b_6e52_019e_0b534b909b09 93513a6b_e98a_59dd_9d2d_7756ef0a1fc0["wrapCacheDep()"] 94638464_4710_0693_528f_4848cf25e876 -->|calls| 93513a6b_e98a_59dd_9d2d_7756ef0a1fc0 a9a859b4_40bd_bdc3_176d_9a4435a365fc["declare()"] 94638464_4710_0693_528f_4848cf25e876 -->|calls| a9a859b4_40bd_bdc3_176d_9a4435a365fc style 94638464_4710_0693_528f_4848cf25e876 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts lines 601–935
function codegenReactiveScope(
cx: Context,
statements: Array<t.Statement>,
scope: ReactiveScope,
block: ReactiveBlock,
): void {
const cacheStoreStatements: Array<t.Statement> = [];
const cacheLoadStatements: Array<t.Statement> = [];
const cacheLoads: Array<{
name: t.Identifier;
index: number;
value: t.Expression;
}> = [];
const changeExpressions: Array<t.Expression> = [];
const changeExpressionComments: Array<string> = [];
const outputComments: Array<string> = [];
for (const dep of [...scope.dependencies].sort(compareScopeDependency)) {
const index = cx.nextCacheIndex;
changeExpressionComments.push(printDependencyComment(dep));
const comparison = t.binaryExpression(
'!==',
t.memberExpression(
t.identifier(cx.synthesizeName('$')),
t.numericLiteral(index),
true,
),
codegenDependency(cx, dep),
);
if (cx.env.config.enableChangeVariableCodegen) {
const changeIdentifier = t.identifier(cx.synthesizeName(`c_${index}`));
statements.push(
t.variableDeclaration('const', [
t.variableDeclarator(changeIdentifier, comparison),
]),
);
changeExpressions.push(changeIdentifier);
} else {
changeExpressions.push(comparison);
}
/*
* Adding directly to cacheStoreStatements rather than cacheLoads, because there
* is no corresponding cacheLoadStatement for dependencies
*/
cacheStoreStatements.push(
t.expressionStatement(
t.assignmentExpression(
'=',
t.memberExpression(
t.identifier(cx.synthesizeName('$')),
t.numericLiteral(index),
true,
),
codegenDependency(cx, dep),
),
),
);
}
let firstOutputIndex: number | null = null;
for (const [, {identifier}] of [...scope.declarations].sort(([, a], [, b]) =>
compareScopeDeclaration(a, b),
)) {
const index = cx.nextCacheIndex;
if (firstOutputIndex === null) {
firstOutputIndex = index;
}
CompilerError.invariant(identifier.name != null, {
reason: `Expected scope declaration identifier to be named`,
description: `Declaration \`${printIdentifier(
identifier,
)}\` is unnamed in scope @${scope.id}`,
loc: GeneratedSource,
});
const name = convertIdentifier(identifier);
outputComments.push(name.name);
if (!cx.hasDeclared(identifier)) {
statements.push(
Domain
Subdomains
Defined In
Calls
Called By
Source
Frequently Asked Questions
What does codegenReactiveScope() do?
codegenReactiveScope() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts.
Where is codegenReactiveScope() defined?
codegenReactiveScope() is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts at line 601.
What does codegenReactiveScope() call?
codegenReactiveScope() calls 14 function(s): codegenBlock, codegenDependency, compareScopeDeclaration, convertIdentifier, createVariableDeclarator, declare, hasDeclared, invariant, and 6 more.
What calls codegenReactiveScope()?
codegenReactiveScope() is called by 1 function(s): codegenBlockNoReset.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free