{"version":3,"sources":["../../../src/build/get-babel-loader-config.ts"],"sourcesContent":["import type { EnvironmentConfig } from 'babel-plugin-react-compiler'\nimport path from 'path'\nimport type { JSONValue, ReactCompilerOptions } from '../server/config-shared'\nimport type { NextBabelLoaderOptions } from './babel/loader/types'\n\nfunction getReactCompiler() {\n  try {\n    return require.resolve('babel-plugin-react-compiler')\n  } catch {\n    throw new Error(\n      'Failed to load the `babel-plugin-react-compiler`. It is required to use the React Compiler. Please install it.'\n    )\n  }\n}\n\nconst getReactCompilerPlugins = (\n  maybeOptions: boolean | ReactCompilerOptions | undefined,\n  isServer: boolean,\n  isDev: boolean,\n  cwd: string\n): undefined | JSONValue[] => {\n  if (!maybeOptions || isServer) {\n    return undefined\n  }\n\n  // Set the React Compiler target based on the installed React version.\n  // Handle only the supported versions.\n  // https://react.dev/reference/react-compiler/target\n  let target: '18' | undefined\n  try {\n    const reactPkgPath = require.resolve('react/package.json', {\n      paths: [cwd],\n    })\n    const majorVersion: string = require(reactPkgPath).version.split('.')[0]\n    if (majorVersion === '18') {\n      target = majorVersion\n    }\n  } catch {\n    // react/package.json not resolvable — skip target detection\n  }\n\n  const environment: Pick<EnvironmentConfig, 'enableNameAnonymousFunctions'> = {\n    enableNameAnonymousFunctions: isDev,\n  }\n  const options: ReactCompilerOptions =\n    typeof maybeOptions === 'boolean' ? {} : maybeOptions\n  const compilerOptions: JSONValue = {\n    ...options,\n    ...(target ? { target } : {}),\n    environment,\n  }\n  return [[getReactCompiler(), compilerOptions]]\n}\n\nconst getBabelLoader = (\n  useSWCLoader: boolean | undefined,\n  babelConfigFile: string | undefined,\n  isServer: boolean,\n  distDir: string,\n  pagesDir: string | undefined,\n  cwd: string,\n  srcDir: string,\n  dev: boolean,\n  isClient: boolean,\n  reactCompilerOptions: boolean | ReactCompilerOptions | undefined,\n  reactCompilerExclude: ((excludePath: string) => boolean) | undefined\n) => {\n  if (!useSWCLoader) {\n    // Make sure these options are kept in sync with\n    // `packages/next/src/build/get-babel-loader-config.ts`\n    const options: NextBabelLoaderOptions = {\n      transformMode: 'default',\n      configFile: babelConfigFile,\n      isServer,\n      distDir,\n      pagesDir,\n      cwd,\n      srcDir: path.dirname(srcDir),\n      development: dev,\n      hasReactRefresh: dev && isClient,\n      hasJsxRuntime: true,\n      reactCompilerPlugins: getReactCompilerPlugins(\n        reactCompilerOptions,\n        isServer,\n        dev,\n        cwd\n      ),\n      reactCompilerExclude,\n    }\n    return {\n      loader: require.resolve('./babel/loader/index'),\n      options,\n    }\n  }\n\n  return undefined\n}\n\n/**\n * Get a separate babel loader for the react compiler, only used if Babel is not\n * configured through e.g. .babelrc. If user have babel config, this should be configured in the babel loader itself.\n * Note from react compiler:\n * > For best results, compiler must run as the first plugin in your Babel pipeline so it receives input as close to the original source as possible.\n */\nconst getReactCompilerLoader = (\n  reactCompilerOptions: boolean | ReactCompilerOptions | undefined,\n  cwd: string,\n  isServer: boolean,\n  reactCompilerExclude: ((excludePath: string) => boolean) | undefined,\n  isDev: boolean\n) => {\n  const reactCompilerPlugins = getReactCompilerPlugins(\n    reactCompilerOptions,\n    isServer,\n    isDev,\n    cwd\n  )\n  if (!reactCompilerPlugins) {\n    return undefined\n  }\n\n  const babelLoaderOptions: NextBabelLoaderOptions = {\n    transformMode: 'standalone',\n    cwd,\n    reactCompilerPlugins,\n    isServer,\n  }\n  if (reactCompilerExclude) {\n    babelLoaderOptions.reactCompilerExclude = reactCompilerExclude\n  }\n\n  return {\n    loader: require.resolve('./babel/loader/index'),\n    options: babelLoaderOptions,\n  }\n}\n\nexport { getBabelLoader, getReactCompilerLoader }\n"],"names":["path","getReactCompiler","require","resolve","Error","getReactCompilerPlugins","maybeOptions","isServer","isDev","cwd","undefined","target","reactPkgPath","paths","majorVersion","version","split","environment","enableNameAnonymousFunctions","options","compilerOptions","getBabelLoader","useSWCLoader","babelConfigFile","distDir","pagesDir","srcDir","dev","isClient","reactCompilerOptions","reactCompilerExclude","transformMode","configFile","dirname","development","hasReactRefresh","hasJsxRuntime","reactCompilerPlugins","loader","getReactCompilerLoader","babelLoaderOptions"],"mappings":"AACA,OAAOA,UAAU,OAAM;AAIvB,SAASC;IACP,IAAI;QACF,OAAOC,QAAQC,OAAO,CAAC;IACzB,EAAE,OAAM;QACN,MAAM,qBAEL,CAFK,IAAIC,MACR,mHADI,qBAAA;mBAAA;wBAAA;0BAAA;QAEN;IACF;AACF;AAEA,MAAMC,0BAA0B,CAC9BC,cACAC,UACAC,OACAC;IAEA,IAAI,CAACH,gBAAgBC,UAAU;QAC7B,OAAOG;IACT;IAEA,sEAAsE;IACtE,sCAAsC;IACtC,oDAAoD;IACpD,IAAIC;IACJ,IAAI;QACF,MAAMC,eAAeV,QAAQC,OAAO,CAAC,sBAAsB;YACzDU,OAAO;gBAACJ;aAAI;QACd;QACA,MAAMK,eAAuBZ,QAAQU,cAAcG,OAAO,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;QACxE,IAAIF,iBAAiB,MAAM;YACzBH,SAASG;QACX;IACF,EAAE,OAAM;IACN,4DAA4D;IAC9D;IAEA,MAAMG,cAAuE;QAC3EC,8BAA8BV;IAChC;IACA,MAAMW,UACJ,OAAOb,iBAAiB,YAAY,CAAC,IAAIA;IAC3C,MAAMc,kBAA6B;QACjC,GAAGD,OAAO;QACV,GAAIR,SAAS;YAAEA;QAAO,IAAI,CAAC,CAAC;QAC5BM;IACF;IACA,OAAO;QAAC;YAAChB;YAAoBmB;SAAgB;KAAC;AAChD;AAEA,MAAMC,iBAAiB,CACrBC,cACAC,iBACAhB,UACAiB,SACAC,UACAhB,KACAiB,QACAC,KACAC,UACAC,sBACAC;IAEA,IAAI,CAACR,cAAc;QACjB,gDAAgD;QAChD,uDAAuD;QACvD,MAAMH,UAAkC;YACtCY,eAAe;YACfC,YAAYT;YACZhB;YACAiB;YACAC;YACAhB;YACAiB,QAAQ1B,KAAKiC,OAAO,CAACP;YACrBQ,aAAaP;YACbQ,iBAAiBR,OAAOC;YACxBQ,eAAe;YACfC,sBAAsB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