ValidateUseMemo.ts — react Source File
Architecture documentation for ValidateUseMemo.ts, a typescript file in the react codebase. 10 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 50f9142a_be38_a654_5f39_5cea59a5336d["ValidateUseMemo.ts"] e96f281e_f381_272d_2359_3e6a091c9a1d["CompilerError.ts"] 50f9142a_be38_a654_5f39_5cea59a5336d --> e96f281e_f381_272d_2359_3e6a091c9a1d 0fda7f86_b7a3_c1f2_f0d9_8d13eed4f042["CompilerDiagnostic"] 50f9142a_be38_a654_5f39_5cea59a5336d --> 0fda7f86_b7a3_c1f2_f0d9_8d13eed4f042 e51fd0d2_bb38_cc97_7763_efe37f300a47["CompilerError"] 50f9142a_be38_a654_5f39_5cea59a5336d --> e51fd0d2_bb38_cc97_7763_efe37f300a47 a2b91621_58d3_1d04_4663_00cd808f1034["ErrorCategory"] 50f9142a_be38_a654_5f39_5cea59a5336d --> a2b91621_58d3_1d04_4663_00cd808f1034 0423f759_97e0_9101_4634_ed555abc5ca9["index.ts"] 50f9142a_be38_a654_5f39_5cea59a5336d --> 0423f759_97e0_9101_4634_ed555abc5ca9 2f3caf55_cc64_415c_55dd_9771ba7dc210["visitors.ts"] 50f9142a_be38_a654_5f39_5cea59a5336d --> 2f3caf55_cc64_415c_55dd_9771ba7dc210 b2fc2985_a7ba_9865_c2a3_2a7531f27d44["eachInstructionValueOperand"] 50f9142a_be38_a654_5f39_5cea59a5336d --> b2fc2985_a7ba_9865_c2a3_2a7531f27d44 41232a25_deb6_6e83_05a8_ae9f961656f7["eachTerminalOperand"] 50f9142a_be38_a654_5f39_5cea59a5336d --> 41232a25_deb6_6e83_05a8_ae9f961656f7 494e3425_0b47_293a_1ea4_d4670b0fc0e7["Result.ts"] 50f9142a_be38_a654_5f39_5cea59a5336d --> 494e3425_0b47_293a_1ea4_d4670b0fc0e7 7aace723_0ee1_cff5_b263_aec8e06dd79e["Result"] 50f9142a_be38_a654_5f39_5cea59a5336d --> 7aace723_0ee1_cff5_b263_aec8e06dd79e style 50f9142a_be38_a654_5f39_5cea59a5336d 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 {
CompilerDiagnostic,
CompilerError,
ErrorCategory,
} from '../CompilerError';
import {
FunctionExpression,
HIRFunction,
IdentifierId,
SourceLocation,
} from '../HIR';
import {
eachInstructionValueOperand,
eachTerminalOperand,
} from '../HIR/visitors';
import {Result} from '../Utils/Result';
export function validateUseMemo(fn: HIRFunction): Result<void, CompilerError> {
const errors = new CompilerError();
const voidMemoErrors = new CompilerError();
const useMemos = new Set<IdentifierId>();
const react = new Set<IdentifierId>();
const functions = new Map<IdentifierId, FunctionExpression>();
const unusedUseMemos = new Map<IdentifierId, SourceLocation>();
for (const [, block] of fn.body.blocks) {
for (const {lvalue, value} of block.instructions) {
if (unusedUseMemos.size !== 0) {
/**
* Most of the time useMemo results are referenced immediately. Don't bother
* scanning instruction operands for useMemos unless there is an as-yet-unused
* useMemo.
*/
for (const operand of eachInstructionValueOperand(value)) {
unusedUseMemos.delete(operand.identifier.id);
}
}
switch (value.kind) {
case 'LoadGlobal': {
if (value.binding.name === 'useMemo') {
useMemos.add(lvalue.identifier.id);
} else if (value.binding.name === 'React') {
react.add(lvalue.identifier.id);
}
break;
}
case 'PropertyLoad': {
if (react.has(value.object.identifier.id)) {
if (value.property === 'useMemo') {
useMemos.add(lvalue.identifier.id);
}
}
break;
}
// ... (169 more lines)
Domain
Subdomains
Dependencies
Source
Frequently Asked Questions
What does ValidateUseMemo.ts do?
ValidateUseMemo.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 ValidateUseMemo.ts?
ValidateUseMemo.ts defines 3 function(s): hasNonVoidReturn, validateNoContextVariableAssignment, validateUseMemo.
What does ValidateUseMemo.ts depend on?
ValidateUseMemo.ts imports 10 module(s): CompilerDiagnostic, CompilerError, CompilerError.ts, ErrorCategory, Result, Result.ts, eachInstructionValueOperand, eachTerminalOperand, and 2 more.
Where is ValidateUseMemo.ts in the architecture?
ValidateUseMemo.ts is located at compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateUseMemo.ts (domain: BabelCompiler, subdomain: Validation, directory: compiler/packages/babel-plugin-react-compiler/src/Validation).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free