{"version":3,"file":"vite-adapter.cjs","names":[],"sources":["../../../../src/core/hmr/vite-adapter.ts"],"sourcesContent":["import * as template from '@babel/template'\nimport { getHandleRouteUpdateCode } from './handle-route-update'\nimport type * as t from '@babel/types'\n\n/**\n * Emits HMR accept code for Vite / native ESM HMR: `import.meta.hot.accept`\n * with a callback that receives the freshly re-imported module.\n *\n * `targetFramework` is currently unused — Vite's framework-specific fast-refresh\n * plugins handle component body patching via their own accept boundaries — but\n * we take it for API symmetry with `createWebpackHmrStatement`.\n */\nexport function createViteHmrStatement(\n  stableRouteOptionKeys: Array<string>,\n  opts: {\n    routeId?: string\n  } = {},\n): Array<t.Statement> {\n  const handleRouteUpdateCode = getHandleRouteUpdateCode(stableRouteOptionKeys)\n  // The replacement Route object can be uninitialized; keep a generated id as\n  // fallback for the existing router route we need to patch.\n  const routeIdFallback =\n    typeof opts.routeId === 'string' ? JSON.stringify(opts.routeId) : 'Route.id'\n\n  return [\n    template.statement(\n      `\nif (import.meta.hot) {\n  const hot = import.meta.hot\n  const hotData = hot.data ??= {}\n  hot.accept((newModule) => {\n    if (Route && newModule && newModule.Route) {\n      const routeId = hotData['tsr-route-id'] ?? ${routeIdFallback}\n      if (routeId) {\n        hotData['tsr-route-id'] = routeId\n      }\n      (${handleRouteUpdateCode})(routeId, newModule.Route)\n    }\n    })\n}\n`,\n      {\n        syntacticPlaceholders: true,\n      },\n    )(),\n  ]\n}\n"],"mappings":";;;;;;;;;;;;;AAYA,SAAgB,uBACd,uBACA,OAEI,EAAE,EACc;CACpB,MAAM,wBAAwB,4BAAA,yBAAyB,sBAAsB;CAG7E,MAAM,kBACJ,OAAO,KAAK,YAAY,WAAW,KAAK,UAAU,KAAK,QAAQ,GAAG;AAEpE,QAAO,CACL,gBAAS,UACP;;;;;;mDAM6C,gBAAgB;;;;SAI1D,sBAAsB;;;;GAKzB,EACE,uBAAuB,MACxB,CACF,EAAE,CACJ"}