@mmapp/react-compiler 0.1.0-alpha.1 → 0.1.0-alpha.4

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 (346) hide show
  1. package/ATOM-PIPELINE.md +144 -0
  2. package/README.md +88 -40
  3. package/dist/auth-3UK75242.mjs +17 -0
  4. package/dist/babel/index.d.mts +2 -2
  5. package/dist/babel/index.d.ts +2 -2
  6. package/dist/babel/index.js +2816 -279
  7. package/dist/babel/index.mjs +2 -2
  8. package/dist/chunk-3USIFFE4.mjs +2190 -0
  9. package/dist/chunk-45YMGEVT.mjs +186 -0
  10. package/dist/chunk-4FN2AISW.mjs +148 -0
  11. package/dist/chunk-4OPI5L7G.mjs +2593 -0
  12. package/dist/chunk-4RYTKOOJ.mjs +186 -0
  13. package/dist/chunk-52XHYD2V.mjs +214 -0
  14. package/dist/chunk-5FTDWKHH.mjs +244 -0
  15. package/dist/chunk-5GUFFFGL.mjs +148 -0
  16. package/dist/chunk-5RKTOVR5.mjs +244 -0
  17. package/dist/chunk-5YDMOO4X.mjs +214 -0
  18. package/dist/chunk-64ZWEMLJ.mjs +148 -0
  19. package/dist/chunk-6XP4KSWQ.mjs +2190 -0
  20. package/dist/chunk-72QWL54I.mjs +175 -0
  21. package/dist/chunk-7B4TRI7C.mjs +4835 -0
  22. package/dist/chunk-7JRAEFRB.mjs +7510 -0
  23. package/dist/chunk-7T6Q5KAA.mjs +7506 -0
  24. package/dist/chunk-7ZKGHTNB.mjs +4952 -0
  25. package/dist/chunk-ABYPKRSB.mjs +215 -0
  26. package/dist/chunk-BZEXUPDH.mjs +175 -0
  27. package/dist/chunk-CIESM3BP.mjs +33 -0
  28. package/dist/chunk-DE3ZGQAC.mjs +148 -0
  29. package/dist/chunk-DMCY3BBG.mjs +1933 -0
  30. package/dist/chunk-DPIK3PJS.mjs +244 -0
  31. package/dist/chunk-E5IVH4RE.mjs +186 -0
  32. package/dist/chunk-E6FZNUR5.mjs +4953 -0
  33. package/dist/chunk-EJRBDQDP.mjs +2607 -0
  34. package/dist/chunk-ELO4TXJL.mjs +186 -0
  35. package/dist/chunk-EO6SYNCG.mjs +175 -0
  36. package/dist/chunk-FKRO52XH.mjs +3446 -0
  37. package/dist/chunk-FL4YAKU6.mjs +4941 -0
  38. package/dist/chunk-FYT47UBU.mjs +5076 -0
  39. package/dist/chunk-GCLGPOJZ.mjs +148 -0
  40. package/dist/chunk-GXB4JOP7.mjs +5072 -0
  41. package/dist/chunk-HFXOUMTD.mjs +175 -0
  42. package/dist/chunk-HRYR54PT.mjs +175 -0
  43. package/dist/chunk-HWIZ47US.mjs +214 -0
  44. package/dist/chunk-IB7MNPQL.mjs +4953 -0
  45. package/dist/chunk-ICSIHQCG.mjs +148 -0
  46. package/dist/chunk-J3M4GUS7.mjs +161 -0
  47. package/dist/chunk-J7JUAHS4.mjs +186 -0
  48. package/dist/chunk-JLA5VNQ3.mjs +186 -0
  49. package/dist/chunk-JQLWFCTM.mjs +214 -0
  50. package/dist/chunk-JRGFBWTN.mjs +2918 -0
  51. package/dist/chunk-KFJJCQAL.mjs +148 -0
  52. package/dist/chunk-KJUIIEQE.mjs +186 -0
  53. package/dist/chunk-KNWTHRVQ.mjs +175 -0
  54. package/dist/chunk-KSG4XSZF.mjs +175 -0
  55. package/dist/chunk-LF5N6DOU.mjs +175 -0
  56. package/dist/chunk-LJQCM2IM.mjs +214 -0
  57. package/dist/chunk-NTB7OEX2.mjs +2918 -0
  58. package/dist/chunk-NW6555WJ.mjs +186 -0
  59. package/dist/chunk-O4AUS7EU.mjs +148 -0
  60. package/dist/chunk-OMZE6VLQ.mjs +214 -0
  61. package/dist/chunk-OPJKP747.mjs +7506 -0
  62. package/dist/chunk-P4BR7WVO.mjs +2190 -0
  63. package/dist/chunk-QQHVYH2X.mjs +244 -0
  64. package/dist/chunk-R2DD5GTY.mjs +186 -0
  65. package/dist/chunk-S5QLWLLT.mjs +186 -0
  66. package/dist/chunk-SCWGT2FY.mjs +2190 -0
  67. package/dist/chunk-SMKJUSB3.mjs +2190 -0
  68. package/dist/chunk-THFYE5ZX.mjs +244 -0
  69. package/dist/chunk-UDDTWG5J.mjs +734 -0
  70. package/dist/chunk-VCAY2KGM.mjs +175 -0
  71. package/dist/chunk-VLTKQDJ3.mjs +244 -0
  72. package/dist/chunk-WBYMW4NQ.mjs +3450 -0
  73. package/dist/chunk-WECAV6QB.mjs +148 -0
  74. package/dist/chunk-WMKBXUCE.mjs +3228 -0
  75. package/dist/chunk-WVYY32LD.mjs +939 -0
  76. package/dist/chunk-XAJ5BKKL.mjs +4947 -0
  77. package/dist/chunk-XDVM4YHX.mjs +3450 -0
  78. package/dist/chunk-XG2X7AEA.mjs +175 -0
  79. package/dist/chunk-XG7Z23NQ.mjs +148 -0
  80. package/dist/chunk-XWZAOCQ7.mjs +2607 -0
  81. package/dist/chunk-Y6MA7ULW.mjs +148 -0
  82. package/dist/chunk-YMS7Q7LG.mjs +214 -0
  83. package/dist/chunk-Z2G5RZ4H.mjs +186 -0
  84. package/dist/chunk-ZA37XTGA.mjs +175 -0
  85. package/dist/chunk-ZE3KCHBM.mjs +2918 -0
  86. package/dist/cli/index.js +14720 -7199
  87. package/dist/cli/index.mjs +224 -183
  88. package/dist/codemod/cli.js +1 -1
  89. package/dist/codemod/cli.mjs +2 -2
  90. package/dist/codemod/index.d.mts +3 -3
  91. package/dist/codemod/index.d.ts +3 -3
  92. package/dist/codemod/index.js +1 -1
  93. package/dist/codemod/index.mjs +2 -2
  94. package/dist/config-PL24KEWL.mjs +219 -0
  95. package/dist/deploy-YAJGW6II.mjs +9 -0
  96. package/dist/dev-server-CrQ041KP.d.mts +79 -0
  97. package/dist/dev-server-CrQ041KP.d.ts +79 -0
  98. package/dist/dev-server-RmGHIntF.d.mts +113 -0
  99. package/dist/dev-server-RmGHIntF.d.ts +113 -0
  100. package/dist/dev-server.d.mts +2 -2
  101. package/dist/dev-server.d.ts +2 -2
  102. package/dist/dev-server.js +6424 -1597
  103. package/dist/dev-server.mjs +5 -5
  104. package/dist/envelope-ChEkuHij.d.mts +265 -0
  105. package/dist/envelope-ChEkuHij.d.ts +265 -0
  106. package/dist/envelope.d.mts +2 -2
  107. package/dist/envelope.d.ts +2 -2
  108. package/dist/envelope.js +2814 -277
  109. package/dist/envelope.mjs +3 -3
  110. package/dist/index-CEKyyazf.d.mts +104 -0
  111. package/dist/index-CEKyyazf.d.ts +104 -0
  112. package/dist/index.d.mts +168 -9
  113. package/dist/index.d.ts +168 -9
  114. package/dist/index.js +5606 -681
  115. package/dist/index.mjs +217 -9
  116. package/dist/init-7FJENUDK.mjs +407 -0
  117. package/{src/cli/init.ts → dist/init-7JQMAAXS.mjs} +70 -95
  118. package/dist/init-DQDX3QK6.mjs +369 -0
  119. package/dist/init-EHO4VQ22.mjs +369 -0
  120. package/dist/init-UC3FWPIW.mjs +367 -0
  121. package/dist/init-UNSMVKIK.mjs +366 -0
  122. package/dist/init-UNV5XIDE.mjs +367 -0
  123. package/dist/project-compiler-2P4N4DR7.mjs +10 -0
  124. package/dist/project-compiler-D2LCC27O.mjs +10 -0
  125. package/dist/project-compiler-EJ3GANJE.mjs +10 -0
  126. package/dist/project-compiler-LOQKVRZJ.mjs +10 -0
  127. package/dist/project-compiler-NNK32MPG.mjs +10 -0
  128. package/dist/project-compiler-OP2VVGJQ.mjs +10 -0
  129. package/dist/project-compiler-RQ6OQKRM.mjs +10 -0
  130. package/dist/project-compiler-VWNNCHGO.mjs +10 -0
  131. package/dist/project-compiler-XVAAU4C5.mjs +10 -0
  132. package/dist/project-compiler-YES5FGMD.mjs +10 -0
  133. package/dist/project-compiler-ZB4RUYVL.mjs +10 -0
  134. package/dist/project-compiler-ZKMQDLGU.mjs +10 -0
  135. package/dist/project-decompiler-FLXCEJHS.mjs +7 -0
  136. package/dist/project-decompiler-U55HQUHW.mjs +7 -0
  137. package/dist/project-decompiler-US7GAVIC.mjs +7 -0
  138. package/dist/project-decompiler-VLPR22QF.mjs +7 -0
  139. package/dist/pull-FUS5QYZS.mjs +109 -0
  140. package/dist/pull-KOL2QAYQ.mjs +109 -0
  141. package/dist/pull-LD5ENLGY.mjs +109 -0
  142. package/dist/pull-P44LDRWB.mjs +109 -0
  143. package/dist/seed-KOGEPGOJ.mjs +154 -0
  144. package/dist/server-VW6UPCHO.mjs +277 -0
  145. package/dist/testing/index.d.mts +8 -8
  146. package/dist/testing/index.d.ts +8 -8
  147. package/dist/testing/index.js +2824 -287
  148. package/dist/testing/index.mjs +2 -2
  149. package/dist/verify-BYHUKARQ.mjs +1833 -0
  150. package/dist/verify-OQDEQYMS.mjs +1833 -0
  151. package/dist/verify-SEIXUGN4.mjs +1833 -0
  152. package/dist/vite/index.d.mts +1 -1
  153. package/dist/vite/index.d.ts +1 -1
  154. package/dist/vite/index.js +2817 -280
  155. package/dist/vite/index.mjs +3 -3
  156. package/examples/authentication/main.workflow.tsx +1 -1
  157. package/examples/authentication/mm.config.ts +1 -1
  158. package/examples/authentication/pages/LoginPage.tsx +2 -2
  159. package/examples/authentication/pages/SignupPage.tsx +2 -2
  160. package/examples/counter.workflow.tsx +1 -1
  161. package/examples/dashboard.workflow.tsx +1 -1
  162. package/examples/invoice-approval/actions/invoice.server.ts +1 -1
  163. package/examples/invoice-approval/main.workflow.tsx +1 -1
  164. package/examples/invoice-approval/mm.config.ts +1 -1
  165. package/examples/invoice-approval/pages/InvoiceDetailPage.tsx +1 -1
  166. package/examples/invoice-approval/pages/InvoiceFormPage.tsx +1 -1
  167. package/examples/invoice-approval/pages/InvoiceListPage.tsx +1 -1
  168. package/examples/todo-app.workflow.tsx +1 -1
  169. package/examples/uber-app/actions/matching.server.ts +1 -1
  170. package/examples/uber-app/actions/notifications.server.ts +1 -1
  171. package/examples/uber-app/actions/payments.server.ts +1 -1
  172. package/examples/uber-app/actions/pricing.server.ts +1 -1
  173. package/examples/uber-app/app/admin/analytics.tsx +2 -2
  174. package/examples/uber-app/app/admin/fleet.tsx +21 -21
  175. package/examples/uber-app/app/admin/surge-pricing.tsx +2 -2
  176. package/examples/uber-app/app/driver/dashboard.tsx +2 -2
  177. package/examples/uber-app/app/driver/earnings.tsx +2 -2
  178. package/examples/uber-app/app/driver/navigation.tsx +2 -2
  179. package/examples/uber-app/app/driver/ride-acceptance.tsx +2 -2
  180. package/examples/uber-app/app/rider/home.tsx +2 -2
  181. package/examples/uber-app/app/rider/payment-methods.tsx +2 -2
  182. package/examples/uber-app/app/rider/ride-history.tsx +2 -2
  183. package/examples/uber-app/app/rider/ride-tracking.tsx +2 -2
  184. package/examples/uber-app/components/DriverCard.tsx +1 -1
  185. package/examples/uber-app/components/MapView.tsx +3 -3
  186. package/examples/uber-app/components/RatingStars.tsx +2 -2
  187. package/examples/uber-app/components/RideCard.tsx +1 -1
  188. package/examples/uber-app/mm.config.ts +1 -1
  189. package/examples/uber-app/workflows/dispute-resolution.workflow.tsx +2 -2
  190. package/examples/uber-app/workflows/driver-onboarding.workflow.tsx +2 -2
  191. package/examples/uber-app/workflows/payment-processing.workflow.tsx +2 -2
  192. package/examples/uber-app/workflows/ride-request.workflow.tsx +2 -2
  193. package/package.json +10 -4
  194. package/compile-blueprint-chat.mjs +0 -99
  195. package/compile-blueprint-glass-console.mjs +0 -98
  196. package/compile-chat-defs.mjs +0 -92
  197. package/examples/uber-app/tests/payment.test.tsx +0 -129
  198. package/examples/uber-app/tests/ride-flow.test.tsx +0 -123
  199. package/package.json.backup +0 -86
  200. package/scripts/decompile.ts +0 -226
  201. package/scripts/seed-auth.ts +0 -267
  202. package/scripts/seed-uber.ts +0 -248
  203. package/scripts/validate-uber.ts +0 -119
  204. package/seed-blueprint-chat.mjs +0 -444
  205. package/seed-blueprint-glass-console.mjs +0 -445
  206. package/seed-compiled.mjs +0 -318
  207. package/src/RoundTripValidator.ts +0 -400
  208. package/src/__tests__/atom-rendering-coverage.test.ts +0 -680
  209. package/src/__tests__/auth-module-compilation.test.ts +0 -247
  210. package/src/__tests__/auth-template-compilation.test.ts +0 -589
  211. package/src/__tests__/change-extractor.test.ts +0 -142
  212. package/src/__tests__/cli-pull.test.ts +0 -73
  213. package/src/__tests__/cli-test.test.ts +0 -72
  214. package/src/__tests__/component-extractor.test.ts +0 -331
  215. package/src/__tests__/context-extractor.test.ts +0 -145
  216. package/src/__tests__/decompiler.test.ts +0 -718
  217. package/src/__tests__/define-blueprint.test.ts +0 -133
  218. package/src/__tests__/definition-validator.test.ts +0 -519
  219. package/src/__tests__/during-extractor.test.ts +0 -152
  220. package/src/__tests__/effect-extractor.test.ts +0 -107
  221. package/src/__tests__/event-emission.test.ts +0 -127
  222. package/src/__tests__/examples.test.ts +0 -236
  223. package/src/__tests__/full-blueprint-coverage.test.ts +0 -1221
  224. package/src/__tests__/golden-suite.test.ts +0 -403
  225. package/src/__tests__/grammar-island-extractor.test.ts +0 -289
  226. package/src/__tests__/instance-key.test.ts +0 -82
  227. package/src/__tests__/ir-migration.test.ts +0 -255
  228. package/src/__tests__/lock-file.test.ts +0 -117
  229. package/src/__tests__/model-extractor.test.ts +0 -195
  230. package/src/__tests__/model-field-acl.test.ts +0 -237
  231. package/src/__tests__/model-hooks.test.ts +0 -130
  232. package/src/__tests__/model-ref-resolution.test.ts +0 -268
  233. package/src/__tests__/model-roundtrip.test.ts +0 -502
  234. package/src/__tests__/model-runtime.test.ts +0 -112
  235. package/src/__tests__/model-transitions.test.ts +0 -183
  236. package/src/__tests__/nrt-action-trace.test.ts +0 -391
  237. package/src/__tests__/pipeline-hardening.test.ts +0 -413
  238. package/src/__tests__/project-compiler.test.ts +0 -546
  239. package/src/__tests__/project-decompiler.test.ts +0 -343
  240. package/src/__tests__/query-compilation.test.ts +0 -145
  241. package/src/__tests__/round-trip/PLAN.md +0 -158
  242. package/src/__tests__/round-trip/README.md +0 -52
  243. package/src/__tests__/round-trip/RESULTS.md +0 -86
  244. package/src/__tests__/round-trip/fixtures/data-heavy/main.workflow.tsx +0 -55
  245. package/src/__tests__/round-trip/fixtures/data-heavy/mm.config.ts +0 -11
  246. package/src/__tests__/round-trip/fixtures/data-heavy/models/contact.ts +0 -54
  247. package/src/__tests__/round-trip/fixtures/full-workflow/main.workflow.tsx +0 -79
  248. package/src/__tests__/round-trip/fixtures/full-workflow/mm.config.ts +0 -12
  249. package/src/__tests__/round-trip/fixtures/full-workflow/models/order.ts +0 -50
  250. package/src/__tests__/round-trip/fixtures/simple-crud/main.workflow.tsx +0 -25
  251. package/src/__tests__/round-trip/fixtures/simple-crud/mm.config.ts +0 -11
  252. package/src/__tests__/round-trip/fixtures/simple-crud/models/task.ts +0 -32
  253. package/src/__tests__/round-trip/fixtures/view-heavy/main.workflow.tsx +0 -79
  254. package/src/__tests__/round-trip/fixtures/view-heavy/mm.config.ts +0 -10
  255. package/src/__tests__/round-trip/round-trip.test.ts +0 -2598
  256. package/src/__tests__/round-trip-ir.test.ts +0 -300
  257. package/src/__tests__/round-trip.test.ts +0 -1212
  258. package/src/__tests__/route-merging.test.ts +0 -372
  259. package/src/__tests__/router-composition.test.ts +0 -489
  260. package/src/__tests__/router-extractor.test.ts +0 -176
  261. package/src/__tests__/server-action-extractor.test.ts +0 -128
  262. package/src/__tests__/smart-type-inference.test.ts +0 -365
  263. package/src/__tests__/source-envelope.test.ts +0 -284
  264. package/src/__tests__/source-fidelity.test.ts +0 -516
  265. package/src/__tests__/state-extractor.test.ts +0 -115
  266. package/src/__tests__/strict-mode.test.ts +0 -227
  267. package/src/__tests__/transition-effect-extractor.test.ts +0 -119
  268. package/src/__tests__/transition-extractor.test.ts +0 -68
  269. package/src/__tests__/ts-to-expression.test.ts +0 -462
  270. package/src/__tests__/type-generator.test.ts +0 -201
  271. package/src/__tests__/uber-validation.test.ts +0 -502
  272. package/src/action-compiler.ts +0 -361
  273. package/src/babel/emitters/experience-transform.ts +0 -199
  274. package/src/babel/emitters/ir-to-tsx-emitter.ts +0 -110
  275. package/src/babel/emitters/pure-form-emitter.ts +0 -1023
  276. package/src/babel/emitters/runtime-glue-emitter.ts +0 -39
  277. package/src/babel/extractors/change-extractor.ts +0 -199
  278. package/src/babel/extractors/component-extractor.ts +0 -907
  279. package/src/babel/extractors/computed-extractor.ts +0 -262
  280. package/src/babel/extractors/context-extractor.ts +0 -277
  281. package/src/babel/extractors/during-extractor.ts +0 -295
  282. package/src/babel/extractors/effect-extractor.ts +0 -340
  283. package/src/babel/extractors/event-extractor.ts +0 -235
  284. package/src/babel/extractors/grammar-island-extractor.ts +0 -302
  285. package/src/babel/extractors/model-extractor.ts +0 -1018
  286. package/src/babel/extractors/router-extractor.ts +0 -303
  287. package/src/babel/extractors/server-action-extractor.ts +0 -173
  288. package/src/babel/extractors/server-action-hook-extractor.ts +0 -72
  289. package/src/babel/extractors/server-state-extractor.ts +0 -88
  290. package/src/babel/extractors/state-extractor.ts +0 -214
  291. package/src/babel/extractors/transition-effect-extractor.ts +0 -176
  292. package/src/babel/extractors/transition-extractor.ts +0 -143
  293. package/src/babel/index.ts +0 -24
  294. package/src/babel/transpilers/ts-to-expression.ts +0 -674
  295. package/src/babel/visitor.ts +0 -807
  296. package/src/cli/auth.ts +0 -255
  297. package/src/cli/build.ts +0 -288
  298. package/src/cli/deploy.ts +0 -206
  299. package/src/cli/index.ts +0 -328
  300. package/src/cli/installer.ts +0 -261
  301. package/src/cli/lock-file.ts +0 -94
  302. package/src/cli/mmrc.ts +0 -22
  303. package/src/cli/pull.ts +0 -172
  304. package/src/cli/registry-client.ts +0 -175
  305. package/src/cli/test.ts +0 -397
  306. package/src/cli/type-generator.ts +0 -243
  307. package/src/codemod/__tests__/forward.test.ts +0 -239
  308. package/src/codemod/__tests__/reverse.test.ts +0 -145
  309. package/src/codemod/__tests__/round-trip.test.ts +0 -137
  310. package/src/codemod/annotation.ts +0 -97
  311. package/src/codemod/classify.ts +0 -197
  312. package/src/codemod/cli.ts +0 -207
  313. package/src/codemod/control-flow.ts +0 -409
  314. package/src/codemod/forward.ts +0 -244
  315. package/src/codemod/import-manager.ts +0 -171
  316. package/src/codemod/index.ts +0 -120
  317. package/src/codemod/reverse.ts +0 -197
  318. package/src/codemod/rules.ts +0 -174
  319. package/src/codemod/state-transform.ts +0 -126
  320. package/src/decompiler/ast-builder.ts +0 -538
  321. package/src/decompiler/config-generator.ts +0 -151
  322. package/src/decompiler/index.ts +0 -315
  323. package/src/decompiler/project-decompiler.ts +0 -1776
  324. package/src/decompiler/project.ts +0 -862
  325. package/src/decompiler/split-strategy.ts +0 -140
  326. package/src/decompiler/state-emitter.ts +0 -1053
  327. package/src/decompiler/sx-emitter.ts +0 -318
  328. package/src/decompiler/workspace-hydrator.ts +0 -189
  329. package/src/dev-server.ts +0 -238
  330. package/src/envelope/fs-tree.ts +0 -217
  331. package/src/envelope/source-envelope.ts +0 -264
  332. package/src/envelope.ts +0 -315
  333. package/src/incremental-compiler.ts +0 -401
  334. package/src/index.ts +0 -99
  335. package/src/model-compiler.ts +0 -277
  336. package/src/project-compiler.ts +0 -1629
  337. package/src/route-extractor.ts +0 -333
  338. package/src/testing/index.ts +0 -32
  339. package/src/testing/snapshot.ts +0 -252
  340. package/src/testing/test-utils.ts +0 -226
  341. package/src/types.ts +0 -68
  342. package/src/vite/index.ts +0 -288
  343. package/test-compile.mjs +0 -142
  344. package/tsconfig.json +0 -25
  345. package/tsup.config.ts +0 -23
  346. package/vitest.config.ts +0 -9
