@wular/pnext 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (337) hide show
  1. package/bin/pnext +9 -2
  2. package/dist/server/_chunks/aliases-pycbtjt1.js +46 -0
  3. package/dist/server/_chunks/analyze-4d9e00g9.js +449 -0
  4. package/dist/server/_chunks/boot-bhemypxz.js +38 -0
  5. package/dist/server/_chunks/build-c991dv65.js +86 -0
  6. package/dist/server/_chunks/build-kh5e3x48.js +3341 -0
  7. package/dist/server/_chunks/build-tier-0a96kmx3.js +2456 -0
  8. package/dist/server/_chunks/compile-040r79gj.js +22 -0
  9. package/dist/server/_chunks/config-0tvz03a6.js +24 -0
  10. package/dist/server/_chunks/config-27rj7830.js +36 -0
  11. package/dist/server/_chunks/create-9rvwshsp.js +135 -0
  12. package/dist/server/_chunks/dev-ex9exynt.js +220 -0
  13. package/dist/server/_chunks/esbuild-yyktfrtt.js +15 -0
  14. package/dist/server/_chunks/generate-myw9hef7.js +22 -0
  15. package/dist/server/_chunks/index-0r5eqfc7.js +279 -0
  16. package/dist/server/_chunks/index-0yjv5v47.js +105 -0
  17. package/dist/server/_chunks/index-11xpbfej.js +17 -0
  18. package/dist/server/_chunks/index-141vcwk6.js +109 -0
  19. package/dist/server/_chunks/index-1pzm1hdy.js +4130 -0
  20. package/dist/server/_chunks/index-29pq0kax.js +590 -0
  21. package/dist/server/_chunks/index-2vz0wzdn.js +59 -0
  22. package/dist/server/_chunks/index-2wfv4kvx.js +182 -0
  23. package/dist/server/_chunks/index-38xpdxwd.js +194 -0
  24. package/dist/server/_chunks/index-3e075kny.js +128 -0
  25. package/dist/server/_chunks/index-3ycf5ckv.js +472 -0
  26. package/dist/server/_chunks/index-4399bvd2.js +18 -0
  27. package/dist/server/_chunks/index-4da76t62.js +297 -0
  28. package/dist/server/_chunks/index-4t92hdxd.js +172 -0
  29. package/dist/server/_chunks/index-4zzebszd.js +10 -0
  30. package/dist/server/_chunks/index-52k54ykj.js +95 -0
  31. package/dist/server/_chunks/index-5hr4062s.js +70 -0
  32. package/dist/server/_chunks/index-68m3mwbd.js +84 -0
  33. package/dist/server/_chunks/index-6b009mt0.js +56 -0
  34. package/dist/server/_chunks/index-6gex3pfa.js +15 -0
  35. package/dist/server/_chunks/index-6kp9r0d9.js +11 -0
  36. package/dist/server/_chunks/index-6q7zvrap.js +134 -0
  37. package/dist/server/_chunks/index-71885zaq.js +284 -0
  38. package/dist/server/_chunks/index-73z4esab.js +38 -0
  39. package/dist/server/_chunks/index-79ngvam8.js +60 -0
  40. package/dist/server/_chunks/index-7wc9n8be.js +25 -0
  41. package/dist/server/_chunks/index-8ct7rqy3.js +198 -0
  42. package/dist/server/_chunks/index-8kcxdfya.js +206 -0
  43. package/dist/server/_chunks/index-9ch50vtq.js +18 -0
  44. package/dist/server/_chunks/index-9f49w76j.js +213 -0
  45. package/dist/server/_chunks/index-9hz3s0m8.js +851 -0
  46. package/dist/server/_chunks/index-akkrvjn6.js +535 -0
  47. package/dist/server/_chunks/index-b6wtkdp4.js +24 -0
  48. package/dist/server/_chunks/index-b7j671dj.js +207 -0
  49. package/dist/server/_chunks/index-bcws5eh2.js +35 -0
  50. package/dist/server/_chunks/index-bzd2ef7t.js +10 -0
  51. package/dist/server/_chunks/index-cjgqs13g.js +65 -0
  52. package/dist/server/_chunks/index-ckkdpht5.js +41 -0
  53. package/dist/server/_chunks/index-cn86z041.js +296 -0
  54. package/dist/server/_chunks/index-cvr4z22m.js +92 -0
  55. package/dist/server/_chunks/index-cyfednwb.js +87 -0
  56. package/dist/server/_chunks/index-d158y67j.js +152 -0
  57. package/dist/server/_chunks/index-d1jsmhhk.js +955 -0
  58. package/dist/server/_chunks/index-dg0f05zs.js +199 -0
  59. package/dist/server/_chunks/index-dgr390q7.js +9438 -0
  60. package/dist/server/_chunks/index-drwv61cc.js +185 -0
  61. package/dist/server/_chunks/index-e3a6yx84.js +18 -0
  62. package/dist/server/_chunks/index-e88tyv35.js +45 -0
  63. package/dist/server/_chunks/index-en7n9f7m.js +22 -0
  64. package/dist/server/_chunks/index-entm8bmz.js +28 -0
  65. package/dist/server/_chunks/index-evhd413j.js +57 -0
  66. package/dist/server/_chunks/index-ezgj0tr1.js +88 -0
  67. package/dist/server/_chunks/index-fjv96re1.js +5295 -0
  68. package/dist/server/_chunks/index-fn1chkkd.js +214 -0
  69. package/dist/server/_chunks/index-fp8r0sqs.js +64 -0
  70. package/dist/server/_chunks/index-gcmj16xy.js +92 -0
  71. package/dist/server/_chunks/index-gkndxkxf.js +736 -0
  72. package/dist/server/_chunks/index-grta8ap3.js +238 -0
  73. package/dist/server/_chunks/index-h2a70tg4.js +7 -0
  74. package/dist/server/_chunks/index-h4xy648y.js +51 -0
  75. package/dist/server/_chunks/index-hdbwtdv2.js +352 -0
  76. package/dist/server/_chunks/index-he6n2bvp.js +1270 -0
  77. package/dist/server/_chunks/index-j0m1jxqa.js +1253 -0
  78. package/dist/server/_chunks/index-j2zrcp1k.js +66 -0
  79. package/dist/server/_chunks/index-j681c48a.js +2530 -0
  80. package/dist/server/_chunks/index-jbj7ehef.js +50 -0
  81. package/dist/server/_chunks/index-jcsjq3d1.js +20 -0
  82. package/dist/server/_chunks/index-jks0x0a1.js +14 -0
  83. package/dist/server/_chunks/index-jn9rbhrx.js +1599 -0
  84. package/dist/server/_chunks/index-jt8e1pje.js +12 -0
  85. package/dist/server/_chunks/index-kdhxpwyq.js +483 -0
  86. package/dist/server/_chunks/index-knp0s912.js +7 -0
  87. package/dist/server/_chunks/index-kqyy1d4f.js +50 -0
  88. package/dist/server/_chunks/index-kresp2n8.js +445 -0
  89. package/dist/server/_chunks/index-m63czgq5.js +590 -0
  90. package/dist/server/_chunks/index-ms9v9tnx.js +31 -0
  91. package/dist/server/_chunks/index-n4hxpng2.js +11 -0
  92. package/dist/server/_chunks/index-n629dy38.js +1071 -0
  93. package/dist/server/_chunks/index-nf3df4jy.js +266 -0
  94. package/dist/server/_chunks/index-nqh3xhdc.js +57 -0
  95. package/dist/server/_chunks/index-pym1cezq.js +39 -0
  96. package/dist/server/_chunks/index-q3r9z8mq.js +213 -0
  97. package/dist/server/_chunks/index-q738kkhj.js +100 -0
  98. package/dist/server/_chunks/index-qcrvt6er.js +112 -0
  99. package/dist/server/_chunks/index-qjj6gddn.js +54 -0
  100. package/dist/server/_chunks/index-qpwsgt3a.js +158 -0
  101. package/dist/server/_chunks/index-r97ptz1q.js +97 -0
  102. package/dist/server/_chunks/index-ras0sdab.js +26 -0
  103. package/dist/server/_chunks/index-rcs322t1.js +19 -0
  104. package/dist/server/_chunks/index-rgj5mx84.js +101 -0
  105. package/dist/server/_chunks/index-rjegyfx4.js +1435 -0
  106. package/dist/server/_chunks/index-rt9qq1va.js +4 -0
  107. package/dist/server/_chunks/index-rthrsed5.js +356 -0
  108. package/dist/server/_chunks/index-sq3kvz3g.js +200 -0
  109. package/dist/server/_chunks/index-stbk3jhn.js +31 -0
  110. package/dist/server/_chunks/index-tf4j19ge.js +130 -0
  111. package/dist/server/_chunks/index-tgcakdxc.js +125 -0
  112. package/dist/server/_chunks/index-tgsfjmep.js +74 -0
  113. package/dist/server/_chunks/index-tq1f96v7.js +51 -0
  114. package/dist/server/_chunks/index-tq3b39a5.js +107 -0
  115. package/dist/server/_chunks/index-typcbcsv.js +819 -0
  116. package/dist/server/_chunks/index-v1ags1na.js +132 -0
  117. package/dist/server/_chunks/index-vmr35jjw.js +170 -0
  118. package/dist/server/_chunks/index-vvq7rqtn.js +329 -0
  119. package/dist/server/_chunks/index-vz0km5qk.js +33 -0
  120. package/dist/server/_chunks/index-w6h8m6vp.js +138 -0
  121. package/dist/server/_chunks/index-web361b8.js +138 -0
  122. package/dist/server/_chunks/index-wm36rj4v.js +311 -0
  123. package/dist/server/_chunks/index-x0y005nh.js +283 -0
  124. package/dist/server/_chunks/index-x2m17v9c.js +6166 -0
  125. package/dist/server/_chunks/index-x3yn4ywm.js +22 -0
  126. package/dist/server/_chunks/index-x9c55pzy.js +871 -0
  127. package/dist/server/_chunks/index-xh1nbk46.js +1299 -0
  128. package/dist/server/_chunks/index-xvj80c3a.js +30 -0
  129. package/dist/server/_chunks/index-xywjg2vc.js +100 -0
  130. package/dist/server/_chunks/index-y4d02znn.js +66 -0
  131. package/dist/server/_chunks/index-y7mzvq2q.js +110 -0
  132. package/dist/server/_chunks/index-ye9hmsvf.js +47 -0
  133. package/dist/server/_chunks/index-yhxkxghe.js +56 -0
  134. package/dist/server/_chunks/index-yrjkqtfj.js +86 -0
  135. package/dist/server/_chunks/index-z88qv16t.js +11 -0
  136. package/dist/server/_chunks/index-zfrwq472.js +154 -0
  137. package/dist/server/_chunks/index-zqpqyg8p.js +666 -0
  138. package/dist/server/_chunks/loader-5en7wpt5.js +80 -0
  139. package/dist/server/_chunks/modules-t92favpj.js +76 -0
  140. package/dist/server/_chunks/pipeline-4t9q43ht.js +836 -0
  141. package/dist/server/_chunks/production-385bw8df.js +55 -0
  142. package/dist/server/_chunks/proxy-config-60gprphe.js +23 -0
  143. package/dist/server/_chunks/proxy-gfhmktbk.js +35 -0
  144. package/dist/server/_chunks/router-xnrva921.js +501 -0
  145. package/dist/server/_chunks/routes-ht868pdc.js +66 -0
  146. package/dist/server/_chunks/run-d40d63ag.js +697 -0
  147. package/dist/server/_chunks/server-2p8fgqq2.js +1839 -0
  148. package/dist/server/_chunks/tsconfig-defaults-bcn34eqb.js +21 -0
  149. package/dist/server/_chunks/typegen-dvtcjtaw.js +37 -0
  150. package/dist/server/api/client-cache.js +14 -0
  151. package/dist/server/cli/index.js +375 -0
  152. package/dist/server/cli/start.js +158 -0
  153. package/dist/server/client/reference.js +16 -0
  154. package/dist/server/compat/next/cache.js +56 -0
  155. package/dist/server/compat/next/canonical-url.js +13 -0
  156. package/dist/server/compat/next/client-cache.js +57 -0
  157. package/dist/server/compat/next/client-navigation.js +232 -0
  158. package/dist/server/compat/next/client-only.js +1 -0
  159. package/dist/server/compat/next/client-script.js +178 -0
  160. package/dist/server/compat/next/client-server.js +34 -0
  161. package/dist/server/compat/next/config-headers.js +34 -0
  162. package/dist/server/compat/next/config-loader.js +25 -0
  163. package/dist/server/compat/next/config.js +10 -0
  164. package/dist/server/compat/next/constants.js +18 -0
  165. package/dist/server/compat/next/custom-server.js +10 -0
  166. package/dist/server/compat/next/dist/client/components/app-router-headers.js +48 -0
  167. package/dist/server/compat/next/dist/server/web/spec-extension/revalidate.js +27 -0
  168. package/dist/server/compat/next/dist/server/web/spec-extension/unstable-cache.js +25 -0
  169. package/dist/server/compat/next/dist/server/web/spec-extension/unstable-no-store.js +25 -0
  170. package/dist/server/compat/next/dynamic.js +21 -0
  171. package/dist/server/compat/next/error.js +112 -0
  172. package/dist/server/compat/next/font/cache.js +16 -0
  173. package/dist/server/compat/next/font/google.js +3 -0
  174. package/dist/server/compat/next/font/index.js +1 -0
  175. package/dist/server/compat/next/font/local.js +24 -0
  176. package/dist/server/compat/next/font/runtime-client.js +33 -0
  177. package/dist/server/compat/next/font/runtime.js +43 -0
  178. package/dist/server/compat/next/font/shared.js +22 -0
  179. package/dist/server/compat/next/form.js +129 -0
  180. package/dist/server/compat/next/head.js +10 -0
  181. package/dist/server/compat/next/headers.js +30 -0
  182. package/dist/server/compat/next/image/client.js +11 -0
  183. package/dist/server/compat/next/image/config.js +18 -0
  184. package/dist/server/compat/next/image/optimizer.js +25 -0
  185. package/dist/server/compat/next/image/patterns.js +12 -0
  186. package/dist/server/compat/next/image/props.js +16 -0
  187. package/dist/server/compat/next/image/shared.js +86 -0
  188. package/dist/server/compat/next/image/static-metadata.js +32 -0
  189. package/dist/server/compat/next/image/validate.js +8 -0
  190. package/dist/server/compat/next/image.js +59 -0
  191. package/dist/server/compat/next/index.js +1 -0
  192. package/dist/server/compat/next/legacy-image.js +78 -0
  193. package/dist/server/compat/next/legacy-request-apis.js +24 -0
  194. package/dist/server/compat/next/link-transform.js +15 -0
  195. package/dist/server/compat/next/link.js +14 -0
  196. package/dist/server/compat/next/navigation.js +191 -0
  197. package/dist/server/compat/next/offline.js +45 -0
  198. package/dist/server/compat/next/og.js +8 -0
  199. package/dist/server/compat/next/preferred-region.js +8 -0
  200. package/dist/server/compat/next/redirects.js +32 -0
  201. package/dist/server/compat/next/resource-hints.js +30 -0
  202. package/dist/server/compat/next/rewrites.js +43 -0
  203. package/dist/server/compat/next/root-params.js +121 -0
  204. package/dist/server/compat/next/route-state.js +23 -0
  205. package/dist/server/compat/next/router.js +103 -0
  206. package/dist/server/compat/next/script.js +37 -0
  207. package/dist/server/compat/next/server-only.js +1 -0
  208. package/dist/server/compat/next/server.js +131 -0
  209. package/dist/server/compat/next/svgr.js +14 -0
  210. package/dist/server/compat/next/telemetry.js +10 -0
  211. package/dist/server/compat/next/usage.js +13 -0
  212. package/dist/server/compat/next/user-agent.js +12 -0
  213. package/dist/server/compat/next/web-vitals.js +35 -0
  214. package/dist/server/compat/react/action-state.js +11 -0
  215. package/dist/server/compat/react/client-lite.js +83 -0
  216. package/dist/server/compat/react/client.js +131 -0
  217. package/dist/server/compat/react/compiler-runtime.js +42 -0
  218. package/dist/server/compat/react/dom-client.js +106 -0
  219. package/dist/server/compat/react/dom-react-server.js +37 -0
  220. package/dist/server/compat/react/dom-server.js +40 -0
  221. package/dist/server/compat/react/dom.js +52 -0
  222. package/dist/server/compat/react/hooks-extra.js +12 -0
  223. package/dist/server/compat/react/internals.js +14 -0
  224. package/dist/server/compat/react/parity.js +11 -0
  225. package/dist/server/compat/react/preact.js +113 -0
  226. package/dist/server/compat/react/react-server.js +133 -0
  227. package/dist/server/compat/react/router-shim.js +8 -0
  228. package/dist/server/compat/react/server-component-use.js +14 -0
  229. package/dist/server/compat/react/server-inserted-html.js +14 -0
  230. package/dist/server/compat/react/server.js +194 -0
  231. package/dist/server/compat/react/style-values.js +10 -0
  232. package/dist/server/compat/react/use.js +10 -0
  233. package/dist/server/compat/react/view-transition.js +12 -0
  234. package/dist/server/generation.json +1 -0
  235. package/package.json +4 -1
  236. package/reference/compat.md +1 -1
  237. package/reference/config.md +2 -2
  238. package/reference/dev.md +1 -1
  239. package/reference/getting-started.md +1 -1
  240. package/reference/rendering.md +4 -4
  241. package/src/api/dynamic.tsx +86 -4
  242. package/src/api/server.ts +24 -6
  243. package/src/cli/adapters/vercel-warm.ts +327 -62
  244. package/src/cli/adapters/vercel.ts +164 -1054
  245. package/src/cli/analyze.ts +3 -2
  246. package/src/cli/build/cache.ts +6 -6
  247. package/src/cli/build.ts +78 -45
  248. package/src/cli/index.ts +21 -3
  249. package/src/cli/serve/immutable.ts +31 -0
  250. package/src/cli/serve/pipeline.ts +97 -93
  251. package/src/cli/serve/standalone-worker.ts +8 -0
  252. package/src/cli/serve/standalone.ts +703 -0
  253. package/src/cli/start.ts +31 -8
  254. package/src/client/build.ts +1 -1
  255. package/src/client/chunk-fold.ts +19 -6
  256. package/src/client/react-tier.ts +3 -2
  257. package/src/client/reference-stub.ts +23 -36
  258. package/src/compat/actions/client-plugin.ts +4 -2
  259. package/src/compat/actions/config.ts +6 -5
  260. package/src/compat/actions/extensions.ts +5 -5
  261. package/src/compat/aliases.ts +8 -1
  262. package/src/compat/bundler/config.ts +88 -0
  263. package/src/compat/bundler/optimize-package-imports.ts +86 -26
  264. package/src/compat/bundler/relay-transform.ts +15 -3
  265. package/src/compat/bundler/require-context.ts +2 -1
  266. package/src/compat/bundler/webpack-loaders.ts +3 -2
  267. package/src/compat/bundler/worker.ts +2 -2
  268. package/src/compat/cache-control.ts +16 -8
  269. package/src/compat/css/inline-css.ts +1 -1
  270. package/src/compat/css/modules.ts +18 -5
  271. package/src/compat/export/build-complete.ts +1 -1
  272. package/src/compat/export/emit.ts +4 -4
  273. package/src/compat/export/standalone.ts +30 -65
  274. package/src/compat/image-optimizer/optimize.ts +1 -1
  275. package/src/compat/lifecycle/error-funnel.ts +1 -1
  276. package/src/compat/lifecycle/instrumentation-client.ts +4 -3
  277. package/src/compat/lifecycle/instrumentation.ts +117 -24
  278. package/src/compat/lifecycle/testmode.ts +3 -2
  279. package/src/compat/metadata-artifacts.ts +1 -1
  280. package/src/compat/next/config-loader.ts +140 -13
  281. package/src/compat/next/dynamic.tsx +10 -23
  282. package/src/compat/next/font/cache.ts +2 -1
  283. package/src/compat/next/font/runtime.ts +23 -3
  284. package/src/compat/next/og.ts +3 -3
  285. package/src/compat/next/usage.ts +3 -2
  286. package/src/compat/pages/api.ts +83 -14
  287. package/src/compat/pages/router.ts +30 -14
  288. package/src/compat/register/bundler.ts +3 -1
  289. package/src/compat/register/image.ts +1 -1
  290. package/src/compat/register/middleware.ts +1 -1
  291. package/src/compat/register/otel.ts +5 -9
  292. package/src/compat/register/render.ts +3 -1
  293. package/src/compat/register/use-cache.ts +3 -1
  294. package/src/compat/release.ts +46 -0
  295. package/src/compat/segment/serve.ts +1 -1
  296. package/src/compat/typecheck/check.ts +6 -4
  297. package/src/compat/validation/validate.ts +10 -7
  298. package/src/config.ts +76 -9
  299. package/src/css/assets.ts +213 -0
  300. package/src/css/build.ts +190 -247
  301. package/src/dev/client-chunk-store.ts +2 -1
  302. package/src/dev/restart/client-key.ts +2 -1
  303. package/src/dev/restart/global-css.ts +2 -1
  304. package/src/dev/restart/route-bundle-key.ts +2 -1
  305. package/src/dev/restart/route-facts.ts +2 -1
  306. package/src/dev/server.ts +34 -14
  307. package/src/extensions.ts +4 -0
  308. package/src/out-paths.ts +10 -0
  309. package/src/render/hooks.ts +13 -0
  310. package/src/render/renderer.ts +53 -33
  311. package/src/request/context.ts +9 -0
  312. package/src/resolve/dynamic.ts +7 -1
  313. package/src/resolve/engine.ts +2 -12
  314. package/src/resolve/imports.ts +12 -52
  315. package/src/resolve/package-json.ts +56 -0
  316. package/src/resolve/scan-facts.ts +250 -1
  317. package/src/routing/href.ts +10 -3
  318. package/src/routing/match.ts +287 -0
  319. package/src/routing/metadata-files.ts +20 -6
  320. package/src/routing/proxy-config.ts +137 -0
  321. package/src/routing/proxy.ts +35 -134
  322. package/src/routing/routes.ts +22 -281
  323. package/src/runtime/fingerprint.ts +23 -8
  324. package/src/runtime/load.ts +170 -0
  325. package/src/runtime/loader.ts +218 -44
  326. package/src/runtime/module-cache.ts +15 -1
  327. package/src/runtime/modules.ts +405 -82
  328. package/src/runtime/prebundle.ts +101 -0
  329. package/src/runtime/production.ts +456 -0
  330. package/src/runtime/release-graph.ts +342 -0
  331. package/src/runtime/vendor-build.ts +750 -17
  332. package/src/runtime/vendor.ts +16 -3
  333. package/src/types.ts +4 -3
  334. package/src/utils/directive.ts +40 -0
  335. package/src/utils/fs.ts +95 -4
  336. package/src/utils/resource-query.ts +12 -0
  337. package/src/cli/serve/entry.ts +0 -45
