minimize() — react Function Reference
Architecture documentation for the minimize() function in minimize.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 4cc2ea3f_517f_a920_44fb_ae7d745078a5["minimize()"] 9c061da8_dbf8_4168_823d_991654a3c55d["minimize.ts"] 4cc2ea3f_517f_a920_44fb_ae7d745078a5 -->|defined in| 9c061da8_dbf8_4168_823d_991654a3c55d d5caee94_b787_985a_c66f_301a6cb1eaba["runMinimizeCommand()"] d5caee94_b787_985a_c66f_301a6cb1eaba -->|calls| 4cc2ea3f_517f_a920_44fb_ae7d745078a5 3163d778_6b57_8e52_d0c7_c4240e4d671b["compileAndGetError()"] 4cc2ea3f_517f_a920_44fb_ae7d745078a5 -->|calls| 3163d778_6b57_8e52_d0c7_c4240e4d671b 84e11526_9c5a_75eb_59ec_b8298c87ce7d["astToCode()"] 4cc2ea3f_517f_a920_44fb_ae7d745078a5 -->|calls| 84e11526_9c5a_75eb_59ec_b8298c87ce7d 7124ff95_0d0f_335d_9b44_ecea82e0d9f5["errorsMatch()"] 4cc2ea3f_517f_a920_44fb_ae7d745078a5 -->|calls| 7124ff95_0d0f_335d_9b44_ecea82e0d9f5 style 4cc2ea3f_517f_a920_44fb_ae7d745078a5 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/snap/src/minimize.ts lines 2045–2142
export function minimize(
input: string,
filename: string,
language: 'flow' | 'typescript',
sourceType: 'module' | 'script',
): MinimizeResult {
// Load the compiler plugin
const importedCompilerPlugin = require(BABEL_PLUGIN_SRC) as Record<
string,
unknown
>;
const BabelPluginReactCompiler = importedCompilerPlugin[
'default'
] as PluginObj;
const parseConfigPragmaForTests = importedCompilerPlugin[
PARSE_CONFIG_PRAGMA_IMPORT
] as typeof ParseConfigPragma;
// Get the initial error
const initialResult = compileAndGetError(
input,
filename,
language,
sourceType,
BabelPluginReactCompiler,
parseConfigPragmaForTests,
);
if (initialResult.kind === 'success') {
return {kind: 'success'};
}
if (initialResult.kind === 'parse_error') {
return {kind: 'success'};
}
const targetError = initialResult;
// Parse the initial AST
let currentAst = parseInput(input, filename, language, sourceType);
let currentCode = input;
let changed = true;
let iterations = 0;
const maxIterations = 1000; // Safety limit
process.stdout.write('\nMinimizing');
while (changed && iterations < maxIterations) {
changed = false;
iterations++;
// Try each simplification strategy
for (const strategy of simplificationStrategies) {
const generator = strategy.generator(currentAst);
for (const candidateAst of generator) {
let candidateCode: string;
try {
candidateCode = astToCode(candidateAst);
} catch {
// If code generation fails, skip this candidate
continue;
}
const result = compileAndGetError(
candidateCode,
filename,
language,
sourceType,
BabelPluginReactCompiler,
parseConfigPragmaForTests,
);
if (errorsMatch(targetError, result)) {
// This simplification preserves the error, keep it
currentAst = candidateAst;
currentCode = candidateCode;
changed = true;
process.stdout.write('.');
break; // Restart from the beginning with the new AST
}
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does minimize() do?
minimize() is a function in the react codebase, defined in compiler/packages/snap/src/minimize.ts.
Where is minimize() defined?
minimize() is defined in compiler/packages/snap/src/minimize.ts at line 2045.
What does minimize() call?
minimize() calls 3 function(s): astToCode, compileAndGetError, errorsMatch.
What calls minimize()?
minimize() is called by 1 function(s): runMinimizeCommand.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free