Home / File/ ValidateSourceLocations.ts — react Source File

ValidateSourceLocations.ts — react Source File

Architecture documentation for ValidateSourceLocations.ts, a typescript file in the react codebase. 6 imports, 1 dependents.

File typescript BabelCompiler Validation 6 imports 1 dependents 3 functions

Entity Profile

Dependency Diagram

graph LR
  87d539e4_ec1f_2367_e9d4_b39778249318["ValidateSourceLocations.ts"]
  0291e079_1c14_3cf3_45da_30767ab28e42["index.ts"]
  87d539e4_ec1f_2367_e9d4_b39778249318 --> 0291e079_1c14_3cf3_45da_30767ab28e42
  494e3425_0b47_293a_1ea4_d4670b0fc0e7["Result.ts"]
  87d539e4_ec1f_2367_e9d4_b39778249318 --> 494e3425_0b47_293a_1ea4_d4670b0fc0e7
  7aace723_0ee1_cff5_b263_aec8e06dd79e["Result"]
  87d539e4_ec1f_2367_e9d4_b39778249318 --> 7aace723_0ee1_cff5_b263_aec8e06dd79e
  ceff537f_04b5_ea96_fed3_19a0a7315bc6["traverse"]
  87d539e4_ec1f_2367_e9d4_b39778249318 --> ceff537f_04b5_ea96_fed3_19a0a7315bc6
  52e3d8d7_abf4_7343_1f98_3f701ec04082["types"]
  87d539e4_ec1f_2367_e9d4_b39778249318 --> 52e3d8d7_abf4_7343_1f98_3f701ec04082
  2ed45bcd_6c82_3ccd_0e20_fa96b5111055[".."]
  87d539e4_ec1f_2367_e9d4_b39778249318 --> 2ed45bcd_6c82_3ccd_0e20_fa96b5111055
  e3cfc07a_10c8_5dcd_e270_e8e14c29309b["Pipeline.ts"]
  e3cfc07a_10c8_5dcd_e270_e8e14c29309b --> 87d539e4_ec1f_2367_e9d4_b39778249318
  style 87d539e4_ec1f_2367_e9d4_b39778249318 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/traverse';
import * as t from '@babel/types';
import {CompilerDiagnostic, CompilerError, ErrorCategory} from '..';
import {CodegenFunction} from '../ReactiveScopes';
import {Result} from '../Utils/Result';

/**
 * IMPORTANT: This validation is only intended for use in unit tests.
 * It is not intended for use in production.
 *
 * This validation is used to ensure that the generated AST has proper source locations
 * for "important" original nodes.
 *
 * There's one big gotcha with this validation: it only works if the "important" original nodes
 * are not optimized away by the compiler.
 *
 * When that scenario happens, we should just update the fixture to not include a node that has no
 * corresponding node in the generated AST due to being completely removed during compilation.
 */

/**
 * Some common node types that are important for coverage tracking.
 * Based on istanbul-lib-instrument + some other common nodes we expect to be present in the generated AST.
 *
 * Note: For VariableDeclaration, VariableDeclarator, and Identifier, we enforce stricter validation
 * that requires both the source location AND node type to match in the generated AST. This ensures
 * that variable declarations maintain their structural integrity through compilation.
 */
const IMPORTANT_INSTRUMENTED_TYPES = new Set([
  'ArrowFunctionExpression',
  'AssignmentPattern',
  'ObjectMethod',
  'ExpressionStatement',
  'BreakStatement',
  'ContinueStatement',
  'ReturnStatement',
  'ThrowStatement',
  'TryStatement',
  'VariableDeclarator',
  'IfStatement',
  'ForStatement',
  'ForInStatement',
  'ForOfStatement',
  'WhileStatement',
  'DoWhileStatement',
  'SwitchStatement',
  'SwitchCase',
  'WithStatement',
  'FunctionDeclaration',
  'FunctionExpression',
  'LabeledStatement',
  'ConditionalExpression',
  'LogicalExpression',
// ... (254 more lines)

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does ValidateSourceLocations.ts do?
ValidateSourceLocations.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 ValidateSourceLocations.ts?
ValidateSourceLocations.ts defines 3 function(s): isManualMemoization, locationKey, validateSourceLocations.
What does ValidateSourceLocations.ts depend on?
ValidateSourceLocations.ts imports 6 module(s): .., Result, Result.ts, index.ts, traverse, types.
What files import ValidateSourceLocations.ts?
ValidateSourceLocations.ts is imported by 1 file(s): Pipeline.ts.
Where is ValidateSourceLocations.ts in the architecture?
ValidateSourceLocations.ts is located at compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateSourceLocations.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