RenameVariables.ts — react Source File
Architecture documentation for RenameVariables.ts, a typescript file in the react codebase. 23 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR a67a8ce3_d9a8_a740_fb57_bc90354f75e7["RenameVariables.ts"] e96f281e_f381_272d_2359_3e6a091c9a1d["CompilerError.ts"] a67a8ce3_d9a8_a740_fb57_bc90354f75e7 --> e96f281e_f381_272d_2359_3e6a091c9a1d e51fd0d2_bb38_cc97_7763_efe37f300a47["CompilerError"] a67a8ce3_d9a8_a740_fb57_bc90354f75e7 --> e51fd0d2_bb38_cc97_7763_efe37f300a47 18a78965_f593_105b_e5e8_07001321c2ec["HIR.ts"] a67a8ce3_d9a8_a740_fb57_bc90354f75e7 --> 18a78965_f593_105b_e5e8_07001321c2ec bf1aef24_2e0f_0adb_12d8_9e5ba8245644["DeclarationId"] a67a8ce3_d9a8_a740_fb57_bc90354f75e7 --> bf1aef24_2e0f_0adb_12d8_9e5ba8245644 bd003dbd_e691_524b_0cf4_50e080ffea94["Identifier"] a67a8ce3_d9a8_a740_fb57_bc90354f75e7 --> bd003dbd_e691_524b_0cf4_50e080ffea94 ea5e48f3_55e1_acac_8e6d_5c938ddce255["IdentifierName"] a67a8ce3_d9a8_a740_fb57_bc90354f75e7 --> ea5e48f3_55e1_acac_8e6d_5c938ddce255 23767d65_9554_fcd2_f2aa_7de7634389f9["InstructionId"] a67a8ce3_d9a8_a740_fb57_bc90354f75e7 --> 23767d65_9554_fcd2_f2aa_7de7634389f9 c7aaa235_c19e_3530_31c2_911f38eed3e0["Place"] a67a8ce3_d9a8_a740_fb57_bc90354f75e7 --> c7aaa235_c19e_3530_31c2_911f38eed3e0 02f69dfe_af02_6deb_8891_1b0229142fd1["PrunedReactiveScopeBlock"] a67a8ce3_d9a8_a740_fb57_bc90354f75e7 --> 02f69dfe_af02_6deb_8891_1b0229142fd1 548400ef_0d5c_3a1e_0c02_c3a80b0d17e4["ReactiveBlock"] a67a8ce3_d9a8_a740_fb57_bc90354f75e7 --> 548400ef_0d5c_3a1e_0c02_c3a80b0d17e4 c0555545_1ea3_9d37_62ad_521eafe2daa8["ReactiveFunction"] a67a8ce3_d9a8_a740_fb57_bc90354f75e7 --> c0555545_1ea3_9d37_62ad_521eafe2daa8 0fba6722_c385_0076_d75b_47ee3ff87ee3["ReactiveScopeBlock"] a67a8ce3_d9a8_a740_fb57_bc90354f75e7 --> 0fba6722_c385_0076_d75b_47ee3ff87ee3 03931fe0_84fd_a4e9_b75a_03f9d092be95["ReactiveValue"] a67a8ce3_d9a8_a740_fb57_bc90354f75e7 --> 03931fe0_84fd_a4e9_b75a_03f9d092be95 a6e982a6_6673_ebe4_110e_b60172814f78["ValidIdentifierName"] a67a8ce3_d9a8_a740_fb57_bc90354f75e7 --> a6e982a6_6673_ebe4_110e_b60172814f78 style a67a8ce3_d9a8_a740_fb57_bc90354f75e7 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 {ProgramContext} from '..';
import {CompilerError} from '../CompilerError';
import {
DeclarationId,
GeneratedSource,
Identifier,
IdentifierName,
InstructionId,
Place,
PrunedReactiveScopeBlock,
ReactiveBlock,
ReactiveFunction,
ReactiveScopeBlock,
ReactiveValue,
ValidIdentifierName,
isPromotedJsxTemporary,
isPromotedTemporary,
makeIdentifierName,
} from '../HIR/HIR';
import {collectReferencedGlobals} from './CollectReferencedGlobals';
import {ReactiveFunctionVisitor, visitReactiveFunction} from './visitors';
/**
* Ensures that each named variable in the given function has a unique name
* that does not conflict with any other variables in the same block scope.
* Note that the scoping is based on the final inferred blocks, not the
* block scopes that were present in the original source. Thus variables
* that shadowed in the original source may end up with unique names in the
* output, if Forget would merge those two blocks into a single scope.
*
* Variables are renamed using their original name followed by a number,
* starting with 0 and incrementing until a unique name is found. Eg if the
* compiler collapses three scopes that each had their own `foo` declaration,
* they will be renamed to `foo`, `foo0`, and `foo1`, assuming that no conflicts'
* exist for `foo0` and `foo1`.
*
* For temporary values that are promoted to named variables, the starting name
* is "T0" for values that appear in JSX tag position and "t0" otherwise. If this
* name conflicts, the number portion increments until the name is unique (t1, t2, etc).
*
* Returns a Set of all the unique variable names in the function after renaming.
*/
export function renameVariables(fn: ReactiveFunction): Set<string> {
const globals = collectReferencedGlobals(fn);
const scopes = new Scopes(globals, fn.env.programContext);
renameVariablesImpl(fn, new Visitor(), scopes);
return new Set([...scopes.names, ...globals]);
}
function renameVariablesImpl(
fn: ReactiveFunction,
visitor: Visitor,
scopes: Scopes,
// ... (133 more lines)
Domain
Subdomains
Functions
Dependencies
- ..
- CollectReferencedGlobals.ts
- CompilerError
- CompilerError.ts
- DeclarationId
- HIR.ts
- Identifier
- IdentifierName
- InstructionId
- Place
- PrunedReactiveScopeBlock
- ReactiveBlock
- ReactiveFunction
- ReactiveFunctionVisitor
- ReactiveScopeBlock
- ReactiveValue
- ValidIdentifierName
- collectReferencedGlobals
- isPromotedJsxTemporary
- isPromotedTemporary
- makeIdentifierName
- visitReactiveFunction
- visitors.ts
Source
Frequently Asked Questions
What does RenameVariables.ts do?
RenameVariables.ts is a source file in the react codebase, written in typescript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in RenameVariables.ts?
RenameVariables.ts defines 2 function(s): renameVariables, renameVariablesImpl.
What does RenameVariables.ts depend on?
RenameVariables.ts imports 23 module(s): .., CollectReferencedGlobals.ts, CompilerError, CompilerError.ts, DeclarationId, HIR.ts, Identifier, IdentifierName, and 15 more.
Where is RenameVariables.ts in the architecture?
RenameVariables.ts is located at compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/RenameVariables.ts (domain: BabelCompiler, subdomain: Validation, directory: compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free