NameAnonymousFunctions.ts — react Source File
Architecture documentation for NameAnonymousFunctions.ts, a typescript file in the react codebase. 1 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 701ffa03_e96c_b2c6_bca0_39530945bc61["NameAnonymousFunctions.ts"] 0423f759_97e0_9101_4634_ed555abc5ca9["index.ts"] 701ffa03_e96c_b2c6_bca0_39530945bc61 --> 0423f759_97e0_9101_4634_ed555abc5ca9 e3cfc07a_10c8_5dcd_e270_e8e14c29309b["Pipeline.ts"] e3cfc07a_10c8_5dcd_e270_e8e14c29309b --> 701ffa03_e96c_b2c6_bca0_39530945bc61 style 701ffa03_e96c_b2c6_bca0_39530945bc61 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 {
FunctionExpression,
getHookKind,
HIRFunction,
IdentifierId,
} from '../HIR';
export function nameAnonymousFunctions(fn: HIRFunction): void {
if (fn.id == null) {
return;
}
const parentName = fn.id;
const functions = nameAnonymousFunctionsImpl(fn);
function visit(node: Node, prefix: string): void {
if (node.generatedName != null && node.fn.nameHint == null) {
/**
* Note that we don't generate a name for functions that already had one,
* so we'll only add the prefix to anonymous functions regardless of
* nesting depth.
*/
const name = `${prefix}${node.generatedName}]`;
node.fn.nameHint = name;
node.fn.loweredFunc.func.nameHint = name;
}
/**
* Whether or not we generated a name for the function at this node,
* traverse into its nested functions to assign them names
*/
const nextPrefix = `${prefix}${node.generatedName ?? node.fn.name ?? '<anonymous>'} > `;
for (const inner of node.inner) {
visit(inner, nextPrefix);
}
}
for (const node of functions) {
visit(node, `${parentName}[`);
}
}
type Node = {
fn: FunctionExpression;
generatedName: string | null;
inner: Array<Node>;
};
function nameAnonymousFunctionsImpl(fn: HIRFunction): Array<Node> {
// Functions that we track to generate names for
const functions: Map<IdentifierId, Node> = new Map();
// Tracks temporaries that read from variables/globals/properties
const names: Map<IdentifierId, string> = new Map();
// Tracks all function nodes to bubble up for later renaming
const nodes: Array<Node> = [];
for (const block of fn.body.blocks.values()) {
for (const instr of block.instructions) {
// ... (120 more lines)
Domain
Subdomains
Types
Dependencies
Source
Frequently Asked Questions
What does NameAnonymousFunctions.ts do?
NameAnonymousFunctions.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 NameAnonymousFunctions.ts?
NameAnonymousFunctions.ts defines 2 function(s): nameAnonymousFunctions, nameAnonymousFunctionsImpl.
What does NameAnonymousFunctions.ts depend on?
NameAnonymousFunctions.ts imports 1 module(s): index.ts.
What files import NameAnonymousFunctions.ts?
NameAnonymousFunctions.ts is imported by 1 file(s): Pipeline.ts.
Where is NameAnonymousFunctions.ts in the architecture?
NameAnonymousFunctions.ts is located at compiler/packages/babel-plugin-react-compiler/src/Transform/NameAnonymousFunctions.ts (domain: BabelCompiler, subdomain: Validation, directory: compiler/packages/babel-plugin-react-compiler/src/Transform).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free