Home / Function/ parseConfigPragmaEnvironmentForTest() — react Function Reference

parseConfigPragmaEnvironmentForTest() — react Function Reference

Architecture documentation for the parseConfigPragmaEnvironmentForTest() function in TestUtils.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  e5e371fb_3742_5a74_1c74_35d7ac870a67["parseConfigPragmaEnvironmentForTest()"]
  61433613_1614_4ece_2f7a_b0186e79adde["TestUtils.ts"]
  e5e371fb_3742_5a74_1c74_35d7ac870a67 -->|defined in| 61433613_1614_4ece_2f7a_b0186e79adde
  7750e61a_286d_376c_20d3_03596b3f28d3["parseConfigPragmaForTests()"]
  7750e61a_286d_376c_20d3_03596b3f28d3 -->|calls| e5e371fb_3742_5a74_1c74_35d7ac870a67
  0a308ef1_088b_bc2c_8901_ab8a0da206f6["splitPragma()"]
  e5e371fb_3742_5a74_1c74_35d7ac870a67 -->|calls| 0a308ef1_088b_bc2c_8901_ab8a0da206f6
  27d56ae1_023e_57f5_a306_f4be92e0daca["hasOwnProperty()"]
  e5e371fb_3742_5a74_1c74_35d7ac870a67 -->|calls| 27d56ae1_023e_57f5_a306_f4be92e0daca
  3a9cf239_47d9_36ec_7a64_96d52ded92ba["tryParseTestPragmaValue()"]
  e5e371fb_3742_5a74_1c74_35d7ac870a67 -->|calls| 3a9cf239_47d9_36ec_7a64_96d52ded92ba
  041ca752_10c1_3cda_1f5c_02f44a01310e["invariant()"]
  e5e371fb_3742_5a74_1c74_35d7ac870a67 -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e
  5228ee8c_dc7c_d859_3f41_614fd9c00374["unwrap()"]
  e5e371fb_3742_5a74_1c74_35d7ac870a67 -->|calls| 5228ee8c_dc7c_d859_3f41_614fd9c00374
  style e5e371fb_3742_5a74_1c74_35d7ac870a67 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/Utils/TestUtils.ts lines 115–161

function parseConfigPragmaEnvironmentForTest(
  pragma: string,
  defaultConfig: PartialEnvironmentConfig,
): EnvironmentConfig {
  // throw early if the defaults are invalid
  EnvironmentConfigSchema.parse(defaultConfig);

  const maybeConfig: Partial<Record<keyof EnvironmentConfig, unknown>> =
    defaultConfig;

  for (const {key, value: val} of splitPragma(pragma)) {
    if (!hasOwnProperty(EnvironmentConfigSchema.shape, key)) {
      continue;
    }
    const isSet = val == null || val === 'true';
    if (isSet && key in testComplexConfigDefaults) {
      maybeConfig[key] = testComplexConfigDefaults[key];
    } else if (isSet) {
      maybeConfig[key] = true;
    } else if (val === 'false') {
      maybeConfig[key] = false;
    } else if (val) {
      const parsedVal = tryParseTestPragmaValue(val).unwrap();
      if (key === 'customMacros' && typeof parsedVal === 'string') {
        maybeConfig[key] = [parsedVal.split('.')[0]];
        continue;
      }
      maybeConfig[key] = parsedVal;
    }
  }
  const config = EnvironmentConfigSchema.safeParse(maybeConfig);
  if (config.success) {
    /**
     * Unless explicitly enabled, do not insert HMR handling code
     * in test fixtures or playground to reduce visual noise.
     */
    if (config.data.enableResetCacheOnSourceFileChanges == null) {
      config.data.enableResetCacheOnSourceFileChanges = false;
    }
    return config.data;
  }
  CompilerError.invariant(false, {
    reason: 'Internal error, could not parse config from pragma string',
    description: `${fromZodError(config.error)}`,
    loc: GeneratedSource,
  });
}

Domain

Subdomains

Frequently Asked Questions

What does parseConfigPragmaEnvironmentForTest() do?
parseConfigPragmaEnvironmentForTest() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Utils/TestUtils.ts.
Where is parseConfigPragmaEnvironmentForTest() defined?
parseConfigPragmaEnvironmentForTest() is defined in compiler/packages/babel-plugin-react-compiler/src/Utils/TestUtils.ts at line 115.
What does parseConfigPragmaEnvironmentForTest() call?
parseConfigPragmaEnvironmentForTest() calls 5 function(s): hasOwnProperty, invariant, splitPragma, tryParseTestPragmaValue, unwrap.
What calls parseConfigPragmaEnvironmentForTest()?
parseConfigPragmaEnvironmentForTest() is called by 1 function(s): parseConfigPragmaForTests.

Analyze Your Own Codebase

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

Try Supermodel Free