{"version":3,"file":"reactCompilerRuntime.mjs","names":["React","$empty","Symbol","for","ReactWithCompilerRuntime","__COMPILER_RUNTIME","c","size","Array","builtinC","useMemo","$","i","k"],"sources":["../src/reactCompilerRuntime.ts"],"sourcesContent":["'use no memo';\n\n/**\n * First-party ESM shim for the React Compiler runtime.\n *\n * The library runs the React Compiler at build time (target: '18'), which emits\n * `import { c } from \"react-compiler-runtime\"` in every compiled component. The\n * upstream `react-compiler-runtime` package is CommonJS-only; when a consumer\n * re-bundles our pre-compiled ESM, the named `c` import fails CJS→ESM interop\n * under some bundlers (e.g. rolldown-vite) and resolves to `undefined` at\n * runtime, so the helper call `c(n)` throws \"D is not a function\" from the first\n * compiled component to render.\n *\n * The tsdown build (see tsdown.config.ts) rewrites that bare specifier to a\n * relative import of this module, so the helper ships as a plain first-party\n * ESM export. It is emitted as a normal relative module in dist/ and keeps\n * `react` external. `c` is the only export the compiler references at target 18\n * (verified: 640/640 compiled files import only `{ c }`).\n *\n * The implementation mirrors upstream react-compiler-runtime@1.0.0: use React's\n * built-in compiler runtime when present (React 19+), else a useMemo-based cache.\n */\nimport * as React from 'react';\n\nconst $empty = Symbol.for('react.memo_cache_sentinel');\n\ntype ReactWithCompilerRuntime = typeof React & {\n  __COMPILER_RUNTIME?: { c?: (size: number) => Array<unknown> };\n};\n\nconst builtinC = (React as ReactWithCompilerRuntime).__COMPILER_RUNTIME?.c;\n\nexport const c: (size: number) => Array<unknown> =\n  typeof builtinC === 'function'\n    ? builtinC\n    : function c(size: number): Array<unknown> {\n        // Not a violation: compiled components invoke `c` at hook position —\n        // this mirrors upstream react-compiler-runtime's own useMemo cache.\n        // eslint-disable-next-line react-hooks/rules-of-hooks\n        return React.useMemo(() => {\n          const $: Array<unknown> = new Array(size);\n          for (let i = 0; i < size; i++) {\n            $[i] = $empty;\n          }\n          // Sentinel marker on the cache array itself; mirrors upstream runtime.\n          ($ as Array<unknown> & { [k: symbol]: unknown })[$empty] = true;\n          return $;\n        }, []);\n      };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAMC,SAASC,OAAOC,IAAI,4BAA4B;AAMtD,MAAMM,WAAYT,QAAmCK,oBAAoBC;AAEzE,MAAaA,IACX,OAAOG,aAAa,aAChBA,WACA,SAASH,EAAEC,MAA8B;AAIvC,QAAOP,QAAMU,cAAc;EACzB,MAAMC,IAAoB,IAAIH,MAAMD,KAAK;AACzC,OAAK,IAAIK,IAAI,GAAGA,IAAIL,MAAMK,IACxBD,GAAEC,KAAKX;AAGRU,IAAgDV,UAAU;AAC3D,SAAOU;IACN,EAAE,CAAC"}