Home / File/ RunReactCompiler.ts — react Source File

RunReactCompiler.ts — react Source File

Architecture documentation for RunReactCompiler.ts, a typescript file in the react codebase. 8 imports, 1 dependents.

File typescript BabelCompiler Validation 8 imports 1 dependents 5 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  0e801e17_9dc9_7a83_ce0f_d28b56e090f5["RunReactCompiler.ts"]
  102f7d62_f771_0080_dd43_d867f5a8bd55["core"]
  0e801e17_9dc9_7a83_ce0f_d28b56e090f5 --> 102f7d62_f771_0080_dd43_d867f5a8bd55
  ba38a3cc_fa9d_cd5d_0746_ec93bcb397e1["parser"]
  0e801e17_9dc9_7a83_ce0f_d28b56e090f5 --> ba38a3cc_fa9d_cd5d_0746_ec93bcb397e1
  52e3d8d7_abf4_7343_1f98_3f701ec04082["types"]
  0e801e17_9dc9_7a83_ce0f_d28b56e090f5 --> 52e3d8d7_abf4_7343_1f98_3f701ec04082
  33e3aca7_66ee_ce27_72ad_b6d7fb17e06c["babel-plugin-react-compiler"]
  0e801e17_9dc9_7a83_ce0f_d28b56e090f5 --> 33e3aca7_66ee_ce27_72ad_b6d7fb17e06c
  e023ae51_0bf7_c8b1_0545_8e7304e4bb72["eslint"]
  0e801e17_9dc9_7a83_ce0f_d28b56e090f5 --> e023ae51_0bf7_c8b1_0545_8e7304e4bb72
  14c74228_2987_7343_cb97_b89a9b190db6["estree"]
  0e801e17_9dc9_7a83_ce0f_d28b56e090f5 --> 14c74228_2987_7343_cb97_b89a9b190db6
  78f0dea0_5a25_0652_2a88_959a2ce71a1f["hermes-parser"]
  0e801e17_9dc9_7a83_ce0f_d28b56e090f5 --> 78f0dea0_5a25_0652_2a88_959a2ce71a1f
  e38503ff_90ab_2fd6_8dbb_f5a5a0bd5a1b["util"]
  0e801e17_9dc9_7a83_ce0f_d28b56e090f5 --> e38503ff_90ab_2fd6_8dbb_f5a5a0bd5a1b
  40190dd7_cea0_7135_9d7e_df5f2d3454b7["ReactCompiler.ts"]
  40190dd7_cea0_7135_9d7e_df5f2d3454b7 --> 0e801e17_9dc9_7a83_ce0f_d28b56e090f5
  style 0e801e17_9dc9_7a83_ce0f_d28b56e090f5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
/* eslint-disable no-for-of-loops/no-for-of-loops */

import {transformFromAstSync} from '@babel/core';
import {parse as babelParse} from '@babel/parser';
import {File} from '@babel/types';
import BabelPluginReactCompiler, {
  parsePluginOptions,
  validateEnvironmentConfig,
  type PluginOptions,
  Logger,
  LoggerEvent,
} from 'babel-plugin-react-compiler';
import type {SourceCode} from 'eslint';
import type * as ESTree from 'estree';
import * as HermesParser from 'hermes-parser';
import {isDeepStrictEqual} from 'util';
import type {ParseResult} from '@babel/parser';

// Pattern for component names: starts with uppercase letter
const COMPONENT_NAME_PATTERN = /^[A-Z]/;
// Pattern for hook names: starts with 'use' followed by uppercase letter or digit
const HOOK_NAME_PATTERN = /^use[A-Z0-9]/;

/**
 * Quick heuristic using ESLint's already-parsed AST to detect if the file
 * may contain React components or hooks based on function naming patterns.
 * Only checks top-level declarations since components/hooks are declared at module scope.
 * Returns true if compilation should proceed, false to skip.
 */
function mayContainReactCode(sourceCode: SourceCode): boolean {
  const ast = sourceCode.ast;

  // Only check top-level statements - components/hooks are declared at module scope
  for (const node of ast.body) {
    if (checkTopLevelNode(node)) {
      return true;
    }
  }

  return false;
}

function checkTopLevelNode(node: ESTree.Node): boolean {
  // Handle Flow component/hook declarations (hermes-eslint produces these node types)
  // @ts-expect-error not part of ESTree spec
  if (node.type === 'ComponentDeclaration' || node.type === 'HookDeclaration') {
    return true;
  }

  // Handle: export function MyComponent() {} or export const useHook = () => {}
  if (node.type === 'ExportNamedDeclaration') {
    const decl = (node as ESTree.ExportNamedDeclaration).declaration;
    if (decl != null) {
      return checkTopLevelNode(decl);
// ... (287 more lines)

Domain

Subdomains

Classes

Dependencies

  • babel-plugin-react-compiler
  • core
  • eslint
  • estree
  • hermes-parser
  • parser
  • types
  • util

Frequently Asked Questions

What does RunReactCompiler.ts do?
RunReactCompiler.ts is a source file in the react codebase, written in typescript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in RunReactCompiler.ts?
RunReactCompiler.ts defines 5 function(s): checkTopLevelNode, getFlowSuppressions, mayContainReactCode, runReactCompiler, runReactCompilerImpl.
What does RunReactCompiler.ts depend on?
RunReactCompiler.ts imports 8 module(s): babel-plugin-react-compiler, core, eslint, estree, hermes-parser, parser, types, util.
What files import RunReactCompiler.ts?
RunReactCompiler.ts is imported by 1 file(s): ReactCompiler.ts.
Where is RunReactCompiler.ts in the architecture?
RunReactCompiler.ts is located at packages/eslint-plugin-react-hooks/src/shared/RunReactCompiler.ts (domain: BabelCompiler, subdomain: Validation, directory: packages/eslint-plugin-react-hooks/src/shared).

Analyze Your Own Codebase

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

Try Supermodel Free