{"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 { createHmrHotExpressionAst } from '../../hmr-hot-expression'\nimport { getUniqueProgramIdentifier } from '../../utils'\nimport type { ReferenceRouteCompilerPlugin } from '../plugins'\n\nconst buildReactRefreshIgnoredRouteExportsStatements = template.statements(\n  `\nconst hot = %%hotExpression%%\nif (hot && typeof window !== 'undefined') {\n  ;(hot.data ??= {})\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(opts?: {\n  hotExpression?: string\n}): 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        buildReactRefreshIgnoredRouteExportsStatements({\n          hotExpression: createHmrHotExpressionAst(\n            opts?.hotExpression ?? ctx.opts.hmrHotExpression,\n          ),\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":";;;;;;;;AAMA,IAAM,iDAAiD,gBAAS,WAC9D;;;;;;;;;;;;;;;;;;;;;GAsBA,EAAE,uBAAuB,MAAM,CAChC;;;;;;;AAQD,IAAM,8BAA8B,gBAAS,UAC3C,oDACA,EAAE,uBAAuB,MAAM,CAChC;AAED,SAAgB,4CAA4C,MAE3B;AAC/B,QAAO;EACL,MAAM;EACN,SAAS,KAAK;GACZ,MAAM,aAAa,cAAA,2BACjB,IAAI,aACJ,uBACD;AAED,OAAI,YAAY,cACd,QACA,+CAA+C;IAC7C,eAAe,2BAAA,0BACb,MAAM,iBAAiB,IAAI,KAAK,iBACjC;IACD,UAAU,aAAE,cAAc,IAAI,KAAK,GAAG;IACvC,CAAC,CACH;AAED,OAAI,YAAY,cACd,QACA,4BAA4B,EAAE,YAAY,CAAC,CAC5C;AAED,UAAO,EAAE,UAAU,MAAM;;EAE5B"}