Repository: facebook/react
File: compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts (TypeScript)

Code before:
      importSpecifierName: 'useRenderCounter',
    },
    gating: {
      source: 'react-compiler-runtime',
      importSpecifierName: 'shouldInstrument',
    },
    globalGating: '__DEV__',
  },
  enableEmitHookGuards: {
    source: 'react-compiler-runtime',
    importSpecifierName: '$dispatcherGuard',
  },
  inlineJsxTransform: {
    elementSymbol: 'react.transitional.element',
    globalDevVar: 'DEV',
  },
  lowerContextAccess: {
    source: 'react-compiler-runtime',
    importSpecifierName: 'useContext_withSelector',
  },
};

/**
 * For snap test fixtures and playground only.
 */
export function parseConfigPragma(pragma: string): EnvironmentConfig {
  const maybeConfig: any = {};
  // Get the defaults to programmatically check for boolean properties
  const defaultConfig = EnvironmentConfigSchema.parse({});

  for (const token of pragma.split(' ')) {
    if (!token.startsWith('@')) {
      continue;
    }
    const keyVal = token.slice(1);
    let [key, val = undefined] = keyVal.split(':');
    const isSet = val === undefined || val === 'true';

    if (isSet && key in testConfigValues) {
      maybeConfig[key] =
        testConfigValues[key as keyof PartialEnvironmentConfig];
      continue;
    }

    if (key === 'customMacros' && val) {
      const valSplit = val.split('.');
      if (valSplit.length > 0) {
        const props = [];
        for (const elt of valSplit.slice(1)) {
          if (elt === '*') {
            props.push({type: 'wildcard'});

Review comment (suggestion):
Before this just used environment defaults, now we're explicitly adding in dummy values just for tests/playground. Let's rename? `parseConfigPragmaForTests()` or similar

Code after:
      importSpecifierName: 'useRenderCounter',
    },
    gating: {
      source: 'react-compiler-runtime',
      importSpecifierName: 'shouldInstrument',
    },
    globalGating: '__DEV__',
  },
  enableEmitHookGuards: {
    source: 'react-compiler-runtime',
    importSpecifierName: '$dispatcherGuard',
  },
  inlineJsxTransform: {
    elementSymbol: 'react.transitional.element',
    globalDevVar: 'DEV',
  },
  lowerContextAccess: {
    source: 'react-compiler-runtime',
    importSpecifierName: 'useContext_withSelector',
  },
};

/**
 * For snap test fixtures and playground only.
 */
export function parseConfigPragmaForTests(pragma: string): EnvironmentConfig {
  const maybeConfig: any = {};
  // Get the defaults to programmatically check for boolean properties
  const defaultConfig = EnvironmentConfigSchema.parse({});

  for (const token of pragma.split(' ')) {
    if (!token.startsWith('@')) {
      continue;
    }
    const keyVal = token.slice(1);
    let [key, val = undefined] = keyVal.split(':');
    const isSet = val === undefined || val === 'true';

    if (isSet && key in testComplexConfigDefaults) {
      maybeConfig[key] =
        testComplexConfigDefaults[key as keyof PartialEnvironmentConfig];
      continue;
    }

    if (key === 'customMacros' && val) {
      const valSplit = val.split('.');
      if (valSplit.length > 0) {
        const props = [];
        for (const elt of valSplit.slice(1)) {
          if (elt === '*') {
            props.push({type: 'wildcard'});