Gating.ts — react Source File
Architecture documentation for Gating.ts, a typescript file in the react codebase. 8 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 3acb56d9_57da_7e65_c06b_21b238146737["Gating.ts"] e96f281e_f381_272d_2359_3e6a091c9a1d["CompilerError.ts"] 3acb56d9_57da_7e65_c06b_21b238146737 --> e96f281e_f381_272d_2359_3e6a091c9a1d e51fd0d2_bb38_cc97_7763_efe37f300a47["CompilerError"] 3acb56d9_57da_7e65_c06b_21b238146737 --> e51fd0d2_bb38_cc97_7763_efe37f300a47 0423f759_97e0_9101_4634_ed555abc5ca9["index.ts"] 3acb56d9_57da_7e65_c06b_21b238146737 --> 0423f759_97e0_9101_4634_ed555abc5ca9 2a7e50cd_6171_085d_277c_6ced6ddd7148["Imports.ts"] 3acb56d9_57da_7e65_c06b_21b238146737 --> 2a7e50cd_6171_085d_277c_6ced6ddd7148 1bba49a9_dc32_ad8e_e249_ee6b8eb56d16["ProgramContext"] 3acb56d9_57da_7e65_c06b_21b238146737 --> 1bba49a9_dc32_ad8e_e249_ee6b8eb56d16 102f7d62_f771_0080_dd43_d867f5a8bd55["core"] 3acb56d9_57da_7e65_c06b_21b238146737 --> 102f7d62_f771_0080_dd43_d867f5a8bd55 52e3d8d7_abf4_7343_1f98_3f701ec04082["types"] 3acb56d9_57da_7e65_c06b_21b238146737 --> 52e3d8d7_abf4_7343_1f98_3f701ec04082 2ed45bcd_6c82_3ccd_0e20_fa96b5111055[".."] 3acb56d9_57da_7e65_c06b_21b238146737 --> 2ed45bcd_6c82_3ccd_0e20_fa96b5111055 9aa4477d_960b_1ea1_b6d9_36076aaa70bd["Program.ts"] 9aa4477d_960b_1ea1_b6d9_36076aaa70bd --> 3acb56d9_57da_7e65_c06b_21b238146737 style 3acb56d9_57da_7e65_c06b_21b238146737 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {NodePath} from '@babel/core';
import * as t from '@babel/types';
import {CompilerError} from '../CompilerError';
import {GeneratedSource} from '../HIR';
import {ProgramContext} from './Imports';
import {ExternalFunction} from '..';
/**
* Gating rewrite for function declarations which are referenced before their
* declaration site.
*
* ```js
* // original
* export default React.memo(Foo);
* function Foo() { ... }
*
* // React compiler optimized + gated
* import {gating} from 'myGating';
* export default React.memo(Foo);
* const gating_result = gating(); <- inserted
* function Foo_optimized() {} <- inserted
* function Foo_unoptimized() {} <- renamed from Foo
* function Foo() { <- inserted function, which can be hoisted by JS engines
* if (gating_result) return Foo_optimized();
* else return Foo_unoptimized();
* }
* ```
*/
function insertAdditionalFunctionDeclaration(
fnPath: NodePath<t.FunctionDeclaration>,
compiled: t.FunctionDeclaration,
programContext: ProgramContext,
gatingFunctionIdentifierName: string,
): void {
const originalFnName = fnPath.node.id;
const originalFnParams = fnPath.node.params;
const compiledParams = fnPath.node.params;
/**
* Note that other than `export default function() {}`, all other function
* declarations must have a binding identifier. Since default exports cannot
* be referenced, it's safe to assume that all function declarations passed
* here will have an identifier.
* https://tc39.es/ecma262/multipage/ecmascript-language-functions-and-classes.html#sec-function-definitions
*/
CompilerError.invariant(originalFnName != null && compiled.id != null, {
reason:
'Expected function declarations that are referenced elsewhere to have a named identifier',
loc: fnPath.node.loc ?? GeneratedSource,
});
CompilerError.invariant(originalFnParams.length === compiledParams.length, {
reason:
'Expected React Compiler optimized function declarations to have the same number of parameters as source',
loc: fnPath.node.loc ?? GeneratedSource,
// ... (161 more lines)
Domain
Subdomains
Functions
Dependencies
Source
Frequently Asked Questions
What does Gating.ts do?
Gating.ts is a source file in the react codebase, written in typescript. It belongs to the BabelCompiler domain, Entrypoint subdomain.
What functions are defined in Gating.ts?
Gating.ts defines 3 function(s): buildFunctionExpression, insertAdditionalFunctionDeclaration, insertGatedFunctionDeclaration.
What does Gating.ts depend on?
Gating.ts imports 8 module(s): .., CompilerError, CompilerError.ts, Imports.ts, ProgramContext, core, index.ts, types.
What files import Gating.ts?
Gating.ts is imported by 1 file(s): Program.ts.
Where is Gating.ts in the architecture?
Gating.ts is located at compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Gating.ts (domain: BabelCompiler, subdomain: Entrypoint, directory: compiler/packages/babel-plugin-react-compiler/src/Entrypoint).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free