substitute() — react Function Reference
Architecture documentation for the substitute() function in TypeUtils.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 5b033808_ef9f_1c72_998b_14de0ddb4423["substitute()"] 1fccc28d_09ce_cbd9_cc1b_5224a1b90f93["TypeUtils.ts"] 5b033808_ef9f_1c72_998b_14de0ddb4423 -->|defined in| 1fccc28d_09ce_cbd9_cc1b_5224a1b90f93 d530521b_d20e_08a8_4bec_1170867678c4["mapType()"] 5b033808_ef9f_1c72_998b_14de0ddb4423 -->|calls| d530521b_d20e_08a8_4bec_1170867678c4 38999144_d544_edc0_6efe_18d9bf834ada["printType()"] 5b033808_ef9f_1c72_998b_14de0ddb4423 -->|calls| 38999144_d544_edc0_6efe_18d9bf834ada c0b647d9_982f_2dc6_de63_c350aa5665d4["printConcrete()"] 5b033808_ef9f_1c72_998b_14de0ddb4423 -->|calls| c0b647d9_982f_2dc6_de63_c350aa5665d4 style 5b033808_ef9f_1c72_998b_14de0ddb4423 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/Flood/TypeUtils.ts lines 14–55
export function substitute(
type: ConcreteType<ResolvedType>,
typeParameters: Array<TypeParameter<ResolvedType>>,
typeArguments: Array<ResolvedType>,
): ResolvedType {
const substMap = new Map<TypeParameterId, ResolvedType>();
for (let i = 0; i < typeParameters.length; i++) {
// TODO: Length checks to make sure type params match up with args
const typeParameter = typeParameters[i];
const typeArgument = typeArguments[i];
substMap.set(typeParameter.id, typeArgument);
}
const substitutionFunction = (t: ResolvedType): ResolvedType => {
// TODO: We really want a stateful mapper or visitor here so that we can model nested polymorphic types
if (t.type.kind === 'Generic' && substMap.has(t.type.id)) {
const substitutedType = substMap.get(t.type.id)!;
return substitutedType;
}
return {
kind: 'Concrete',
type: mapType(substitutionFunction, t.type),
platform: t.platform,
};
};
const substituted = mapType(substitutionFunction, type);
if (DEBUG) {
let substs = '';
for (let i = 0; i < typeParameters.length; i++) {
const typeParameter = typeParameters[i];
const typeArgument = typeArguments[i];
substs += `[${typeParameter.name}${typeParameter.id} := ${printType(typeArgument)}]`;
}
console.log(
`${printConcrete(type, printType)}${substs} = ${printConcrete(substituted, printType)}`,
);
}
return {kind: 'Concrete', type: substituted, platform: /* TODO */ 'shared'};
}
Domain
Subdomains
Source
Frequently Asked Questions
What does substitute() do?
substitute() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Flood/TypeUtils.ts.
Where is substitute() defined?
substitute() is defined in compiler/packages/babel-plugin-react-compiler/src/Flood/TypeUtils.ts at line 14.
What does substitute() call?
substitute() calls 3 function(s): mapType, printConcrete, printType.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free