Home / Function/ parsePluginOptions() — react Function Reference

parsePluginOptions() — react Function Reference

Architecture documentation for the parsePluginOptions() function in Options.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  24cdb07f_f37c_ae1f_e990_0390441e2808["parsePluginOptions()"]
  4828f3cc_e6ac_9239_d7f7_c05f7f60419c["Options.ts"]
  24cdb07f_f37c_ae1f_e990_0390441e2808 -->|defined in| 4828f3cc_e6ac_9239_d7f7_c05f7f60419c
  ac13f5c1_be17_dd7a_6bd3_66d91c46aadf["create()"]
  24cdb07f_f37c_ae1f_e990_0390441e2808 -->|calls| ac13f5c1_be17_dd7a_6bd3_66d91c46aadf
  a0135f69_c8e1_b5c5_ad8b_6bb43eb13eb4["isCompilerFlag()"]
  24cdb07f_f37c_ae1f_e990_0390441e2808 -->|calls| a0135f69_c8e1_b5c5_ad8b_6bb43eb13eb4
  b0ce8325_6d38_9f7e_a2d3_ca5cccc78d99["parseEnvironmentConfig()"]
  24cdb07f_f37c_ae1f_e990_0390441e2808 -->|calls| b0ce8325_6d38_9f7e_a2d3_ca5cccc78d99
  f4dabc03_d648_e2d6_19ef_83872ae711d3["throwInvalidConfig()"]
  24cdb07f_f37c_ae1f_e990_0390441e2808 -->|calls| f4dabc03_d648_e2d6_19ef_83872ae711d3
  c3310103_d462_d9f3_3830_423274c8a1af["parseTargetConfig()"]
  24cdb07f_f37c_ae1f_e990_0390441e2808 -->|calls| c3310103_d462_d9f3_3830_423274c8a1af
  3d8c9cf4_b77b_a09b_46bb_a39cfadd4173["tryParseExternalFunction()"]
  24cdb07f_f37c_ae1f_e990_0390441e2808 -->|calls| 3d8c9cf4_b77b_a09b_46bb_a39cfadd4173
  0ce970b2_5d95_e70b_84a7_d8306d937c82["toString()"]
  24cdb07f_f37c_ae1f_e990_0390441e2808 -->|calls| 0ce970b2_5d95_e70b_84a7_d8306d937c82
  style 24cdb07f_f37c_ae1f_e990_0390441e2808 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Options.ts lines 333–412

export function parsePluginOptions(obj: unknown): ParsedPluginOptions {
  if (obj == null || typeof obj !== 'object') {
    return defaultOptions;
  }
  const parsedOptions = Object.create(null);
  for (let [key, value] of Object.entries(obj)) {
    if (typeof value === 'string') {
      // normalize string configs to be case insensitive
      value = value.toLowerCase();
    }
    if (isCompilerFlag(key)) {
      switch (key) {
        case 'environment': {
          const environmentResult = parseEnvironmentConfig(value);
          if (environmentResult.isErr()) {
            CompilerError.throwInvalidConfig({
              reason:
                'Error in validating environment config. This is an advanced setting and not meant to be used directly',
              description: environmentResult.unwrapErr().toString(),
              suggestions: null,
              loc: null,
            });
          }
          parsedOptions[key] = environmentResult.unwrap();
          break;
        }
        case 'target': {
          parsedOptions[key] = parseTargetConfig(value);
          break;
        }
        case 'gating': {
          if (value == null) {
            parsedOptions[key] = null;
          } else {
            parsedOptions[key] = tryParseExternalFunction(value);
          }
          break;
        }
        case 'dynamicGating': {
          if (value == null) {
            parsedOptions[key] = null;
          } else {
            const result = DynamicGatingOptionsSchema.safeParse(value);
            if (result.success) {
              parsedOptions[key] = result.data;
            } else {
              CompilerError.throwInvalidConfig({
                reason:
                  'Could not parse dynamic gating. Update React Compiler config to fix the error',
                description: `${fromZodError(result.error)}`,
                loc: null,
                suggestions: null,
              });
            }
          }
          break;
        }
        case 'customOptOutDirectives': {
          const result = CustomOptOutDirectiveSchema.safeParse(value);
          if (result.success) {
            parsedOptions[key] = result.data;
          } else {
            CompilerError.throwInvalidConfig({
              reason:
                'Could not parse custom opt out directives. Update React Compiler config to fix the error',
              description: `${fromZodError(result.error)}`,
              loc: null,
              suggestions: null,
            });
          }
          break;
        }
        default: {
          parsedOptions[key] = value;
        }
      }
    }
  }
  return {...defaultOptions, ...parsedOptions};
}

Domain

Subdomains

Frequently Asked Questions

What does parsePluginOptions() do?
parsePluginOptions() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Options.ts.
Where is parsePluginOptions() defined?
parsePluginOptions() is defined in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Options.ts at line 333.
What does parsePluginOptions() call?
parsePluginOptions() calls 7 function(s): create, isCompilerFlag, parseEnvironmentConfig, parseTargetConfig, throwInvalidConfig, toString, tryParseExternalFunction.

Analyze Your Own Codebase

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

Try Supermodel Free