diff() — react Function Reference
Architecture documentation for the diff() function in TypeUtils.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 32d9a46d_2c9f_4d15_f8fb_432c549e02fa["diff()"] 1fccc28d_09ce_cbd9_cc1b_5224a1b90f93["TypeUtils.ts"] 32d9a46d_2c9f_4d15_f8fb_432c549e02fa -->|defined in| 1fccc28d_09ce_cbd9_cc1b_5224a1b90f93 30ec2474_aaf0_f8e7_9820_34b266dc18e0["unsupportedLanguageFeature()"] 32d9a46d_2c9f_4d15_f8fb_432c549e02fa -->|calls| 30ec2474_aaf0_f8e7_9820_34b266dc18e0 d7fde76c_4fd9_feb3_299b_798689f05bc6["assertExhaustive()"] 32d9a46d_2c9f_4d15_f8fb_432c549e02fa -->|calls| d7fde76c_4fd9_feb3_299b_798689f05bc6 style 32d9a46d_2c9f_4d15_f8fb_432c549e02fa fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/Flood/TypeUtils.ts lines 145–305
export function diff<R, T>(
a: ConcreteType<T>,
b: ConcreteType<T>,
onChild: (a: T, b: T) => R,
onChildMismatch: (child: R, cur: R) => R,
onMismatch: (a: ConcreteType<T>, b: ConcreteType<T>, cur: R) => R,
init: R,
): R {
let errors = init;
// Check if kinds match
if (a.kind !== b.kind) {
errors = onMismatch(a, b, errors);
return errors;
}
// Based on kind, check other properties
switch (a.kind) {
case 'Mixed':
case 'Number':
case 'String':
case 'Boolean':
case 'Void':
// Simple types, no further checks needed
break;
case 'Nullable':
// Check the nested type
errors = onChildMismatch(onChild(a.type, (b as typeof a).type), errors);
break;
case 'Array':
case 'Set':
// Check the element type
errors = onChildMismatch(
onChild(a.element, (b as typeof a).element),
errors,
);
break;
case 'Map':
// Check both key and value types
errors = onChildMismatch(onChild(a.key, (b as typeof a).key), errors);
errors = onChildMismatch(onChild(a.value, (b as typeof a).value), errors);
break;
case 'Function': {
const bFunc = b as typeof a;
// Check type parameters
if ((a.typeParameters == null) !== (bFunc.typeParameters == null)) {
errors = onMismatch(a, b, errors);
}
if (a.typeParameters != null && bFunc.typeParameters != null) {
if (a.typeParameters.length !== bFunc.typeParameters.length) {
errors = onMismatch(a, b, errors);
}
// Type parameters are just numbers, so we can compare them directly
for (let i = 0; i < a.typeParameters.length; i++) {
if (a.typeParameters[i] !== bFunc.typeParameters[i]) {
errors = onMismatch(a, b, errors);
}
}
}
// Check parameters
if (a.params.length !== bFunc.params.length) {
errors = onMismatch(a, b, errors);
}
for (let i = 0; i < a.params.length; i++) {
errors = onChildMismatch(onChild(a.params[i], bFunc.params[i]), errors);
}
// Check return type
errors = onChildMismatch(onChild(a.returnType, bFunc.returnType), errors);
break;
}
Domain
Subdomains
Source
Frequently Asked Questions
What does diff() do?
diff() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Flood/TypeUtils.ts.
Where is diff() defined?
diff() is defined in compiler/packages/babel-plugin-react-compiler/src/Flood/TypeUtils.ts at line 145.
What does diff() call?
diff() calls 2 function(s): assertExhaustive, unsupportedLanguageFeature.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free