Home / Function/ compileAndGetError() — react Function Reference

compileAndGetError() — react Function Reference

Architecture documentation for the compileAndGetError() function in minimize.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  3163d778_6b57_8e52_d0c7_c4240e4d671b["compileAndGetError()"]
  9c061da8_dbf8_4168_823d_991654a3c55d["minimize.ts"]
  3163d778_6b57_8e52_d0c7_c4240e4d671b -->|defined in| 9c061da8_dbf8_4168_823d_991654a3c55d
  4cc2ea3f_517f_a920_44fb_ae7d745078a5["minimize()"]
  4cc2ea3f_517f_a920_44fb_ae7d745078a5 -->|calls| 3163d778_6b57_8e52_d0c7_c4240e4d671b
  style 3163d778_6b57_8e52_d0c7_c4240e4d671b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/snap/src/minimize.ts lines 28–102

function compileAndGetError(
  code: string,
  filename: string,
  language: 'flow' | 'typescript',
  sourceType: 'module' | 'script',
  plugin: PluginObj,
  parseConfigPragmaFn: typeof ParseConfigPragma,
): CompileResult {
  let ast: t.File;
  try {
    ast = parseInput(code, filename, language, sourceType);
  } catch (e: unknown) {
    return {kind: 'parse_error', message: (e as Error).message};
  }

  const firstLine = code.substring(0, code.indexOf('\n'));
  const config = parseConfigPragmaFn(firstLine, {compilationMode: 'all'});
  const options = {
    ...config,
    environment: {
      ...config.environment,
    },
    logger: {
      logEvent: () => {},
      debugLogIRs: () => {},
    },
    enableReanimatedCheck: false,
  };

  try {
    transformFromAstSync(ast, code, {
      filename: '/' + filename,
      highlightCode: false,
      retainLines: true,
      compact: true,
      plugins: [[plugin, options]],
      sourceType: 'module',
      ast: false,
      cloneInputAst: true,
      configFile: false,
      babelrc: false,
    });
    return {kind: 'success'};
  } catch (e: unknown) {
    const error = e as Error & {
      details?: Array<{
        category: string;
        reason: string;
        description: string | null;
      }>;
    };
    // Check if this is a CompilerError with details
    if (error.details && error.details.length > 0) {
      return {
        kind: 'errors',
        errors: error.details.map(detail => ({
          category: detail.category,
          reason: detail.reason,
          description: detail.description,
        })),
      };
    }
    // Fallback for other errors - use error name/message
    return {
      kind: 'errors',
      errors: [
        {
          category: error.name ?? 'Error',
          reason: error.message,
          description: null,
        },
      ],
    };
  }
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does compileAndGetError() do?
compileAndGetError() is a function in the react codebase, defined in compiler/packages/snap/src/minimize.ts.
Where is compileAndGetError() defined?
compileAndGetError() is defined in compiler/packages/snap/src/minimize.ts at line 28.
What calls compileAndGetError()?
compileAndGetError() is called by 1 function(s): minimize.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free