Home / File/ Imports.ts — react Source File

Imports.ts — react Source File

Architecture documentation for Imports.ts, a typescript file in the react codebase. 24 imports, 2 dependents.

File typescript BabelCompiler Entrypoint 24 imports 2 dependents 4 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  2a7e50cd_6171_085d_277c_6ced6ddd7148["Imports.ts"]
  e96f281e_f381_272d_2359_3e6a091c9a1d["CompilerError.ts"]
  2a7e50cd_6171_085d_277c_6ced6ddd7148 --> e96f281e_f381_272d_2359_3e6a091c9a1d
  e51fd0d2_bb38_cc97_7763_efe37f300a47["CompilerError"]
  2a7e50cd_6171_085d_277c_6ced6ddd7148 --> e51fd0d2_bb38_cc97_7763_efe37f300a47
  a2b91621_58d3_1d04_4663_00cd808f1034["ErrorCategory"]
  2a7e50cd_6171_085d_277c_6ced6ddd7148 --> a2b91621_58d3_1d04_4663_00cd808f1034
  0423f759_97e0_9101_4634_ed555abc5ca9["index.ts"]
  2a7e50cd_6171_085d_277c_6ced6ddd7148 --> 0423f759_97e0_9101_4634_ed555abc5ca9
  eb9d33f9_42c1_205c_93e6_8e1365a31839["utils.ts"]
  2a7e50cd_6171_085d_277c_6ced6ddd7148 --> eb9d33f9_42c1_205c_93e6_8e1365a31839
  4663af75_e270_25e3_3415_1230be609d66["getOrInsertWith"]
  2a7e50cd_6171_085d_277c_6ced6ddd7148 --> 4663af75_e270_25e3_3415_1230be609d66
  1b971013_8a90_0d8d_1fcc_f31581cd66aa["Environment.ts"]
  2a7e50cd_6171_085d_277c_6ced6ddd7148 --> 1b971013_8a90_0d8d_1fcc_f31581cd66aa
  9017c821_3b98_1fe2_6116_790d721b5b40["ExternalFunction"]
  2a7e50cd_6171_085d_277c_6ced6ddd7148 --> 9017c821_3b98_1fe2_6116_790d721b5b40
  c32c4801_8f1e_6ab5_ff15_ac8ec7df6945["isHookName"]
  2a7e50cd_6171_085d_277c_6ced6ddd7148 --> c32c4801_8f1e_6ab5_ff15_ac8ec7df6945
  494e3425_0b47_293a_1ea4_d4670b0fc0e7["Result.ts"]
  2a7e50cd_6171_085d_277c_6ced6ddd7148 --> 494e3425_0b47_293a_1ea4_d4670b0fc0e7
  9217845a_d29d_c624_b607_e3b35cf604bc["Err"]
  2a7e50cd_6171_085d_277c_6ced6ddd7148 --> 9217845a_d29d_c624_b607_e3b35cf604bc
  9f0e6a52_ff9e_00f3_1760_5fddfd89b234["Ok"]
  2a7e50cd_6171_085d_277c_6ced6ddd7148 --> 9f0e6a52_ff9e_00f3_1760_5fddfd89b234
  7aace723_0ee1_cff5_b263_aec8e06dd79e["Result"]
  2a7e50cd_6171_085d_277c_6ced6ddd7148 --> 7aace723_0ee1_cff5_b263_aec8e06dd79e
  4828f3cc_e6ac_9239_d7f7_c05f7f60419c["Options.ts"]
  2a7e50cd_6171_085d_277c_6ced6ddd7148 --> 4828f3cc_e6ac_9239_d7f7_c05f7f60419c
  style 2a7e50cd_6171_085d_277c_6ced6ddd7148 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.
 */

import {NodePath} from '@babel/core';
import * as t from '@babel/types';
import {Scope as BabelScope} from '@babel/traverse';

import {CompilerError, ErrorCategory} from '../CompilerError';
import {
  EnvironmentConfig,
  GeneratedSource,
  NonLocalImportSpecifier,
} from '../HIR';
import {getOrInsertWith} from '../Utils/utils';
import {ExternalFunction, isHookName} from '../HIR/Environment';
import {Err, Ok, Result} from '../Utils/Result';
import {LoggerEvent, ParsedPluginOptions} from './Options';
import {BabelFn, getReactCompilerRuntimeModule} from './Program';
import {SuppressionRange} from './Suppression';

export function validateRestrictedImports(
  path: NodePath<t.Program>,
  {validateBlocklistedImports}: EnvironmentConfig,
): CompilerError | null {
  if (
    validateBlocklistedImports == null ||
    validateBlocklistedImports.length === 0
  ) {
    return null;
  }
  const error = new CompilerError();
  const restrictedImports = new Set(validateBlocklistedImports);
  path.traverse({
    ImportDeclaration(importDeclPath) {
      if (restrictedImports.has(importDeclPath.node.source.value)) {
        error.push({
          category: ErrorCategory.Todo,
          reason: 'Bailing out due to blocklisted import',
          description: `Import from module ${importDeclPath.node.source.value}`,
          loc: importDeclPath.node.loc ?? null,
        });
      }
    },
  });
  if (error.hasAnyErrors()) {
    return error;
  } else {
    return null;
  }
}

type ProgramContextOptions = {
  program: NodePath<t.Program>;
  suppressions: Array<SuppressionRange>;
  opts: ParsedPluginOptions;
  filename: string | null;
// ... (277 more lines)

Domain

Subdomains

Classes

Frequently Asked Questions

What does Imports.ts do?
Imports.ts is a source file in the react codebase, written in typescript. It belongs to the BabelCompiler domain, Entrypoint subdomain.
What functions are defined in Imports.ts?
Imports.ts defines 4 function(s): addImportsToProgram, getExistingImports, isNonNamespacedImport, validateRestrictedImports.
What does Imports.ts depend on?
Imports.ts imports 24 module(s): BabelFn, CompilerError, CompilerError.ts, Environment.ts, Err, ErrorCategory, ExternalFunction, LoggerEvent, and 16 more.
What files import Imports.ts?
Imports.ts is imported by 2 file(s): Gating.ts, Program.ts.
Where is Imports.ts in the architecture?
Imports.ts is located at compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Imports.ts (domain: BabelCompiler, subdomain: Entrypoint, directory: compiler/packages/babel-plugin-react-compiler/src/Entrypoint).

Analyze Your Own Codebase

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

Try Supermodel Free