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

Code before:
        reason: 'Expected compiled function to have an identifier',
        loc: null,
      });
      CompilerError.invariant(originalFn.parentPath.isVariableDeclarator(), {
        reason: 'Expected a variable declarator parent',
        loc: null,
      });
      const varDecl = originalFn.parentPath.parentPath;
      varDecl.insertAfter(
        t.variableDeclaration('const', [
          t.variableDeclarator(compiledFn.id, funcExpr),
        ]),
      );
      CompilerError.invariant(typeof varDecl.key === 'number', {
        reason:
          'Just Babel things: expected the VariableDeclaration containing the compiled function expression to have a number key',
        loc: null,
      });
      const insertedCompiledFnVarDecl = varDecl.getSibling(varDecl.key + 1);
      CompilerError.invariant(
        insertedCompiledFnVarDecl.isVariableDeclaration(),
        {
          reason: 'Expected inserted sibling to be a VariableDeclaration',
          loc: null,
        },
      );
      // safety: we synthesized it above, no need to check again
      const insertedFuncExpr = insertedCompiledFnVarDecl
        .get('declarations')[0]!
        .get('init')!;
      CompilerError.invariant(
        insertedFuncExpr.isArrowFunctionExpression() ||
          insertedFuncExpr.isFunctionExpression(),
        {
          reason: 'Expected inserted (arrow) function expression',
          description: `Got: ${insertedFuncExpr}`,
          loc: null,
        },
      );
      return insertedFuncExpr;
    }
    default: {
      assertExhaustive(
        originalFn,
        `Inserting unhandled function: ${originalFn}`,
      );
    }
  }
}

/*

Review comment (suggestion):
Nit: (please disregard if this is intentional to double check babel-things) I think we might be able to just use the return value of `insertAfter` instead of going through `getSibling` etc. 

Code after:
        reason: 'Expected compiled function to have an identifier',
        loc: compiledFn.loc,
      });
      CompilerError.invariant(
        originalFn.parentPath.isVariableDeclarator() &&
          originalFn.parentPath.parentPath.isVariableDeclaration(),
        {
          reason: 'Expected a variable declarator parent',
          loc: originalFn.node.loc ?? null,
        },
      );
      const varDecl = originalFn.parentPath.parentPath;
      varDecl.insertAfter(
        t.variableDeclaration('const', [
          t.variableDeclarator(compiledFn.id, funcExpr),
        ]),
      );
      const insertedFuncExpr = varDecl.get('declarations')[0]!.get('init')!;
      CompilerError.invariant(
        insertedFuncExpr.isArrowFunctionExpression() ||
          insertedFuncExpr.isFunctionExpression(),
        {
          reason: 'Expected inserted (arrow) function expression',
          description: `Got: ${insertedFuncExpr}`,
          loc: insertedFuncExpr.node?.loc ?? null,
        },
      );
      return insertedFuncExpr;
    }
    default: {
      assertExhaustive(
        originalFn,
        `Inserting unhandled function: ${originalFn}`,
      );
    }
  }
}

/*
 * This is a hack to work around what seems to be a Babel bug. Babel doesn't
 * consistently respect the `skip()` function to avoid revisiting a node within
 * a pass, so we use this set to track nodes that we have compiled.
 */
const ALREADY_COMPILED: WeakSet<object> | Set<object> = new (WeakSet ?? Set)();

const DEFAULT_ESLINT_SUPPRESSIONS = [
  'react-hooks/exhaustive-deps',
  'react-hooks/rules-of-hooks',
];

function isFilePartOfSources(