@@ -0,0 +1,871 @@
1
+ // @bun
2
+ import {
3
+ isCommonJsModuleSource
4
+ } from "./index-d1jsmhhk.js";
5
+ import {
6
+ loadNative
7
+ } from "./index-7wc9n8be.js";
8
+ import {
9
+ __require
10
+ } from "./index-rt9qq1va.js";
11
+
12
+ // src/runtime/module-transform.ts
13
+ var transformSync = (...args) => loadNative(() => __require("oxc-transform")).transformSync(...args);
14
+ var NON_LITERAL_DYNAMIC_IMPORT = /\bimport\s*\(\s*(?!['"])[^)]/;
15
+ var REQUIRE_CALL = /\brequire\s*\(/;
16
+ var COMMONJS_EXPORTS = /\bmodule\.exports\b|\bexports\s*\.\s*[A-Za-z_$]/;
17
+ var ENUM_DECLARATION = /(?:^|[^.\w$])enum\s+[A-Za-z_$]/;
18
+ function transformBailReason(source, file) {
19
+ if (REQUIRE_CALL.test(source) || COMMONJS_EXPORTS.test(source) || isCommonJsModuleSource(source, file)) {
20
+ return "commonjs";
21
+ }
22
+ if (NON_LITERAL_DYNAMIC_IMPORT.test(source))
23
+ return "glob-import";
24
+ if (ENUM_DECLARATION.test(source))
25
+ return "enum";
26
+ return;
27
+ }
28
+ function transformServerModule(source, file, define) {
29
+ const options = {
30
+ lang: langForFile(file),
31
+ jsx: { runtime: "automatic", importSource: "preact" },
32
+ sourcemap: false,
33
+ ...define ? { define } : {}
34
+ };
35
+ const result = transformSync(file, source, options);
36
+ if (result.errors.length > 0)
37
+ return { bail: "parse-error" };
38
+ if (Object.keys(result.helpersUsed).length > 0)
39
+ return { bail: "helpers" };
40
+ return { code: dropUnreferencedImports(result.code) };
41
+ }
42
+ function langForFile(file) {
43
+ if (/\.[mc]?ts$/.test(file))
44
+ return "ts";
45
+ if (file.endsWith(".tsx"))
46
+ return "tsx";
47
+ return "jsx";
48
+ }
49
+ var SPECIFIER_RE = /(?:^|[\n;{}])\s*(?:import|export)\b[^;'"]*?\bfrom\s*("[^"]*"|'[^']*')|(?:^|[\n;{}])\s*import\s*("[^"]*"|'[^']*')|\bimport\s*\(\s*("[^"]*"|'[^']*')\s*\)/g;
50
+ function outputSpecifiers(code) {
51
+ const found = [];
52
+ SPECIFIER_RE.lastIndex = 0;
53
+ let match;
54
+ while (match = SPECIFIER_RE.exec(code)) {
55
+ for (let group = 1;group <= 3; group += 1) {
56
+ const literal = match[group];
57
+ if (literal === undefined)
58
+ continue;
59
+ const start = match.index + match[0].lastIndexOf(literal);
60
+ found.push({
61
+ start,
62
+ end: start + literal.length,
63
+ value: literal.slice(1, -1),
64
+ kind: group === 3 ? "dynamic-import" : "import-statement"
65
+ });
66
+ }
67
+ }
68
+ return found;
69
+ }
70
+ function spliceSource(code, edits) {
71
+ let next = code;
72
+ for (const edit of [...edits].sort((a, b) => b.start - a.start)) {
73
+ next = `${next.slice(0, edit.start)}${edit.value}${next.slice(edit.end)}`;
74
+ }
75
+ return next;
76
+ }
77
+ var IMPORT_STATEMENT_RE = /(?:^|\n)[ \t]*import\s+([A-Za-z_$][\w$]*\s*,\s*)?(?:\*\s*as\s+([A-Za-z_$][\w$]*)|\{([^}]*)\}|([A-Za-z_$][\w$]*))\s+from\s*(?:"[^"]*"|'[^']*')\s*;?/g;
78
+ function dropUnreferencedImports(code) {
79
+ const statements = [];
80
+ IMPORT_STATEMENT_RE.lastIndex = 0;
81
+ let match;
82
+ while (match = IMPORT_STATEMENT_RE.exec(code)) {
83
+ const [text, defaultWithNamed, namespace, named, defaultOnly] = match;
84
+ const names = [];
85
+ if (defaultWithNamed)
86
+ names.push(defaultWithNamed.replace(/\s*,\s*$/, "").trim());
87
+ if (namespace)
88
+ names.push(namespace);
89
+ if (defaultOnly)
90
+ names.push(defaultOnly);
91
+ if (named !== undefined) {
92
+ for (const part of named.split(",")) {
93
+ const local = part.split(/\bas\b/).pop()?.trim();
94
+ if (!local)
95
+ continue;
96
+ if (!/^[A-Za-z_$][\w$]*$/.test(local))
97
+ return code;
98
+ names.push(local);
99
+ }
100
+ }
101
+ if (names.length === 0)
102
+ continue;
103
+ const leading = text.startsWith(`
104
+ `) ? 1 : 0;
105
+ statements.push({ start: match.index + leading, end: match.index + text.length, names });
106
+ }
107
+ if (statements.length === 0)
108
+ return code;
109
+ const gaps = [];
110
+ let cursor = 0;
111
+ for (const statement of statements) {
112
+ gaps.push(code.slice(cursor, statement.start));
113
+ cursor = statement.end;
114
+ }
115
+ gaps.push(code.slice(cursor));
116
+ const used = referencedNames(gaps.join(`
117
+ `));
118
+ const unused = statements.filter((statement) => statement.names.every((name) => !used.has(name)));
119
+ if (unused.length === 0)
120
+ return code;
121
+ return spliceSource(code, unused.map(({ start, end }) => ({ start, end, value: "" })));
122
+ }
123
+ var IDENTIFIER_RE = /[A-Za-z_$][\w$]*/g;
124
+ function referencedNames(body) {
125
+ const names = new Set;
126
+ IDENTIFIER_RE.lastIndex = 0;
127
+ let match;
128
+ while (match = IDENTIFIER_RE.exec(body)) {
129
+ if (body[match.index - 1] === "." && body[match.index - 2] !== ".")
130
+ continue;
131
+ names.add(match[0]);
132
+ }
133
+ return names;
134
+ }
135
+
136
+ // src/resolve/scan-facts.ts
137
+ var parseSync = (...args) => loadNative(() => __require("oxc-parser")).parseSync(...args);
138
+ var { Bun: bun } = globalThis;
139
+ var stylesheetOrData = /\.(?:css|scss|sass|less|styl|json)$/;
140
+ var emptyFacts = {
141
+ imports: [],
142
+ dynamicImports: [],
143
+ requires: [],
144
+ exportNames: [],
145
+ exportStars: [],
146
+ useClient: false,
147
+ useServer: false,
148
+ dynamicCalls: []
149
+ };
150
+ var emptyRewriteFacts = {
151
+ edges: [],
152
+ imports: [],
153
+ importMetas: [],
154
+ computedImports: [],
155
+ unreliable: false
156
+ };
157
+ var memo = new Map;
158
+ var hits = 0;
159
+ var misses = 0;
160
+ function scanFacts(file, source) {
161
+ if (stylesheetOrData.test(file))
162
+ return emptyFacts;
163
+ return parsed(file, source).scan;
164
+ }
165
+ function importSpecifiers(source, sourcefile = "source") {
166
+ const facts = scanFacts(sourcefile, source);
167
+ return [
168
+ ...facts.imports.map((edge) => edge.specifier),
169
+ ...facts.dynamicImports.map((entry) => entry.specifier),
170
+ ...facts.requires.map((entry) => entry.specifier)
171
+ ];
172
+ }
173
+ function moduleExportNames(source, sourcefile = "source.tsx") {
174
+ return scanFacts(sourcefile, source).exportNames;
175
+ }
176
+ function moduleExportStars(source, sourcefile = "source.tsx") {
177
+ return scanFacts(sourcefile, source).exportStars;
178
+ }
179
+ function dynamicCallFacts(source, file = "module.tsx") {
180
+ if (stylesheetOrData.test(file))
181
+ return [];
182
+ return parsed(file, source).scan.dynamicCalls;
183
+ }
184
+ function rewriteFacts(file, source) {
185
+ if (stylesheetOrData.test(file))
186
+ return emptyRewriteFacts;
187
+ return parsed(file, source).rewrite;
188
+ }
189
+ function moduleSpecifierEdges(source, file = "source") {
190
+ const facts = rewriteFacts(file, source);
191
+ return facts.unreliable ? textualEdges(source) : facts.edges;
192
+ }
193
+ function parsed(file, source, lang = langForFile2(file)) {
194
+ const key = `${lang}\x00${source.length}\x00${bun.hash(source).toString()}`;
195
+ const cached = memo.get(key);
196
+ if (cached) {
197
+ hits += 1;
198
+ return cached;
199
+ }
200
+ misses += 1;
201
+ const facts = parseFacts(file, source, lang);
202
+ memo.set(key, facts);
203
+ return facts;
204
+ }
205
+ function rewriteSpecifierLiterals(source, file, replace) {
206
+ const edges = moduleSpecifierEdges(source, file);
207
+ const edits = [];
208
+ for (const edge of edges) {
209
+ const value = replace(edge.specifier, edge.kind);
210
+ if (value !== undefined)
211
+ edits.push({ start: edge.start, end: edge.end, value });
212
+ }
213
+ return edits.length > 0 ? spliceSource(source, edits) : source;
214
+ }
215
+ var textualSpecifier = /(\bfrom\s*|\b(?:import|require)\s*\(\s*)(['"])([^'"]+)\2/g;
216
+ function textualEdges(source) {
217
+ const edges = [];
218
+ textualSpecifier.lastIndex = 0;
219
+ let match;
220
+ while (match = textualSpecifier.exec(source)) {
221
+ const start = match.index + match[1].length;
222
+ edges.push({
223
+ specifier: match[3],
224
+ start,
225
+ end: start + match[3].length + 2,
226
+ kind: match[1].includes("require") ? "require" : match[1].includes("import") ? "dynamic" : "import"
227
+ });
228
+ }
229
+ return edges;
230
+ }
231
+ function scanFactsStats() {
232
+ return { hits, misses, sources: memo.size };
233
+ }
234
+ function parseFacts(file, source, lang) {
235
+ const result = parseSync(file, source, { lang });
236
+ const imports = [];
237
+ const exportNames = [];
238
+ const exportStars = [];
239
+ const edges = [];
240
+ const importStatements = [];
241
+ for (const statement of result.module.staticImports) {
242
+ const names = [];
243
+ const bindings = [];
244
+ let bindsValue = statement.entries.length === 0;
245
+ for (const entry of statement.entries) {
246
+ const kind = entry.importName.kind;
247
+ bindings.push({
248
+ imported: kind === "Default" ? "default" : kind === "NamespaceObject" ? "*" : entry.importName.name ?? "",
249
+ local: entry.localName.value ?? "",
250
+ type: entry.isType
251
+ });
252
+ if (entry.isType)
253
+ continue;
254
+ bindsValue = true;
255
+ if (kind === "Default")
256
+ names.push("default");
257
+ else if (kind === "NamespaceObject")
258
+ names.push("*");
259
+ else if (entry.importName.name)
260
+ names.push(entry.importName.name);
261
+ }
262
+ importStatements.push({
263
+ specifier: statement.moduleRequest.value,
264
+ start: statement.start,
265
+ end: statement.end,
266
+ specifierStart: statement.moduleRequest.start,
267
+ specifierEnd: statement.moduleRequest.end,
268
+ bindings
269
+ });
270
+ edges.push({
271
+ specifier: statement.moduleRequest.value,
272
+ start: statement.moduleRequest.start,
273
+ end: statement.moduleRequest.end,
274
+ kind: statement.entries.length === 0 ? "side-effect" : "import"
275
+ });
276
+ if (!bindsValue)
277
+ continue;
278
+ imports.push({
279
+ specifier: statement.moduleRequest.value,
280
+ exports: names,
281
+ index: statement.start
282
+ });
283
+ }
284
+ const seenExportRequests = new Set;
285
+ for (const statement of result.module.staticExports) {
286
+ for (const entry of statement.entries) {
287
+ const request = entry.moduleRequest;
288
+ if (!request || seenExportRequests.has(request.start))
289
+ continue;
290
+ seenExportRequests.add(request.start);
291
+ edges.push({
292
+ specifier: request.value,
293
+ start: request.start,
294
+ end: request.end,
295
+ kind: "export"
296
+ });
297
+ }
298
+ }
299
+ for (const statement of result.module.staticExports) {
300
+ const edges2 = new Map;
301
+ for (const entry of statement.entries) {
302
+ if (entry.isType)
303
+ continue;
304
+ const exportKind = entry.exportName.kind;
305
+ if (exportKind === "Default")
306
+ exportNames.push("default");
307
+ else if (entry.exportName.name)
308
+ exportNames.push(entry.exportName.name);
309
+ const specifier = entry.moduleRequest?.value;
310
+ if (!specifier)
311
+ continue;
312
+ const importKind = entry.importName.kind;
313
+ const star = importKind === "AllButDefault";
314
+ if (star)
315
+ exportStars.push(specifier);
316
+ let edge = edges2.get(specifier);
317
+ if (!edge) {
318
+ edge = {
319
+ specifier,
320
+ exports: [],
321
+ index: statement.start,
322
+ reexport: true,
323
+ exportMap: {}
324
+ };
325
+ edges2.set(specifier, edge);
326
+ imports.push(edge);
327
+ }
328
+ if (star)
329
+ edge.star = true;
330
+ else if (importKind === "All")
331
+ edge.exports.push("*");
332
+ else {
333
+ const imported = importKind === "Default" ? "default" : entry.importName.name;
334
+ if (!imported)
335
+ continue;
336
+ edge.exports.push(imported);
337
+ const exported = exportKind === "Default" ? "default" : entry.exportName.name;
338
+ if (exported)
339
+ edge.exportMap[exported] = imported;
340
+ }
341
+ }
342
+ }
343
+ imports.sort((a, b) => a.index - b.index);
344
+ const dynamicImports = [];
345
+ const computedImports = [];
346
+ for (const entry of result.module.dynamicImports) {
347
+ const raw = source.slice(entry.moduleRequest.start, entry.moduleRequest.end);
348
+ const specifier = literalSpecifier(raw);
349
+ if (specifier === undefined) {
350
+ computedImports.push({ start: entry.start, end: entry.end });
351
+ continue;
352
+ }
353
+ dynamicImports.push({ specifier, index: entry.start });
354
+ const lead = raw.length - raw.trimStart().length;
355
+ edges.push({
356
+ specifier,
357
+ start: entry.moduleRequest.start + lead,
358
+ end: entry.moduleRequest.start + lead + specifier.length + 2,
359
+ kind: "dynamic"
360
+ });
361
+ }
362
+ const requires = requireCalls(source, result.comments);
363
+ for (const call of requires) {
364
+ edges.push({
365
+ specifier: call.specifier,
366
+ start: call.specifierStart,
367
+ end: call.specifierStart + call.specifier.length + 2,
368
+ kind: "require"
369
+ });
370
+ }
371
+ edges.sort((a, b) => a.start - b.start);
372
+ return {
373
+ scan: {
374
+ imports,
375
+ dynamicImports,
376
+ requires,
377
+ exportNames,
378
+ exportStars,
379
+ useClient: moduleDirective(source, result, "use client"),
380
+ useServer: moduleDirective(source, result, "use server"),
381
+ dynamicCalls: source.includes("@wular/pnext") || source.includes("next/dynamic") ? collectDynamicCalls(result.program) : []
382
+ },
383
+ rewrite: {
384
+ edges,
385
+ imports: importStatements,
386
+ importMetas: result.module.importMetas.map((meta) => ({ start: meta.start, end: meta.end })),
387
+ computedImports,
388
+ unreliable: result.errors.length > 0
389
+ }
390
+ };
391
+ }
392
+ function moduleDirective(source, result, directive) {
393
+ const sniffed = sniffDirective(source, directive);
394
+ if (sniffed !== undefined)
395
+ return sniffed;
396
+ if (!source.includes(directive))
397
+ return false;
398
+ return hasDirective(result.program.body, directive);
399
+ }
400
+ var continuesExpression = /[+\-*/%.,?:=<>!&|^~([`)\]}]/;
401
+ var wordContinuation = /^(?:in|instanceof)\b/;
402
+ var lineTerminator = /[\n\r\u2028\u2029]/;
403
+ function sniffDirective(source, directive) {
404
+ let index = 0;
405
+ if (source.startsWith("#!")) {
406
+ const nl = source.search(lineTerminator);
407
+ if (nl < 0)
408
+ return false;
409
+ index = nl + 1;
410
+ }
411
+ for (;; ) {
412
+ index = skipTrivia(source, index);
413
+ if (index < 0)
414
+ return;
415
+ const quote = source[index];
416
+ if (quote !== '"' && quote !== "'")
417
+ return false;
418
+ let end = index + 1;
419
+ while (end < source.length) {
420
+ const char = source[end];
421
+ if (char === "\\" || lineTerminator.test(char))
422
+ return;
423
+ if (char === quote)
424
+ break;
425
+ end += 1;
426
+ }
427
+ if (end >= source.length)
428
+ return;
429
+ const raw = source.slice(index + 1, end);
430
+ const after = skipTrivia(source, end + 1);
431
+ if (after < 0)
432
+ return;
433
+ const next = source[after];
434
+ let terminated = after >= source.length || next === ";";
435
+ if (!terminated && lineTerminator.test(source.slice(end + 1, after))) {
436
+ terminated = !continuesExpression.test(next) && !wordContinuation.test(source.slice(after, after + 11));
437
+ }
438
+ if (!terminated)
439
+ return;
440
+ if (raw === directive)
441
+ return true;
442
+ index = next === ";" ? after + 1 : after;
443
+ if (index >= source.length)
444
+ return false;
445
+ }
446
+ }
447
+ function skipTrivia(source, index) {
448
+ for (;; ) {
449
+ while (index < source.length && /\s/.test(source[index]))
450
+ index += 1;
451
+ if (source[index] !== "/")
452
+ return index;
453
+ if (source[index + 1] === "/") {
454
+ let end = index + 2;
455
+ while (end < source.length && !lineTerminator.test(source[end]))
456
+ end += 1;
457
+ index = end;
458
+ continue;
459
+ }
460
+ if (source[index + 1] === "*") {
461
+ const end = source.indexOf("*/", index + 2);
462
+ if (end < 0)
463
+ return -1;
464
+ index = end + 2;
465
+ continue;
466
+ }
467
+ return index;
468
+ }
469
+ }
470
+ function hasDirective(body, directive) {
471
+ for (const statement of body) {
472
+ if (statement.type !== "ExpressionStatement" || typeof statement.directive !== "string")
473
+ return false;
474
+ if (statement.directive === directive)
475
+ return true;
476
+ }
477
+ return false;
478
+ }
479
+ var requirePattern = /\brequire\s*\(\s*(['"])([^'"]+)\1\s*\)/g;
480
+ function requireCalls(source, comments) {
481
+ const calls = [];
482
+ if (!source.includes("require"))
483
+ return calls;
484
+ requirePattern.lastIndex = 0;
485
+ let match;
486
+ let cursor = 0;
487
+ while (match = requirePattern.exec(source)) {
488
+ const index = match.index;
489
+ while (cursor < comments.length && comments[cursor].end <= index)
490
+ cursor += 1;
491
+ if (cursor < comments.length && index >= comments[cursor].start)
492
+ continue;
493
+ calls.push({
494
+ specifier: match[2],
495
+ index,
496
+ specifierStart: index + match[0].indexOf(match[1])
497
+ });
498
+ }
499
+ return calls;
500
+ }
501
+ function literalSpecifier(raw) {
502
+ return /^\s*(['"])([^'"]*)\1\s*$/.exec(raw)?.[2] || undefined;
503
+ }
504
+ function isNode(value) {
505
+ return typeof value === "object" && value !== null && typeof value.type === "string";
506
+ }
507
+ function child(node, key) {
508
+ const value = node?.[key];
509
+ return isNode(value) ? value : undefined;
510
+ }
511
+ var noMetaRefs = {
512
+ urls: [],
513
+ resolves: [],
514
+ readsLocation: false,
515
+ computedImports: [],
516
+ unreliable: false
517
+ };
518
+ var metaRefMemo = new Map;
519
+ var locationMembers = new Set(["url", "dirname", "filename", "resolve"]);
520
+ function importMetaRefs(file, source) {
521
+ if (stylesheetOrData.test(file))
522
+ return noMetaRefs;
523
+ if (!source.includes("import.meta") && !source.includes("import("))
524
+ return noMetaRefs;
525
+ const record = rewriteFacts(file, source);
526
+ if (record.importMetas.length === 0)
527
+ return { ...noMetaRefs, computedImports: record.computedImports, unreliable: record.unreliable };
528
+ const lang = langForFile2(file);
529
+ const key = `${lang}\x00${source.length}\x00${bun.hash(source).toString()}`;
530
+ const cached = metaRefMemo.get(key);
531
+ if (cached)
532
+ return cached;
533
+ const result = parseSync(file, source, { lang });
534
+ const refs = {
535
+ ...noMetaRefs,
536
+ urls: [],
537
+ resolves: [],
538
+ computedImports: record.computedImports
539
+ };
540
+ refs.unreliable = result.errors.length > 0;
541
+ const isImportMeta = (node) => node?.type === "MetaProperty" && child(node, "meta")?.name === "import" && child(node, "property")?.name === "meta";
542
+ const memberName = (node) => node.computed ? stringValue(child(node, "property")) : child(node, "property")?.name;
543
+ const literal = (node) => {
544
+ if (!node)
545
+ return;
546
+ const value = stringValue(node) ?? (node.type === "TemplateLiteral" && node.expressions.length === 0 ? node.quasis[0]?.value?.cooked : undefined);
547
+ return value === undefined ? undefined : { specifier: value, start: node.start, end: node.end };
548
+ };
549
+ const visit = (value, parent) => {
550
+ if (Array.isArray(value)) {
551
+ for (const item of value)
552
+ visit(item, parent);
553
+ return;
554
+ }
555
+ if (!isNode(value))
556
+ return;
557
+ if (isImportMeta(value)) {
558
+ const member = parent?.type === "MemberExpression" && parent.object === value;
559
+ if (!member || locationMembers.has(memberName(parent) ?? ""))
560
+ refs.readsLocation = true;
561
+ } else if (value.type === "NewExpression" && child(value, "callee")?.name === "URL") {
562
+ const [target, base] = value.arguments;
563
+ const span = literal(target);
564
+ if (span && base?.type === "MemberExpression" && isImportMeta(child(base, "object"))) {
565
+ if (memberName(base) === "url")
566
+ refs.urls.push(span);
567
+ }
568
+ } else if (value.type === "CallExpression") {
569
+ const callee = child(value, "callee");
570
+ if (callee?.type === "MemberExpression" && isImportMeta(child(callee, "object"))) {
571
+ const span = literal(value.arguments[0]);
572
+ if (span && memberName(callee) === "resolve")
573
+ refs.resolves.push(span);
574
+ }
575
+ }
576
+ for (const key2 in value) {
577
+ if (key2 !== "start" && key2 !== "end" && key2 !== "type")
578
+ visit(value[key2], value);
579
+ }
580
+ };
581
+ visit(result.program, undefined);
582
+ metaRefMemo.set(key, refs);
583
+ return refs;
584
+ }
585
+ function hasModuleState(file, source) {
586
+ const result = parseSync(file, source, { lang: langForFile2(file) });
587
+ const pureEnds = new Set(result.comments.filter((comment) => /^\s*[#@]__PURE__\s*$/.test(comment.value)).map((comment) => comment.end));
588
+ const annotatedPure = (node) => {
589
+ for (let index = node.start - 1;index >= 0; index -= 1) {
590
+ if (pureEnds.has(index + 1))
591
+ return true;
592
+ if (!/\s/.test(source[index]))
593
+ return false;
594
+ }
595
+ return false;
596
+ };
597
+ const plainCallee = (node) => node?.type === "Identifier" || node?.type === "MemberExpression" && !node.computed && plainCallee(child(node, "object"));
598
+ const declarations = result.program.body.flatMap((statement) => {
599
+ const declaration = statement.type === "ExportNamedDeclaration" ? child(statement, "declaration") : statement;
600
+ return declaration?.type === "VariableDeclaration" ? declaration.declarations : [];
601
+ });
602
+ return declarations.some((declarator) => {
603
+ const init = unwrapExpression(child(declarator, "init"));
604
+ if (init?.type === "NewExpression")
605
+ return true;
606
+ if (init?.type !== "CallExpression")
607
+ return false;
608
+ const callee = child(init, "callee");
609
+ return plainCallee(callee) && callee?.name !== "require" && !annotatedPure(init);
610
+ });
611
+ }
612
+ function absolutePathLiterals(file, source) {
613
+ const result = parseSync(file, source, { lang: langForFile2(file) });
614
+ if (result.errors.length > 0)
615
+ return;
616
+ const found = [];
617
+ const visit = (value, parent) => {
618
+ if (Array.isArray(value)) {
619
+ for (const item of value)
620
+ visit(item, parent);
621
+ return;
622
+ }
623
+ if (!isNode(value))
624
+ return;
625
+ const literal = stringValue(value);
626
+ if (literal !== undefined && (literal.startsWith("/") || literal.startsWith("file:///"))) {
627
+ const key = parent?.type === "Property" && parent.key === value && !parent.computed;
628
+ found.push({ value: literal, start: value.start, end: value.end, key });
629
+ }
630
+ for (const key in value) {
631
+ if (key !== "start" && key !== "end" && key !== "type")
632
+ visit(value[key], value);
633
+ }
634
+ };
635
+ visit(result.program, undefined);
636
+ return found;
637
+ }
638
+ function lineComments(file, source) {
639
+ const result = parseSync(file, source, { lang: langForFile2(file) });
640
+ if (result.errors.length > 0)
641
+ return;
642
+ return result.comments.filter((comment) => comment.type === "Line").map((comment) => ({ value: comment.value, start: comment.start, end: comment.end }));
643
+ }
644
+ function stripJsonImportAttributes(source, file, compiled) {
645
+ const result = parseSync(file, source, { lang: "js", sourceType: "module" });
646
+ if (result.errors.length > 0)
647
+ return source;
648
+ const edits = [];
649
+ const visit = (node) => {
650
+ const target = child(node, "source");
651
+ const specifier = stringValue(target);
652
+ if (target && specifier !== undefined && compiled(specifier)) {
653
+ const attributes = node.attributes;
654
+ const options = child(node, "options");
655
+ if (attributes?.length && attributes.every(jsonTypeAttribute)) {
656
+ const end = source.indexOf("}", attributes.at(-1).end) + 1;
657
+ edits.push({ start: target.end, end, value: "" });
658
+ } else if (node.type === "ImportExpression" && options && jsonImportOptions(options)) {
659
+ edits.push({ start: target.end, end: options.end, value: "" });
660
+ }
661
+ }
662
+ for (const value of Object.values(node)) {
663
+ if (isNode(value))
664
+ visit(value);
665
+ else if (Array.isArray(value)) {
666
+ for (const item of value)
667
+ if (isNode(item))
668
+ visit(item);
669
+ }
670
+ }
671
+ };
672
+ visit(result.program);
673
+ return edits.length > 0 ? spliceSource(source, edits) : source;
674
+ }
675
+ function propertyName(node) {
676
+ if (!node)
677
+ return;
678
+ return node.type === "Identifier" ? node.name : stringValue(node);
679
+ }
680
+ function jsonTypeAttribute(node) {
681
+ return !node.computed && propertyName(child(node, "key")) === "type" && stringValue(child(node, "value")) === "json";
682
+ }
683
+ function jsonImportOptions(options) {
684
+ const [property, ...rest] = options.properties ?? [];
685
+ const attributes = child(property, "value");
686
+ const entries = attributes?.properties;
687
+ return options.type === "ObjectExpression" && !!property && rest.length === 0 && property.type === "Property" && !property.computed && ["with", "assert"].includes(propertyName(child(property, "key")) ?? "") && attributes?.type === "ObjectExpression" && !!entries?.length && entries.every((entry) => entry.type === "Property" && jsonTypeAttribute(entry));
688
+ }
689
+ function collectDynamicCalls(program) {
690
+ const calls = [];
691
+ const visit = (value) => {
692
+ if (Array.isArray(value)) {
693
+ for (const item of value)
694
+ visit(item);
695
+ return;
696
+ }
697
+ if (!isNode(value))
698
+ return;
699
+ if (value.type === "CallExpression") {
700
+ const fact = dynamicCallFact(value);
701
+ if (fact)
702
+ calls.push(fact);
703
+ }
704
+ for (const key in value) {
705
+ if (key === "type" || key === "loc" || key === "range")
706
+ continue;
707
+ const entry = value[key];
708
+ if (entry && typeof entry === "object")
709
+ visit(entry);
710
+ }
711
+ };
712
+ visit(program.body);
713
+ return calls.sort((a, b) => a.start - b.start);
714
+ }
715
+ function dynamicCallFact(call) {
716
+ const callee = child(call, "callee");
717
+ if (callee?.type !== "Identifier")
718
+ return;
719
+ const args = call.arguments;
720
+ if (!Array.isArray(args) || !isNode(args[0]))
721
+ return;
722
+ const loader = args[0];
723
+ let target;
724
+ let literal;
725
+ if (stringValue(loader) !== undefined) {
726
+ target = { specifier: loader, exportName: "default" };
727
+ literal = true;
728
+ } else if (loader.type === "ArrowFunctionExpression" || loader.type === "FunctionExpression") {
729
+ target = loaderImportTarget(loader) ?? firstImportTarget(loader);
730
+ }
731
+ if (!target)
732
+ return;
733
+ const specifier = stringValue(target.specifier);
734
+ if (specifier === undefined)
735
+ return;
736
+ const options = isNode(args[1]) ? args[1] : undefined;
737
+ return {
738
+ name: callee.name,
739
+ start: callee.start,
740
+ end: call.end,
741
+ specifier,
742
+ specifierStart: target.specifier.start,
743
+ specifierEnd: target.specifier.end,
744
+ exportName: target.exportName,
745
+ ...literal ? { literal } : {},
746
+ loaderEnd: loader.end,
747
+ ...options ? { optionsStart: options.start, optionsEnd: options.end } : {}
748
+ };
749
+ }
750
+ function stringValue(node) {
751
+ if (!node)
752
+ return;
753
+ if (node.type !== "Literal" && node.type !== "StringLiteral")
754
+ return;
755
+ return typeof node.value === "string" ? node.value : undefined;
756
+ }
757
+ function unwrapExpression(node) {
758
+ let current = node;
759
+ for (;; ) {
760
+ if (!current)
761
+ return;
762
+ if (current.type === "ParenthesizedExpression" || current.type === "ChainExpression") {
763
+ current = child(current, "expression");
764
+ } else if (current.type === "AwaitExpression") {
765
+ current = child(current, "argument");
766
+ } else if (current.type === "TSAsExpression" || current.type === "TSNonNullExpression" || current.type === "TSSatisfiesExpression") {
767
+ current = child(current, "expression");
768
+ } else {
769
+ return current;
770
+ }
771
+ }
772
+ }
773
+ function loaderResult(fn) {
774
+ const body = child(fn, "body");
775
+ if (!body)
776
+ return;
777
+ if (body.type !== "BlockStatement" && body.type !== "FunctionBody")
778
+ return unwrapExpression(body);
779
+ const statements = body.body;
780
+ if (!Array.isArray(statements))
781
+ return;
782
+ for (const statement of statements) {
783
+ if (isNode(statement) && statement.type === "ReturnStatement") {
784
+ return unwrapExpression(child(statement, "argument"));
785
+ }
786
+ }
787
+ return;
788
+ }
789
+ function importSource(node) {
790
+ if (node?.type !== "ImportExpression")
791
+ return;
792
+ const source = child(node, "source");
793
+ return source && stringValue(source) !== undefined ? source : undefined;
794
+ }
795
+ function loaderImportTarget(fn) {
796
+ const result = loaderResult(fn);
797
+ if (!result)
798
+ return;
799
+ const direct = importSource(result);
800
+ if (direct)
801
+ return { specifier: direct, exportName: "default" };
802
+ if (result.type === "MemberExpression" && result.computed !== true) {
803
+ const source2 = importSource(unwrapExpression(child(result, "object")));
804
+ const property = child(result, "property");
805
+ if (source2 && property?.type === "Identifier") {
806
+ return { specifier: source2, exportName: property.name };
807
+ }
808
+ }
809
+ if (result.type !== "CallExpression")
810
+ return;
811
+ const callee = child(result, "callee");
812
+ if (callee?.type !== "MemberExpression" || callee.computed === true)
813
+ return;
814
+ if (child(callee, "property")?.name !== "then")
815
+ return;
816
+ const source = importSource(unwrapExpression(child(callee, "object")));
817
+ if (!source)
818
+ return;
819
+ return { specifier: source, exportName: thenArmExport(result) ?? "default" };
820
+ }
821
+ function thenArmExport(thenCall) {
822
+ const args = thenCall.arguments;
823
+ if (!Array.isArray(args) || !isNode(args[0]))
824
+ return;
825
+ const arm = args[0];
826
+ if (arm.type !== "ArrowFunctionExpression" && arm.type !== "FunctionExpression")
827
+ return;
828
+ const params = arm.params;
829
+ const param = Array.isArray(params) && isNode(params[0]) ? params[0] : undefined;
830
+ if (param?.type !== "Identifier")
831
+ return;
832
+ const result = loaderResult(arm);
833
+ if (result?.type !== "MemberExpression" || result.computed === true)
834
+ return;
835
+ const object = unwrapExpression(child(result, "object"));
836
+ if (object?.type !== "Identifier" || object.name !== param.name)
837
+ return;
838
+ const property = child(result, "property");
839
+ return property?.type === "Identifier" ? property.name : undefined;
840
+ }
841
+ function firstImportTarget(fn) {
842
+ let found;
843
+ const visit = (value) => {
844
+ if (found)
845
+ return;
846
+ if (Array.isArray(value)) {
847
+ for (const item of value)
848
+ visit(item);
849
+ return;
850
+ }
851
+ if (!isNode(value))
852
+ return;
853
+ const source = importSource(value);
854
+ if (source) {
855
+ found = source;
856
+ return;
857
+ }
858
+ for (const key in value) {
859
+ const entry = value[key];
860
+ if (entry && typeof entry === "object")
861
+ visit(entry);
862
+ }
863
+ };
864
+ visit(fn.body);
865
+ return found ? { specifier: found, exportName: "default" } : undefined;
866
+ }
867
+ function langForFile2(file) {
868
+ return /\.[mc]?ts$/.test(file) ? "ts" : "tsx";
869
+ }
870
+
871
+ export { transformBailReason, transformServerModule, outputSpecifiers, spliceSource, scanFacts, importSpecifiers, moduleExportNames, moduleExportStars, dynamicCallFacts, rewriteFacts, moduleSpecifierEdges, rewriteSpecifierLiterals, scanFactsStats, importMetaRefs, hasModuleState, absolutePathLiterals, lineComments, stripJsonImportAttributes };