@@ -0,0 +1,939 @@
1
+ // src/codemod/index.ts
2
+ import { transformSync } from "@babel/core";
3
+ import { declare } from "@babel/helper-plugin-utils";
4
+
5
+ // src/codemod/forward.ts
6
+ import * as t2 from "@babel/types";
7
+
8
+ // src/codemod/rules.ts
9
+ var FORWARD_RULES = [
10
+ // div with flex-col → Stack
11
+ {
12
+ htmlTag: "div",
13
+ atom: "Stack",
14
+ classSignal: ["flex-col"],
15
+ implicitClasses: ["flex", "flex-col"],
16
+ priority: 20
17
+ },
18
+ // div with grid → Grid
19
+ {
20
+ htmlTag: "div",
21
+ atom: "Grid",
22
+ classSignal: ["grid"],
23
+ implicitClasses: ["grid"],
24
+ priority: 20
25
+ },
26
+ // div with flex (no flex-col) → Row
27
+ {
28
+ htmlTag: "div",
29
+ atom: "Row",
30
+ classSignal: ["flex"],
31
+ implicitClasses: ["flex"],
32
+ priority: 10
33
+ },
34
+ // div with no layout signal → Stack (default container)
35
+ {
36
+ htmlTag: "div",
37
+ atom: "Stack",
38
+ classSignal: [],
39
+ implicitClasses: [],
40
+ priority: 0
41
+ },
42
+ // Semantic HTML
43
+ { htmlTag: "main", atom: "Stack", implicitClasses: [] },
44
+ { htmlTag: "aside", atom: "Stack", implicitClasses: [] },
45
+ { htmlTag: "nav", atom: "Stack", implicitClasses: [] },
46
+ { htmlTag: "section", atom: "Section", implicitClasses: [] },
47
+ { htmlTag: "header", atom: "Row", implicitClasses: [] },
48
+ { htmlTag: "footer", atom: "Row", implicitClasses: [] },
49
+ // Text elements
50
+ { htmlTag: "span", atom: "Text", implicitClasses: [] },
51
+ { htmlTag: "p", atom: "Text", implicitClasses: [] },
52
+ { htmlTag: "label", atom: "Text", implicitClasses: [] },
53
+ { htmlTag: "h1", atom: "Text", implicitClasses: [], props: { variant: "h1" } },
54
+ { htmlTag: "h2", atom: "Text", implicitClasses: [], props: { variant: "h2" } },
55
+ { htmlTag: "h3", atom: "Text", implicitClasses: [], props: { variant: "h3" } },
56
+ { htmlTag: "h4", atom: "Text", implicitClasses: [], props: { variant: "h4" } },
57
+ { htmlTag: "h5", atom: "Text", implicitClasses: [], props: { variant: "h5" } },
58
+ { htmlTag: "h6", atom: "Text", implicitClasses: [], props: { variant: "h6" } },
59
+ // Interactive elements
60
+ { htmlTag: "button", atom: "Button", implicitClasses: [] },
61
+ { htmlTag: "a", atom: "Link", implicitClasses: [] },
62
+ // Form elements
63
+ { htmlTag: "input", atom: "TextInput", implicitClasses: [] },
64
+ {
65
+ htmlTag: "textarea",
66
+ atom: "TextInput",
67
+ implicitClasses: [],
68
+ props: { multiline: true }
69
+ },
70
+ // Media
71
+ { htmlTag: "img", atom: "Image", implicitClasses: [] }
72
+ ];
73
+ var REVERSE_RULES = [
74
+ { atom: "Stack", htmlTag: "div", injectClasses: ["flex", "flex-col"] },
75
+ { atom: "Row", htmlTag: "div", injectClasses: ["flex"] },
76
+ { atom: "Grid", htmlTag: "div", injectClasses: ["grid"] },
77
+ { atom: "Text", htmlTag: "span" },
78
+ { atom: "Button", htmlTag: "button" },
79
+ { atom: "Link", htmlTag: "a" },
80
+ { atom: "TextInput", htmlTag: "input" },
81
+ { atom: "Image", htmlTag: "img" },
82
+ { atom: "Section", htmlTag: "section" }
83
+ ];
84
+ var CONTROL_FLOW_ATOMS = /* @__PURE__ */ new Set([
85
+ "Show",
86
+ "Each",
87
+ "Modal",
88
+ "Slot",
89
+ "Divider"
90
+ ]);
91
+ var ATOM_IMPORT_SOURCE = "@mmapp/react/atoms";
92
+ var TEXT_VARIANT_TO_TAG = {
93
+ h1: "h1",
94
+ h2: "h2",
95
+ h3: "h3",
96
+ h4: "h4",
97
+ h5: "h5",
98
+ h6: "h6"
99
+ };
100
+
101
+ // src/codemod/classify.ts
102
+ function extractStaticClasses(attrValue) {
103
+ if (!attrValue) return [];
104
+ if (attrValue.type === "StringLiteral") {
105
+ return attrValue.value.split(/\s+/).filter(Boolean);
106
+ }
107
+ if (attrValue.type === "JSXExpressionContainer") {
108
+ return extractStaticClasses(attrValue.expression);
109
+ }
110
+ if (attrValue.type === "TemplateLiteral") {
111
+ const staticParts = attrValue.quasis.map((q) => q.value.raw).join(" ");
112
+ return staticParts.split(/\s+/).filter(Boolean);
113
+ }
114
+ if (attrValue.type === "CallExpression" && attrValue.callee.type === "Identifier" && attrValue.callee.name === "cn" && attrValue.arguments.length > 0) {
115
+ const firstArg = attrValue.arguments[0];
116
+ if (firstArg.type === "StringLiteral") {
117
+ return firstArg.value.split(/\s+/).filter(Boolean);
118
+ }
119
+ }
120
+ return [];
121
+ }
122
+ function classifyElement(tagName, classNames) {
123
+ if (tagName[0] === tagName[0].toUpperCase() && tagName[0] !== tagName[0].toLowerCase()) {
124
+ return null;
125
+ }
126
+ if (tagName.startsWith("motion.")) {
127
+ return null;
128
+ }
129
+ const candidates = FORWARD_RULES.filter((r) => r.htmlTag === tagName).sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
130
+ if (candidates.length === 0) return null;
131
+ if (tagName === "div") {
132
+ for (const rule2 of candidates) {
133
+ if (!rule2.classSignal || rule2.classSignal.length === 0) {
134
+ continue;
135
+ }
136
+ const hasAllSignals = rule2.classSignal.every((s) => classNames.includes(s));
137
+ if (hasAllSignals) {
138
+ return makeResult(rule2, tagName);
139
+ }
140
+ }
141
+ const defaultRule = candidates.find((r) => (r.priority ?? 0) === 0);
142
+ if (defaultRule) {
143
+ return makeResult(defaultRule, tagName);
144
+ }
145
+ }
146
+ const rule = candidates[0];
147
+ return makeResult(rule, tagName);
148
+ }
149
+ function makeResult(rule, tagName) {
150
+ return {
151
+ atom: rule.atom,
152
+ removeClasses: rule.implicitClasses ?? [],
153
+ addProps: rule.props ?? {},
154
+ originalTag: tagName
155
+ };
156
+ }
157
+ function reverseClassifyAtom(atomName, props) {
158
+ if (CONTROL_FLOW_ATOMS.has(atomName)) return null;
159
+ if (atomName === "Text") {
160
+ const variantNode = props.get("variant");
161
+ if (variantNode && variantNode.type === "StringLiteral") {
162
+ const tag = TEXT_VARIANT_TO_TAG[variantNode.value];
163
+ if (tag) {
164
+ return {
165
+ htmlTag: tag,
166
+ injectClasses: [],
167
+ removeProps: ["variant"]
168
+ };
169
+ }
170
+ }
171
+ return { htmlTag: "span", injectClasses: [], removeProps: [] };
172
+ }
173
+ if (atomName === "TextInput") {
174
+ const multilineNode = props.get("multiline");
175
+ if (multilineNode) {
176
+ const isMultiline = multilineNode.type === "BooleanLiteral" && multilineNode.value || multilineNode.type === "JSXExpressionContainer" && multilineNode.expression?.type === "BooleanLiteral" && multilineNode.expression?.value;
177
+ if (isMultiline) {
178
+ return { htmlTag: "textarea", injectClasses: [], removeProps: ["multiline"] };
179
+ }
180
+ }
181
+ return { htmlTag: "input", injectClasses: [], removeProps: [] };
182
+ }
183
+ const rule = REVERSE_RULES.find((r) => r.atom === atomName);
184
+ if (!rule) return null;
185
+ return {
186
+ htmlTag: rule.htmlTag,
187
+ injectClasses: rule.injectClasses ?? [],
188
+ removeProps: rule.removeProps ?? []
189
+ };
190
+ }
191
+ function removeClassesFromString(className, toRemove) {
192
+ if (toRemove.length === 0) return className;
193
+ const removeSet = new Set(toRemove);
194
+ return className.split(/\s+/).filter((c) => c && !removeSet.has(c)).join(" ");
195
+ }
196
+ function addClassesToString(className, toAdd) {
197
+ if (toAdd.length === 0) return className;
198
+ const existing = new Set(className.split(/\s+/).filter(Boolean));
199
+ const newClasses = toAdd.filter((c) => !existing.has(c));
200
+ if (newClasses.length === 0) return className;
201
+ return [...newClasses, ...className.split(/\s+/).filter(Boolean)].join(" ");
202
+ }
203
+
204
+ // src/codemod/control-flow.ts
205
+ import * as t from "@babel/types";
206
+ function matchConditionalRender(expr) {
207
+ if (expr.type !== "LogicalExpression" || expr.operator !== "&&") return null;
208
+ if (!isJSXLike(expr.right)) return null;
209
+ return { condition: expr.left, consequent: expr.right };
210
+ }
211
+ function matchTernaryRender(expr) {
212
+ if (expr.type !== "ConditionalExpression") return null;
213
+ if (!isJSXLike(expr.consequent) && !isJSXLike(expr.alternate)) return null;
214
+ return {
215
+ condition: expr.test,
216
+ consequent: expr.consequent,
217
+ alternate: expr.alternate
218
+ };
219
+ }
220
+ function matchMapRender(expr) {
221
+ if (expr.type !== "CallExpression") return null;
222
+ if (expr.callee.type !== "MemberExpression") return null;
223
+ const prop = expr.callee.property;
224
+ if (!(prop.type === "Identifier" && prop.name === "map")) return null;
225
+ const array = expr.callee.object;
226
+ const callback = expr.arguments[0];
227
+ if (!callback) return null;
228
+ if (callback.type !== "ArrowFunctionExpression" && callback.type !== "FunctionExpression")
229
+ return null;
230
+ const param = callback.params[0] || t.identifier("item");
231
+ const indexParam = callback.params[1] && callback.params[1].type === "Identifier" ? callback.params[1] : null;
232
+ let keyExpression = null;
233
+ const returnedJSX = getReturnedJSX(callback.body);
234
+ if (returnedJSX && returnedJSX.type === "JSXElement") {
235
+ const keyAttr = returnedJSX.openingElement.attributes.find(
236
+ (a) => a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && a.name.name === "key"
237
+ );
238
+ if (keyAttr && keyAttr.value) {
239
+ if (keyAttr.value.type === "JSXExpressionContainer") {
240
+ keyExpression = keyAttr.value.expression;
241
+ } else if (keyAttr.value.type === "StringLiteral") {
242
+ keyExpression = keyAttr.value;
243
+ }
244
+ }
245
+ }
246
+ return {
247
+ array,
248
+ param,
249
+ indexParam,
250
+ body: callback.body,
251
+ keyExpression
252
+ };
253
+ }
254
+ function createShowElement(condition, children) {
255
+ const whenAttr = t.jsxAttribute(
256
+ t.jsxIdentifier("when"),
257
+ t.jsxExpressionContainer(condition)
258
+ );
259
+ const childNodes = [];
260
+ if (t.isJSXElement(children) || t.isJSXFragment(children)) {
261
+ childNodes.push(children);
262
+ } else {
263
+ childNodes.push(t.jsxExpressionContainer(children));
264
+ }
265
+ return t.jsxElement(
266
+ t.jsxOpeningElement(t.jsxIdentifier("Show"), [whenAttr]),
267
+ t.jsxClosingElement(t.jsxIdentifier("Show")),
268
+ childNodes,
269
+ false
270
+ );
271
+ }
272
+ function createEachElement(items, paramName, body, keyExpression, indexParam) {
273
+ const attrs = [
274
+ t.jsxAttribute(
275
+ t.jsxIdentifier("items"),
276
+ t.jsxExpressionContainer(items)
277
+ ),
278
+ t.jsxAttribute(t.jsxIdentifier("as"), t.stringLiteral(paramName))
279
+ ];
280
+ if (keyExpression) {
281
+ attrs.push(
282
+ t.jsxAttribute(
283
+ t.jsxIdentifier("keyField"),
284
+ t.jsxExpressionContainer(keyExpression)
285
+ )
286
+ );
287
+ }
288
+ const params = [t.identifier(paramName)];
289
+ if (indexParam) params.push(indexParam);
290
+ const arrow = t.arrowFunctionExpression(params, body);
291
+ const child = t.jsxExpressionContainer(arrow);
292
+ removeKeyFromBody(body);
293
+ return t.jsxElement(
294
+ t.jsxOpeningElement(t.jsxIdentifier("Each"), attrs),
295
+ t.jsxClosingElement(t.jsxIdentifier("Each")),
296
+ [child],
297
+ false
298
+ );
299
+ }
300
+ function matchShowElement(node) {
301
+ const tag = node.openingElement.name;
302
+ if (tag.type !== "JSXIdentifier" || tag.name !== "Show") return null;
303
+ const whenAttr = node.openingElement.attributes.find(
304
+ (a) => a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && a.name.name === "when"
305
+ );
306
+ if (!whenAttr || !whenAttr.value) return null;
307
+ let condition;
308
+ if (whenAttr.value.type === "JSXExpressionContainer") {
309
+ condition = whenAttr.value.expression;
310
+ } else if (whenAttr.value.type === "StringLiteral") {
311
+ condition = whenAttr.value;
312
+ } else {
313
+ return null;
314
+ }
315
+ return { condition, children: node.children };
316
+ }
317
+ function matchEachElement(node) {
318
+ const tag = node.openingElement.name;
319
+ if (tag.type !== "JSXIdentifier" || tag.name !== "Each") return null;
320
+ const itemsAttr = node.openingElement.attributes.find(
321
+ (a) => a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && a.name.name === "items"
322
+ );
323
+ if (!itemsAttr?.value) return null;
324
+ const asAttr = node.openingElement.attributes.find(
325
+ (a) => a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && a.name.name === "as"
326
+ );
327
+ const keyAttr = node.openingElement.attributes.find(
328
+ (a) => a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && a.name.name === "keyField"
329
+ );
330
+ let items;
331
+ if (itemsAttr.value.type === "JSXExpressionContainer") {
332
+ items = itemsAttr.value.expression;
333
+ } else {
334
+ return null;
335
+ }
336
+ const paramName = asAttr?.value?.type === "StringLiteral" ? asAttr.value.value : "item";
337
+ let keyExpression = null;
338
+ if (keyAttr?.value?.type === "JSXExpressionContainer") {
339
+ keyExpression = keyAttr.value.expression;
340
+ }
341
+ return { items, paramName, keyExpression, children: node.children };
342
+ }
343
+ function showToConditional(condition, children) {
344
+ const content = unwrapChildren(children);
345
+ const logical = t.logicalExpression("&&", condition, content);
346
+ return t.jsxExpressionContainer(logical);
347
+ }
348
+ function eachToMap(items, paramName, keyExpression, children) {
349
+ let callback = null;
350
+ for (const child of children) {
351
+ if (child.type === "JSXExpressionContainer" && child.expression.type !== "JSXEmptyExpression") {
352
+ const expr = child.expression;
353
+ if (expr.type === "ArrowFunctionExpression" || expr.type === "FunctionExpression") {
354
+ callback = expr;
355
+ break;
356
+ }
357
+ }
358
+ }
359
+ if (!callback) {
360
+ const content = unwrapChildren(children);
361
+ callback = t.arrowFunctionExpression([t.identifier(paramName)], content);
362
+ }
363
+ if (keyExpression) {
364
+ addKeyToCallback(callback, keyExpression);
365
+ }
366
+ const mapCall = t.callExpression(
367
+ t.memberExpression(items, t.identifier("map")),
368
+ [callback]
369
+ );
370
+ return t.jsxExpressionContainer(mapCall);
371
+ }
372
+ function isJSXLike(node) {
373
+ return node.type === "JSXElement" || node.type === "JSXFragment" || node.type === "ParenthesizedExpression" && isJSXLike(node.expression);
374
+ }
375
+ function getReturnedJSX(body) {
376
+ if (body.type === "JSXElement" || body.type === "JSXFragment") return body;
377
+ if (body.type === "ParenthesizedExpression") {
378
+ return getReturnedJSX(body.expression);
379
+ }
380
+ if (body.type === "BlockStatement") {
381
+ for (const stmt of body.body) {
382
+ if (stmt.type === "ReturnStatement" && stmt.argument) {
383
+ if (stmt.argument.type === "JSXElement" || stmt.argument.type === "JSXFragment") {
384
+ return stmt.argument;
385
+ }
386
+ if (stmt.argument.type === "ParenthesizedExpression") {
387
+ return getReturnedJSX(stmt.argument.expression);
388
+ }
389
+ }
390
+ }
391
+ }
392
+ return null;
393
+ }
394
+ function removeKeyFromBody(body) {
395
+ const jsx = getReturnedJSX(body);
396
+ if (jsx && jsx.type === "JSXElement") {
397
+ jsx.openingElement.attributes = jsx.openingElement.attributes.filter(
398
+ (a) => !(a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && a.name.name === "key")
399
+ );
400
+ }
401
+ }
402
+ function addKeyToCallback(callback, keyExpr) {
403
+ const jsx = getReturnedJSX(callback.body);
404
+ if (jsx && jsx.type === "JSXElement") {
405
+ const hasKey = jsx.openingElement.attributes.some(
406
+ (a) => a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && a.name.name === "key"
407
+ );
408
+ if (!hasKey) {
409
+ jsx.openingElement.attributes.unshift(
410
+ t.jsxAttribute(
411
+ t.jsxIdentifier("key"),
412
+ t.jsxExpressionContainer(keyExpr)
413
+ )
414
+ );
415
+ }
416
+ }
417
+ }
418
+ function unwrapChildren(children) {
419
+ const meaningful = children.filter((c) => {
420
+ if (c.type === "JSXText") return c.value.trim().length > 0;
421
+ return true;
422
+ });
423
+ if (meaningful.length === 1) {
424
+ const child = meaningful[0];
425
+ if (child.type === "JSXElement" || child.type === "JSXFragment") return child;
426
+ if (child.type === "JSXExpressionContainer") {
427
+ return child.expression;
428
+ }
429
+ }
430
+ return t.jsxFragment(t.jsxOpeningFragment(), t.jsxClosingFragment(), meaningful);
431
+ }
432
+
433
+ // src/codemod/annotation.ts
434
+ var ANNOTATION_PREFIX = "@mm-original";
435
+ function createAnnotation(originalTag, classNames) {
436
+ const parts = [originalTag, ...classNames.slice(0, 10)];
437
+ return `${ANNOTATION_PREFIX} ${parts.join(".")}`;
438
+ }
439
+ function parseAnnotation(comment) {
440
+ const trimmed = comment.trim();
441
+ if (!trimmed.startsWith(ANNOTATION_PREFIX)) return null;
442
+ const rest = trimmed.slice(ANNOTATION_PREFIX.length).trim();
443
+ if (!rest) return null;
444
+ const parts = rest.split(".");
445
+ const tag = parts[0];
446
+ const classes = parts.slice(1);
447
+ return { tag, classes };
448
+ }
449
+ function addAnnotationComment(node, originalTag, classNames) {
450
+ const text = ` ${createAnnotation(originalTag, classNames)} `;
451
+ if (!node.leadingComments) {
452
+ node.leadingComments = [];
453
+ }
454
+ node.leadingComments.push({
455
+ type: "CommentBlock",
456
+ value: text
457
+ });
458
+ }
459
+ function readAnnotationComment(node) {
460
+ if (!node.leadingComments) return null;
461
+ for (let i = node.leadingComments.length - 1; i >= 0; i--) {
462
+ const comment = node.leadingComments[i];
463
+ const parsed = parseAnnotation(comment.value);
464
+ if (parsed) {
465
+ node.leadingComments.splice(i, 1);
466
+ return parsed;
467
+ }
468
+ }
469
+ return null;
470
+ }
471
+
472
+ // src/codemod/forward.ts
473
+ function createForwardVisitor(imports, options = {}) {
474
+ const { annotate = true } = options;
475
+ return {
476
+ JSXElement(path) {
477
+ const opening = path.node.openingElement;
478
+ const tag = opening.name;
479
+ if (tag.type !== "JSXIdentifier") return;
480
+ const tagName = tag.name;
481
+ const classAttr = opening.attributes.find(
482
+ (a) => a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && a.name.name === "className"
483
+ );
484
+ const staticClasses = extractStaticClasses(classAttr?.value ?? null);
485
+ const result = classifyElement(tagName, staticClasses);
486
+ if (!result) return;
487
+ if (annotate) {
488
+ addAnnotationComment(path.node, result.originalTag, staticClasses);
489
+ }
490
+ tag.name = result.atom;
491
+ if (path.node.closingElement) {
492
+ path.node.closingElement.name.name = result.atom;
493
+ }
494
+ imports.addAtom(result.atom);
495
+ if (classAttr && result.removeClasses.length > 0) {
496
+ updateClassName(classAttr, result.removeClasses, "remove");
497
+ }
498
+ for (const [key, value] of Object.entries(result.addProps)) {
499
+ const existing = opening.attributes.find(
500
+ (a) => a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && a.name.name === key
501
+ );
502
+ if (!existing) {
503
+ if (typeof value === "boolean") {
504
+ opening.attributes.push(
505
+ t2.jsxAttribute(
506
+ t2.jsxIdentifier(key),
507
+ value ? null : t2.jsxExpressionContainer(t2.booleanLiteral(false))
508
+ )
509
+ );
510
+ } else {
511
+ opening.attributes.push(
512
+ t2.jsxAttribute(t2.jsxIdentifier(key), t2.stringLiteral(value))
513
+ );
514
+ }
515
+ }
516
+ }
517
+ renameEventHandlers(opening, "forward");
518
+ },
519
+ JSXExpressionContainer(path) {
520
+ if (!path.parentPath.isJSXElement() && !path.parentPath.isJSXFragment()) return;
521
+ const expr = path.node.expression;
522
+ if (expr.type === "JSXEmptyExpression") return;
523
+ const conditional = matchConditionalRender(expr);
524
+ if (conditional) {
525
+ const showEl = createShowElement(conditional.condition, conditional.consequent);
526
+ imports.addAtom("Show");
527
+ path.replaceWith(showEl);
528
+ return;
529
+ }
530
+ const ternary = matchTernaryRender(expr);
531
+ if (ternary) {
532
+ const show1 = createShowElement(ternary.condition, ternary.consequent);
533
+ const negated = t2.unaryExpression("!", ternary.condition);
534
+ const show2 = createShowElement(negated, ternary.alternate);
535
+ imports.addAtom("Show");
536
+ path.replaceWithMultiple([show1, show2]);
537
+ return;
538
+ }
539
+ const mapRender = matchMapRender(expr);
540
+ if (mapRender) {
541
+ const paramName = mapRender.param.type === "Identifier" ? mapRender.param.name : "item";
542
+ const eachEl = createEachElement(
543
+ mapRender.array,
544
+ paramName,
545
+ mapRender.body,
546
+ mapRender.keyExpression,
547
+ mapRender.indexParam
548
+ );
549
+ imports.addAtom("Each");
550
+ path.replaceWith(eachEl);
551
+ return;
552
+ }
553
+ }
554
+ };
555
+ }
556
+ function updateClassName(attr, classes, operation) {
557
+ if (!attr.value) return;
558
+ if (attr.value.type === "StringLiteral") {
559
+ const result = operation === "remove" ? removeClassesFromString(attr.value.value, classes) : attr.value.value;
560
+ if (result.trim()) {
561
+ attr.value = t2.stringLiteral(result);
562
+ } else {
563
+ attr.value = t2.stringLiteral("");
564
+ }
565
+ return;
566
+ }
567
+ if (attr.value.type === "JSXExpressionContainer") {
568
+ const expr = attr.value.expression;
569
+ if (expr.type === "TemplateLiteral") {
570
+ for (const quasi of expr.quasis) {
571
+ if (operation === "remove") {
572
+ quasi.value.raw = removeClassesFromString(quasi.value.raw, classes);
573
+ quasi.value.cooked = removeClassesFromString(quasi.value.cooked ?? quasi.value.raw, classes);
574
+ }
575
+ }
576
+ return;
577
+ }
578
+ if (expr.type === "CallExpression" && expr.callee.type === "Identifier" && expr.callee.name === "cn" && expr.arguments.length > 0) {
579
+ const firstArg = expr.arguments[0];
580
+ if (firstArg.type === "StringLiteral" && operation === "remove") {
581
+ firstArg.value = removeClassesFromString(firstArg.value, classes);
582
+ }
583
+ return;
584
+ }
585
+ }
586
+ }
587
+ function renameEventHandlers(opening, direction) {
588
+ const map = direction === "forward" ? { onClick: "onPress", onChange: "onChange", onSubmit: "onSubmit" } : { onPress: "onClick" };
589
+ for (const attr of opening.attributes) {
590
+ if (attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier" && attr.name.name in map) {
591
+ attr.name.name = map[attr.name.name];
592
+ }
593
+ }
594
+ }
595
+
596
+ // src/codemod/reverse.ts
597
+ import * as t3 from "@babel/types";
598
+ function createReverseVisitor(imports, _options = {}) {
599
+ return {
600
+ JSXElement: {
601
+ // Use exit so children are processed first (bottom-up)
602
+ exit(path) {
603
+ const opening = path.node.openingElement;
604
+ const tag = opening.name;
605
+ if (tag.type !== "JSXIdentifier") return;
606
+ const atomName = tag.name;
607
+ const showMatch = matchShowElement(path.node);
608
+ if (showMatch) {
609
+ const replacement = showToConditional(showMatch.condition, showMatch.children);
610
+ imports.removeAtom("Show");
611
+ path.replaceWith(replacement);
612
+ return;
613
+ }
614
+ const eachMatch = matchEachElement(path.node);
615
+ if (eachMatch) {
616
+ const replacement = eachToMap(
617
+ eachMatch.items,
618
+ eachMatch.paramName,
619
+ eachMatch.keyExpression,
620
+ eachMatch.children
621
+ );
622
+ imports.removeAtom("Each");
623
+ path.replaceWith(replacement);
624
+ return;
625
+ }
626
+ const annotation = readAnnotationComment(path.node);
627
+ const propsMap = /* @__PURE__ */ new Map();
628
+ for (const attr of opening.attributes) {
629
+ if (attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier") {
630
+ propsMap.set(attr.name.name, attr.value ?? t3.booleanLiteral(true));
631
+ }
632
+ }
633
+ const result = reverseClassifyAtom(atomName, propsMap);
634
+ if (!result) return;
635
+ const targetTag = annotation?.tag ?? result.htmlTag;
636
+ tag.name = targetTag;
637
+ if (path.node.closingElement) {
638
+ path.node.closingElement.name.name = targetTag;
639
+ }
640
+ imports.removeAtom(atomName);
641
+ if (result.removeProps.length > 0) {
642
+ opening.attributes = opening.attributes.filter(
643
+ (attr) => !(attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier" && result.removeProps.includes(attr.name.name))
644
+ );
645
+ }
646
+ if (result.injectClasses.length > 0) {
647
+ injectClasses(opening, result.injectClasses, annotation?.classes);
648
+ }
649
+ renameEventHandlers2(opening);
650
+ }
651
+ }
652
+ };
653
+ }
654
+ function injectClasses(opening, injectClasses2, _annotationClasses) {
655
+ const classAttr = opening.attributes.find(
656
+ (a) => a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && a.name.name === "className"
657
+ );
658
+ if (classAttr && classAttr.value) {
659
+ if (classAttr.value.type === "StringLiteral") {
660
+ classAttr.value = t3.stringLiteral(
661
+ addClassesToString(classAttr.value.value, injectClasses2)
662
+ );
663
+ return;
664
+ }
665
+ if (classAttr.value.type === "JSXExpressionContainer") {
666
+ const expr = classAttr.value.expression;
667
+ if (expr.type === "TemplateLiteral" && expr.quasis.length > 0) {
668
+ const first = expr.quasis[0];
669
+ first.value.raw = addClassesToString(first.value.raw, injectClasses2);
670
+ first.value.cooked = addClassesToString(first.value.cooked ?? first.value.raw, injectClasses2);
671
+ return;
672
+ }
673
+ if (expr.type === "CallExpression" && expr.callee.type === "Identifier" && expr.callee.name === "cn" && expr.arguments.length > 0 && expr.arguments[0].type === "StringLiteral") {
674
+ expr.arguments[0] = t3.stringLiteral(
675
+ addClassesToString(expr.arguments[0].value, injectClasses2)
676
+ );
677
+ return;
678
+ }
679
+ }
680
+ } else {
681
+ const classValue = injectClasses2.join(" ");
682
+ if (classValue) {
683
+ opening.attributes.push(
684
+ t3.jsxAttribute(
685
+ t3.jsxIdentifier("className"),
686
+ t3.stringLiteral(classValue)
687
+ )
688
+ );
689
+ }
690
+ }
691
+ }
692
+ function renameEventHandlers2(opening) {
693
+ const map = { onPress: "onClick" };
694
+ for (const attr of opening.attributes) {
695
+ if (attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier" && attr.name.name in map) {
696
+ attr.name.name = map[attr.name.name];
697
+ }
698
+ }
699
+ }
700
+
701
+ // src/codemod/state-transform.ts
702
+ import * as t4 from "@babel/types";
703
+ function createStateVisitor(mode) {
704
+ if (mode === "preserve") return {};
705
+ if (mode === "annotate") {
706
+ return {
707
+ VariableDeclaration(path) {
708
+ for (const decl of path.node.declarations) {
709
+ if (!isUseStateCall(decl.init)) continue;
710
+ if (hasFieldAnnotation(path.node)) continue;
711
+ const fieldType = inferFieldType(decl.init);
712
+ const comment = ` @mm-field type=${fieldType} `;
713
+ if (!path.node.trailingComments) {
714
+ path.node.trailingComments = [];
715
+ }
716
+ path.node.trailingComments.push({
717
+ type: "CommentLine",
718
+ value: comment
719
+ });
720
+ }
721
+ }
722
+ };
723
+ }
724
+ return {
725
+ VariableDeclaration(path) {
726
+ for (const decl of path.node.declarations) {
727
+ if (!isUseStateCall(decl.init)) continue;
728
+ const migrateAnnotation = getMigrateAnnotation(path.node);
729
+ if (!migrateAnnotation) continue;
730
+ if (migrateAnnotation.type === "query") {
731
+ if (decl.id.type !== "ArrayPattern" || decl.id.elements.length < 1)
732
+ continue;
733
+ const nameNode = decl.id.elements[0];
734
+ if (!nameNode || nameNode.type !== "Identifier") continue;
735
+ decl.id = nameNode;
736
+ decl.init = t4.callExpression(t4.identifier("useQuery"), [
737
+ t4.stringLiteral(migrateAnnotation.model || nameNode.name),
738
+ t4.objectExpression([
739
+ t4.objectProperty(
740
+ t4.identifier("where"),
741
+ t4.objectExpression([])
742
+ )
743
+ ])
744
+ ]);
745
+ }
746
+ }
747
+ }
748
+ };
749
+ }
750
+ function isUseStateCall(node) {
751
+ return !!node && node.type === "CallExpression" && node.callee.type === "Identifier" && node.callee.name === "useState";
752
+ }
753
+ function hasFieldAnnotation(node) {
754
+ return !!node.trailingComments && node.trailingComments.some((c) => c.value.includes("@mm-field"));
755
+ }
756
+ function inferFieldType(call) {
757
+ if (call.arguments.length === 0) return "any";
758
+ const arg = call.arguments[0];
759
+ if (arg.type === "StringLiteral") return "text";
760
+ if (arg.type === "NumericLiteral") return "number";
761
+ if (arg.type === "BooleanLiteral") return "boolean";
762
+ if (arg.type === "ArrayExpression") return "list";
763
+ if (arg.type === "ObjectExpression") return "object";
764
+ if (arg.type === "NullLiteral") return "any";
765
+ return "any";
766
+ }
767
+ function getMigrateAnnotation(node) {
768
+ const comments = [
769
+ ...node.leadingComments || [],
770
+ ...node.trailingComments || []
771
+ ];
772
+ for (const c of comments) {
773
+ const match = c.value.match(/@mm-migrate:\s*(query|mutation)(?:\s+(\w+))?/);
774
+ if (match) {
775
+ return {
776
+ type: match[1],
777
+ model: match[2]
778
+ };
779
+ }
780
+ }
781
+ return null;
782
+ }
783
+
784
+ // src/codemod/import-manager.ts
785
+ import * as t5 from "@babel/types";
786
+ function createImportTracker() {
787
+ const used = /* @__PURE__ */ new Set();
788
+ const removed = /* @__PURE__ */ new Set();
789
+ return {
790
+ addAtom(name) {
791
+ used.add(name);
792
+ removed.delete(name);
793
+ },
794
+ removeAtom(name) {
795
+ removed.add(name);
796
+ },
797
+ getUsedAtoms() {
798
+ return used;
799
+ },
800
+ getRemovedAtoms() {
801
+ return removed;
802
+ }
803
+ };
804
+ }
805
+ function rewriteImportsForward(programPath, tracker) {
806
+ const usedAtoms = tracker.getUsedAtoms();
807
+ if (usedAtoms.size === 0) return;
808
+ let existingImport = null;
809
+ programPath.traverse({
810
+ ImportDeclaration(path) {
811
+ if (path.node.source.value === ATOM_IMPORT_SOURCE) {
812
+ existingImport = path;
813
+ }
814
+ }
815
+ });
816
+ if (existingImport) {
817
+ const existing = new Set(
818
+ existingImport.node.specifiers.filter((s) => s.type === "ImportSpecifier").map((s) => s.imported.name)
819
+ );
820
+ for (const atom of usedAtoms) {
821
+ if (!existing.has(atom)) {
822
+ existingImport.node.specifiers.push(
823
+ t5.importSpecifier(t5.identifier(atom), t5.identifier(atom))
824
+ );
825
+ }
826
+ }
827
+ } else {
828
+ const specifiers = Array.from(usedAtoms).sort().map((name) => t5.importSpecifier(t5.identifier(name), t5.identifier(name)));
829
+ const importDecl = t5.importDeclaration(
830
+ specifiers,
831
+ t5.stringLiteral(ATOM_IMPORT_SOURCE)
832
+ );
833
+ const lastImport = programPath.get("body").filter((p) => p.isImportDeclaration()).pop();
834
+ if (lastImport) {
835
+ lastImport.insertAfter(importDecl);
836
+ } else {
837
+ programPath.get("body")[0].insertBefore(importDecl);
838
+ }
839
+ }
840
+ }
841
+ function rewriteImportsReverse(programPath, tracker) {
842
+ const removed = tracker.getRemovedAtoms();
843
+ if (removed.size === 0) return;
844
+ programPath.traverse({
845
+ ImportDeclaration(path) {
846
+ if (path.node.source.value !== ATOM_IMPORT_SOURCE) return;
847
+ path.node.specifiers = path.node.specifiers.filter((spec) => {
848
+ if (spec.type !== "ImportSpecifier") return true;
849
+ const name = spec.imported.name;
850
+ return !removed.has(name);
851
+ });
852
+ if (path.node.specifiers.length === 0) {
853
+ path.remove();
854
+ }
855
+ }
856
+ });
857
+ let hasReactImport = false;
858
+ programPath.traverse({
859
+ ImportDeclaration(path) {
860
+ if (path.node.source.value === "react") {
861
+ hasReactImport = true;
862
+ }
863
+ }
864
+ });
865
+ if (!hasReactImport) {
866
+ const reactImport = t5.importDeclaration(
867
+ [t5.importDefaultSpecifier(t5.identifier("React"))],
868
+ t5.stringLiteral("react")
869
+ );
870
+ programPath.get("body")[0].insertBefore(reactImport);
871
+ }
872
+ }
873
+
874
+ // src/codemod/index.ts
875
+ var codemodPlugin = declare(
876
+ (api, options) => {
877
+ api.assertVersion(7);
878
+ const direction = options.direction || "forward";
879
+ const stateMode = options.stateMode || "preserve";
880
+ return {
881
+ name: "mm-codemod",
882
+ visitor: {
883
+ Program: {
884
+ enter(programPath) {
885
+ const imports = createImportTracker();
886
+ const stateVisitor = createStateVisitor(stateMode);
887
+ if (direction === "forward") {
888
+ const forwardVisitor = createForwardVisitor(imports, {
889
+ annotate: options.annotate ?? true,
890
+ stateMode
891
+ });
892
+ programPath.traverse(stateVisitor);
893
+ programPath.traverse(forwardVisitor);
894
+ rewriteImportsForward(programPath, imports);
895
+ } else {
896
+ const reverseVisitor = createReverseVisitor(imports, {
897
+ stripAnnotations: !options.annotate
898
+ });
899
+ programPath.traverse(reverseVisitor);
900
+ rewriteImportsReverse(programPath, imports);
901
+ }
902
+ }
903
+ }
904
+ }
905
+ };
906
+ }
907
+ );
908
+ var codemod_default = codemodPlugin;
909
+ function transform(source, options) {
910
+ const babelOptions = {
911
+ filename: "file.tsx",
912
+ plugins: [
913
+ ["@babel/plugin-syntax-typescript", { isTSX: true }],
914
+ [codemodPlugin, options]
915
+ ],
916
+ // Preserve formatting as much as possible
917
+ retainLines: true,
918
+ compact: false,
919
+ sourceMaps: true
920
+ };
921
+ const result = transformSync(source, babelOptions);
922
+ if (!result || !result.code) {
923
+ throw new Error("Codemod transform produced no output");
924
+ }
925
+ return { code: result.code, map: result.map };
926
+ }
927
+
928
+ export {
929
+ FORWARD_RULES,
930
+ REVERSE_RULES,
931
+ ATOM_IMPORT_SOURCE,
932
+ extractStaticClasses,
933
+ classifyElement,
934
+ reverseClassifyAtom,
935
+ createImportTracker,
936
+ codemodPlugin,
937
+ codemod_default,
938
+ transform
939
+ };