validateSourceLocations() — react Function Reference
Architecture documentation for the validateSourceLocations() function in ValidateSourceLocations.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 1585633e_2e6a_1940_c40c_efddc2007c4d["validateSourceLocations()"] 87d539e4_ec1f_2367_e9d4_b39778249318["ValidateSourceLocations.ts"] 1585633e_2e6a_1940_c40c_efddc2007c4d -->|defined in| 87d539e4_ec1f_2367_e9d4_b39778249318 c3bc3875_256f_8f5e_7800_2f9c5bae65eb["runWithEnvironment()"] c3bc3875_256f_8f5e_7800_2f9c5bae65eb -->|calls| 1585633e_2e6a_1940_c40c_efddc2007c4d 3f815049_5f15_927c_9fa3_c1994d9c39c4["isManualMemoization()"] 1585633e_2e6a_1940_c40c_efddc2007c4d -->|calls| 3f815049_5f15_927c_9fa3_c1994d9c39c4 f5b6dce0_b016_1a9d_687a_0afa3e0b5f45["locationKey()"] 1585633e_2e6a_1940_c40c_efddc2007c4d -->|calls| f5b6dce0_b016_1a9d_687a_0afa3e0b5f45 style 1585633e_2e6a_1940_c40c_efddc2007c4d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateSourceLocations.ts lines 121–313
export function validateSourceLocations(
func: NodePath<
t.FunctionDeclaration | t.ArrowFunctionExpression | t.FunctionExpression
>,
generatedAst: CodegenFunction,
): Result<void, CompilerError> {
const errors = new CompilerError();
/*
* Step 1: Collect important locations from the original source
* Note: Multiple node types can share the same location (e.g. VariableDeclarator and Identifier)
*/
const importantOriginalLocations = new Map<
string,
{loc: t.SourceLocation; nodeTypes: Set<string>}
>();
func.traverse({
enter(path) {
const node = path.node;
// Only track node types that Istanbul instruments
if (!IMPORTANT_INSTRUMENTED_TYPES.has(node.type)) {
return;
}
// Skip manual memoization that the compiler intentionally removes
if (isManualMemoization(node)) {
return;
}
/*
* Skip return statements inside arrow functions that will be simplified to expression body.
* The compiler transforms `() => { return expr }` to `() => expr` in CodegenReactiveFunction
*/
if (t.isReturnStatement(node) && node.argument != null) {
const parentBody = path.parentPath;
const parentFunc = parentBody?.parentPath;
if (
parentBody?.isBlockStatement() &&
parentFunc?.isArrowFunctionExpression() &&
parentBody.node.body.length === 1 &&
parentBody.node.directives.length === 0
) {
return;
}
}
// Collect the location if it exists
if (node.loc) {
const key = locationKey(node.loc);
const existing = importantOriginalLocations.get(key);
if (existing) {
existing.nodeTypes.add(node.type);
} else {
importantOriginalLocations.set(key, {
loc: node.loc,
nodeTypes: new Set([node.type]),
});
}
}
},
});
// Step 2: Collect all locations from the generated AST with their node types
const generatedLocations = new Map<string, Set<string>>();
function collectGeneratedLocations(node: t.Node): void {
if (node.loc) {
const key = locationKey(node.loc);
const nodeTypes = generatedLocations.get(key);
if (nodeTypes) {
nodeTypes.add(node.type);
} else {
generatedLocations.set(key, new Set([node.type]));
}
}
// Use Babel's VISITOR_KEYS to traverse only actual node properties
const keys = t.VISITOR_KEYS[node.type as keyof typeof t.VISITOR_KEYS];
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does validateSourceLocations() do?
validateSourceLocations() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateSourceLocations.ts.
Where is validateSourceLocations() defined?
validateSourceLocations() is defined in compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateSourceLocations.ts at line 121.
What does validateSourceLocations() call?
validateSourceLocations() calls 2 function(s): isManualMemoization, locationKey.
What calls validateSourceLocations()?
validateSourceLocations() is called by 1 function(s): runWithEnvironment.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free