Home / Function/ parseOptions() — react Function Reference

parseOptions() — react Function Reference

Architecture documentation for the parseOptions() function in compilation.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  736dd773_fb1f_3bb4_d30a_8caa66060372["parseOptions()"]
  9ba26589_c539_da05_fcd2_2ca7851645ba["compilation.ts"]
  736dd773_fb1f_3bb4_d30a_8caa66060372 -->|defined in| 9ba26589_c539_da05_fcd2_2ca7851645ba
  01f84d19_40f4_ddcb_bf42_a422f8d05d88["compile()"]
  01f84d19_40f4_ddcb_bf42_a422f8d05d88 -->|calls| 736dd773_fb1f_3bb4_d30a_8caa66060372
  style 736dd773_fb1f_3bb4_d30a_8caa66060372 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/apps/playground/lib/compilation.ts lines 129–181

function parseOptions(
  source: string,
  mode: 'compiler' | 'linter',
  configOverrides: string,
): PluginOptions {
  // Extract the first line to quickly check for custom test directives
  const pragma = source.substring(0, source.indexOf('\n'));

  const parsedPragmaOptions = parseConfigPragmaForTests(pragma, {
    compilationMode: 'infer',
    environment:
      mode === 'linter'
        ? {
            // enabled in compiler
            validateRefAccessDuringRender: false,
            // enabled in linter
            validateNoSetStateInRender: true,
            validateNoSetStateInEffects: true,
            validateNoJSXInTryStatements: true,
            validateNoImpureFunctionsInRender: true,
            validateStaticComponents: true,
            validateNoFreezingKnownMutableFunctions: true,
            validateNoVoidUseMemo: true,
          }
        : {
            /* use defaults for compiler mode */
          },
  });

  // Parse config overrides from config editor
  let configOverrideOptions: any = {};
  const configMatch = configOverrides.match(/^\s*import.*?\n\n\((.*)\)/s);
  if (configOverrides.trim()) {
    if (configMatch && configMatch[1]) {
      const configString = configMatch[1].replace(/satisfies.*$/, '').trim();
      configOverrideOptions = new Function(`return (${configString})`)();
    } else {
      throw new Error('Invalid override format');
    }
  }

  const opts: PluginOptions = parsePluginOptions({
    ...parsedPragmaOptions,
    ...configOverrideOptions,
    environment: {
      ...parsedPragmaOptions.environment,
      ...configOverrideOptions.environment,
      customHooks: new Map([...COMMON_HOOKS]),
    },
  });

  return opts;
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does parseOptions() do?
parseOptions() is a function in the react codebase, defined in compiler/apps/playground/lib/compilation.ts.
Where is parseOptions() defined?
parseOptions() is defined in compiler/apps/playground/lib/compilation.ts at line 129.
What calls parseOptions()?
parseOptions() is called by 1 function(s): compile.

Analyze Your Own Codebase

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

Try Supermodel Free