{"version":3,"file":"react-refresh-ignored-route-exports.cjs","names":[],"sources":["../../../../../src/core/code-splitter/plugins/react-refresh-ignored-route-exports.ts"],"sourcesContent":["import * as template from '@babel/template'\nimport * as t from '@babel/types'\nimport { getUniqueProgramIdentifier } from '../../utils'\nimport type { ReferenceRouteCompilerPlugin } from '../plugins'\n\nconst buildReactRefreshIgnoredRouteExportsStatement = template.statement(\n  `\nif (import.meta.hot && typeof window !== 'undefined') {\n  const tsrReactRefresh = window.__TSR_REACT_REFRESH__ ??= (() => {\n    const ignoredExportsById = new Map()\n    const previousGetIgnoredExports = window.__getReactRefreshIgnoredExports\n\n    window.__getReactRefreshIgnoredExports = (ctx) => {\n      const ignoredExports = previousGetIgnoredExports?.(ctx) ?? []\n      const moduleIgnored = ignoredExportsById.get(ctx.id) ?? []\n      return [...ignoredExports, ...moduleIgnored]\n    }\n\n    return {\n      ignoredExportsById,\n    }\n  })()\n\n  tsrReactRefresh.ignoredExportsById.set(%%moduleId%%, ['Route'])\n}\n`,\n  { syntacticPlaceholders: true },\n)\n\n/**\n * A trivial component-shaped export that gives `@vitejs/plugin-react` a valid\n * Fast Refresh boundary. Without at least one non-ignored component export,\n * the module would be invalidated (full page reload) on every update even\n * though our custom route HMR handler already manages the update.\n */\nconst buildRefreshAnchorStatement = template.statement(\n  `export function %%anchorName%%() { return null }`,\n  { syntacticPlaceholders: true },\n)\n\nexport function createReactRefreshIgnoredRouteExportsPlugin(): ReferenceRouteCompilerPlugin {\n  return {\n    name: 'react-refresh-ignored-route-exports',\n    onAddHmr(ctx) {\n      const anchorName = getUniqueProgramIdentifier(\n        ctx.programPath,\n        'TSRFastRefreshAnchor',\n      )\n\n      ctx.programPath.pushContainer(\n        'body',\n        buildReactRefreshIgnoredRouteExportsStatement({\n          moduleId: t.stringLiteral(ctx.opts.id),\n        }),\n      )\n\n      ctx.programPath.pushContainer(\n        'body',\n        buildRefreshAnchorStatement({ anchorName }),\n      )\n\n      return { modified: true }\n    },\n  }\n}\n"],"mappings":";;;;;;;AAKA,IAAM,gDAAgD,gBAAS,UAC7D;;;;;;;;;;;;;;;;;;;GAoBA,EAAE,uBAAuB,MAAM,CAChC;;;;;;;AAQD,IAAM,8BAA8B,gBAAS,UAC3C,oDACA,EAAE,uBAAuB,MAAM,CAChC;AAED,SAAgB,8CAA4E;AAC1F,QAAO;EACL,MAAM;EACN,SAAS,KAAK;GACZ,MAAM,aAAa,cAAA,2BACjB,IAAI,aACJ,uBACD;AAED,OAAI,YAAY,cACd,QACA,8CAA8C,EAC5C,UAAU,aAAE,cAAc,IAAI,KAAK,GAAG,EACvC,CAAC,CACH;AAED,OAAI,YAAY,cACd,QACA,4BAA4B,EAAE,YAAY,CAAC,CAC5C;AAED,UAAO,EAAE,UAAU,MAAM;;EAE5B"}