@mmapp/react-compiler 0.1.0-alpha.1

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 (314) hide show
  1. package/README.md +107 -0
  2. package/compile-blueprint-chat.mjs +99 -0
  3. package/compile-blueprint-glass-console.mjs +98 -0
  4. package/compile-chat-defs.mjs +92 -0
  5. package/dist/babel/index.d.mts +3 -0
  6. package/dist/babel/index.d.ts +3 -0
  7. package/dist/babel/index.js +4851 -0
  8. package/dist/babel/index.mjs +7 -0
  9. package/dist/chunk-26U577GB.mjs +3465 -0
  10. package/dist/chunk-2FBDFAX6.mjs +2362 -0
  11. package/dist/chunk-2L4QSMXG.mjs +175 -0
  12. package/dist/chunk-2REDFOER.mjs +931 -0
  13. package/dist/chunk-46YKSHQR.mjs +175 -0
  14. package/dist/chunk-4XHK6FWL.mjs +2058 -0
  15. package/dist/chunk-5M7DKKBC.mjs +215 -0
  16. package/dist/chunk-5VNJ7C6N.mjs +154 -0
  17. package/dist/chunk-6CQOAAMV.mjs +1803 -0
  18. package/dist/chunk-6SEVAAVT.mjs +3516 -0
  19. package/dist/chunk-6YLR5ZDA.mjs +2829 -0
  20. package/dist/chunk-AOGY2GK6.mjs +3292 -0
  21. package/dist/chunk-AXXUXRNA.mjs +1434 -0
  22. package/dist/chunk-CHLVKMQW.mjs +175 -0
  23. package/dist/chunk-CKGOZAB7.mjs +939 -0
  24. package/dist/chunk-D34RAZUX.mjs +2223 -0
  25. package/dist/chunk-EQGA6A6D.mjs +121 -0
  26. package/dist/chunk-EY2CSXYA.mjs +822 -0
  27. package/dist/chunk-FIQ65CDR.mjs +925 -0
  28. package/dist/chunk-FOZXJFAR.mjs +186 -0
  29. package/dist/chunk-FX6URXWN.mjs +186 -0
  30. package/dist/chunk-G7SMOWOL.mjs +828 -0
  31. package/dist/chunk-GGB4G5YY.mjs +175 -0
  32. package/dist/chunk-HLRGCCIL.mjs +4839 -0
  33. package/dist/chunk-HOIUP6IF.mjs +690 -0
  34. package/dist/chunk-I3AU7GRD.mjs +120 -0
  35. package/dist/chunk-ILFGMUVD.mjs +1933 -0
  36. package/dist/chunk-IPTX5MJU.mjs +3223 -0
  37. package/dist/chunk-ITGUSH2Z.mjs +2783 -0
  38. package/dist/chunk-IXHBCAMF.mjs +3306 -0
  39. package/dist/chunk-J7TWJ3TM.mjs +2784 -0
  40. package/dist/chunk-JDPLDGVF.mjs +4810 -0
  41. package/dist/chunk-K53XP2DL.mjs +148 -0
  42. package/dist/chunk-K5HX2SVL.mjs +1902 -0
  43. package/dist/chunk-KFGYOOVS.mjs +214 -0
  44. package/dist/chunk-KFVVOS5N.mjs +925 -0
  45. package/dist/chunk-L2OZ4CDV.mjs +113 -0
  46. package/dist/chunk-MIZV3TAN.mjs +3293 -0
  47. package/dist/chunk-NKKLQE5V.mjs +148 -0
  48. package/dist/chunk-NOW23XFZ.mjs +186 -0
  49. package/dist/chunk-NRXQKQ74.mjs +148 -0
  50. package/dist/chunk-OWI6XWCD.mjs +3375 -0
  51. package/dist/chunk-PRUMNNDI.mjs +3192 -0
  52. package/dist/chunk-QTBD5B3F.mjs +148 -0
  53. package/dist/chunk-SKSDPPNT.mjs +3788 -0
  54. package/dist/chunk-SP2YUS33.mjs +186 -0
  55. package/dist/chunk-SU4E6E7B.mjs +3153 -0
  56. package/dist/chunk-SYUUKW5A.mjs +3379 -0
  57. package/dist/chunk-UL2XZEMA.mjs +3128 -0
  58. package/dist/chunk-XMWUHQVV.mjs +939 -0
  59. package/dist/chunk-XZNEDRGN.mjs +3876 -0
  60. package/dist/chunk-Y6FXYEAI.mjs +10 -0
  61. package/dist/chunk-YFS6JMYO.mjs +3342 -0
  62. package/dist/chunk-Z6AIQ4KL.mjs +113 -0
  63. package/dist/cli/index.d.mts +1 -0
  64. package/dist/cli/index.d.ts +1 -0
  65. package/dist/cli/index.js +11585 -0
  66. package/dist/cli/index.mjs +701 -0
  67. package/dist/codemod/cli.d.mts +1 -0
  68. package/dist/codemod/cli.d.ts +1 -0
  69. package/dist/codemod/cli.js +1104 -0
  70. package/dist/codemod/cli.mjs +157 -0
  71. package/dist/codemod/index.d.mts +148 -0
  72. package/dist/codemod/index.d.ts +148 -0
  73. package/dist/codemod/index.js +981 -0
  74. package/dist/codemod/index.mjs +25 -0
  75. package/dist/dev-server-Bs_sz2DG.d.mts +111 -0
  76. package/dist/dev-server-Bs_sz2DG.d.ts +111 -0
  77. package/dist/dev-server-CjoufJ-u.d.mts +109 -0
  78. package/dist/dev-server-CjoufJ-u.d.ts +109 -0
  79. package/dist/dev-server.d.mts +3 -0
  80. package/dist/dev-server.d.ts +3 -0
  81. package/dist/dev-server.js +7603 -0
  82. package/dist/dev-server.mjs +11 -0
  83. package/dist/envelope-DD7v0v6E.d.mts +265 -0
  84. package/dist/envelope-DD7v0v6E.d.ts +265 -0
  85. package/dist/envelope-vCVjrHlo.d.mts +265 -0
  86. package/dist/envelope-vCVjrHlo.d.ts +265 -0
  87. package/dist/envelope.d.mts +2 -0
  88. package/dist/envelope.d.ts +2 -0
  89. package/dist/envelope.js +5184 -0
  90. package/dist/envelope.mjs +9 -0
  91. package/dist/index-B5gSgvnd.d.mts +44 -0
  92. package/dist/index-B5gSgvnd.d.ts +44 -0
  93. package/dist/index-Bs0MnR54.d.mts +103 -0
  94. package/dist/index-Bs0MnR54.d.ts +103 -0
  95. package/dist/index-DR0nNc_f.d.mts +101 -0
  96. package/dist/index-DR0nNc_f.d.ts +101 -0
  97. package/dist/index-revho_gS.d.mts +104 -0
  98. package/dist/index-revho_gS.d.ts +104 -0
  99. package/dist/index.d.mts +1099 -0
  100. package/dist/index.d.ts +1099 -0
  101. package/dist/index.js +10162 -0
  102. package/dist/index.mjs +372 -0
  103. package/dist/init-IXEE2RCF.mjs +340 -0
  104. package/dist/project-compiler-EGJUTAJU.mjs +10 -0
  105. package/dist/project-compiler-VFR6CSDX.mjs +10 -0
  106. package/dist/project-decompiler-5GY2KSG4.mjs +7 -0
  107. package/dist/pull-A2QUHW4K.mjs +109 -0
  108. package/dist/pull-JBEQWVPE.mjs +109 -0
  109. package/dist/testing/index.d.mts +211 -0
  110. package/dist/testing/index.d.ts +211 -0
  111. package/dist/testing/index.js +5106 -0
  112. package/dist/testing/index.mjs +247 -0
  113. package/dist/vite/index.d.mts +59 -0
  114. package/dist/vite/index.d.ts +59 -0
  115. package/dist/vite/index.js +5023 -0
  116. package/dist/vite/index.mjs +8 -0
  117. package/examples/README.md +72 -0
  118. package/examples/authentication/main.workflow.tsx +139 -0
  119. package/examples/authentication/mm.config.ts +22 -0
  120. package/examples/authentication/models/auth.ts +45 -0
  121. package/examples/authentication/pages/LoginPage.tsx +79 -0
  122. package/examples/authentication/pages/SignupPage.tsx +87 -0
  123. package/examples/counter.workflow.tsx +65 -0
  124. package/examples/dashboard.workflow.tsx +419 -0
  125. package/examples/invoice-approval/actions/invoice.server.ts +72 -0
  126. package/examples/invoice-approval/main.workflow.tsx +168 -0
  127. package/examples/invoice-approval/mm.config.ts +18 -0
  128. package/examples/invoice-approval/models/invoice.ts +46 -0
  129. package/examples/invoice-approval/pages/InvoiceDetailPage.tsx +175 -0
  130. package/examples/invoice-approval/pages/InvoiceFormPage.tsx +198 -0
  131. package/examples/invoice-approval/pages/InvoiceListPage.tsx +141 -0
  132. package/examples/todo-app.workflow.tsx +131 -0
  133. package/examples/uber-app/actions/matching.server.ts +177 -0
  134. package/examples/uber-app/actions/notifications.server.ts +176 -0
  135. package/examples/uber-app/actions/payments.server.ts +184 -0
  136. package/examples/uber-app/actions/pricing.server.ts +176 -0
  137. package/examples/uber-app/app/admin/analytics.tsx +102 -0
  138. package/examples/uber-app/app/admin/fleet.tsx +102 -0
  139. package/examples/uber-app/app/admin/surge-pricing.tsx +95 -0
  140. package/examples/uber-app/app/driver/dashboard.tsx +87 -0
  141. package/examples/uber-app/app/driver/earnings.tsx +101 -0
  142. package/examples/uber-app/app/driver/navigation.tsx +94 -0
  143. package/examples/uber-app/app/driver/ride-acceptance.tsx +103 -0
  144. package/examples/uber-app/app/rider/home.tsx +109 -0
  145. package/examples/uber-app/app/rider/payment-methods.tsx +134 -0
  146. package/examples/uber-app/app/rider/ride-history.tsx +90 -0
  147. package/examples/uber-app/app/rider/ride-tracking.tsx +108 -0
  148. package/examples/uber-app/components/DriverCard.tsx +176 -0
  149. package/examples/uber-app/components/MapView.tsx +216 -0
  150. package/examples/uber-app/components/RatingStars.tsx +227 -0
  151. package/examples/uber-app/components/RideCard.tsx +167 -0
  152. package/examples/uber-app/mm.config.ts +30 -0
  153. package/examples/uber-app/models/location.model.ts +70 -0
  154. package/examples/uber-app/models/payment.model.ts +87 -0
  155. package/examples/uber-app/models/rating.model.ts +54 -0
  156. package/examples/uber-app/models/ride.model.ts +118 -0
  157. package/examples/uber-app/models/user.model.ts +66 -0
  158. package/examples/uber-app/models/vehicle.model.ts +63 -0
  159. package/examples/uber-app/tests/payment.test.tsx +129 -0
  160. package/examples/uber-app/tests/ride-flow.test.tsx +123 -0
  161. package/examples/uber-app/workflows/dispute-resolution.workflow.tsx +205 -0
  162. package/examples/uber-app/workflows/driver-onboarding.workflow.tsx +227 -0
  163. package/examples/uber-app/workflows/payment-processing.workflow.tsx +223 -0
  164. package/examples/uber-app/workflows/ride-request.workflow.tsx +194 -0
  165. package/package.json +77 -0
  166. package/package.json.backup +86 -0
  167. package/scripts/decompile.ts +226 -0
  168. package/scripts/seed-auth.ts +267 -0
  169. package/scripts/seed-uber.ts +248 -0
  170. package/scripts/validate-uber.ts +119 -0
  171. package/seed-blueprint-chat.mjs +444 -0
  172. package/seed-blueprint-glass-console.mjs +445 -0
  173. package/seed-compiled.mjs +318 -0
  174. package/src/RoundTripValidator.ts +400 -0
  175. package/src/__tests__/atom-rendering-coverage.test.ts +680 -0
  176. package/src/__tests__/auth-module-compilation.test.ts +247 -0
  177. package/src/__tests__/auth-template-compilation.test.ts +589 -0
  178. package/src/__tests__/change-extractor.test.ts +142 -0
  179. package/src/__tests__/cli-pull.test.ts +73 -0
  180. package/src/__tests__/cli-test.test.ts +72 -0
  181. package/src/__tests__/component-extractor.test.ts +331 -0
  182. package/src/__tests__/context-extractor.test.ts +145 -0
  183. package/src/__tests__/decompiler.test.ts +718 -0
  184. package/src/__tests__/define-blueprint.test.ts +133 -0
  185. package/src/__tests__/definition-validator.test.ts +519 -0
  186. package/src/__tests__/during-extractor.test.ts +152 -0
  187. package/src/__tests__/effect-extractor.test.ts +107 -0
  188. package/src/__tests__/event-emission.test.ts +127 -0
  189. package/src/__tests__/examples.test.ts +236 -0
  190. package/src/__tests__/full-blueprint-coverage.test.ts +1221 -0
  191. package/src/__tests__/golden-suite.test.ts +403 -0
  192. package/src/__tests__/grammar-island-extractor.test.ts +289 -0
  193. package/src/__tests__/instance-key.test.ts +82 -0
  194. package/src/__tests__/ir-migration.test.ts +255 -0
  195. package/src/__tests__/lock-file.test.ts +117 -0
  196. package/src/__tests__/model-extractor.test.ts +195 -0
  197. package/src/__tests__/model-field-acl.test.ts +237 -0
  198. package/src/__tests__/model-hooks.test.ts +130 -0
  199. package/src/__tests__/model-ref-resolution.test.ts +268 -0
  200. package/src/__tests__/model-roundtrip.test.ts +502 -0
  201. package/src/__tests__/model-runtime.test.ts +112 -0
  202. package/src/__tests__/model-transitions.test.ts +183 -0
  203. package/src/__tests__/nrt-action-trace.test.ts +391 -0
  204. package/src/__tests__/pipeline-hardening.test.ts +413 -0
  205. package/src/__tests__/project-compiler.test.ts +546 -0
  206. package/src/__tests__/project-decompiler.test.ts +343 -0
  207. package/src/__tests__/query-compilation.test.ts +145 -0
  208. package/src/__tests__/round-trip/PLAN.md +158 -0
  209. package/src/__tests__/round-trip/README.md +52 -0
  210. package/src/__tests__/round-trip/RESULTS.md +86 -0
  211. package/src/__tests__/round-trip/fixtures/data-heavy/main.workflow.tsx +55 -0
  212. package/src/__tests__/round-trip/fixtures/data-heavy/mm.config.ts +11 -0
  213. package/src/__tests__/round-trip/fixtures/data-heavy/models/contact.ts +54 -0
  214. package/src/__tests__/round-trip/fixtures/full-workflow/main.workflow.tsx +79 -0
  215. package/src/__tests__/round-trip/fixtures/full-workflow/mm.config.ts +12 -0
  216. package/src/__tests__/round-trip/fixtures/full-workflow/models/order.ts +50 -0
  217. package/src/__tests__/round-trip/fixtures/simple-crud/main.workflow.tsx +25 -0
  218. package/src/__tests__/round-trip/fixtures/simple-crud/mm.config.ts +11 -0
  219. package/src/__tests__/round-trip/fixtures/simple-crud/models/task.ts +32 -0
  220. package/src/__tests__/round-trip/fixtures/view-heavy/main.workflow.tsx +79 -0
  221. package/src/__tests__/round-trip/fixtures/view-heavy/mm.config.ts +10 -0
  222. package/src/__tests__/round-trip/round-trip.test.ts +2598 -0
  223. package/src/__tests__/round-trip-ir.test.ts +300 -0
  224. package/src/__tests__/round-trip.test.ts +1212 -0
  225. package/src/__tests__/route-merging.test.ts +372 -0
  226. package/src/__tests__/router-composition.test.ts +489 -0
  227. package/src/__tests__/router-extractor.test.ts +176 -0
  228. package/src/__tests__/server-action-extractor.test.ts +128 -0
  229. package/src/__tests__/smart-type-inference.test.ts +365 -0
  230. package/src/__tests__/source-envelope.test.ts +284 -0
  231. package/src/__tests__/source-fidelity.test.ts +516 -0
  232. package/src/__tests__/state-extractor.test.ts +115 -0
  233. package/src/__tests__/strict-mode.test.ts +227 -0
  234. package/src/__tests__/transition-effect-extractor.test.ts +119 -0
  235. package/src/__tests__/transition-extractor.test.ts +68 -0
  236. package/src/__tests__/ts-to-expression.test.ts +462 -0
  237. package/src/__tests__/type-generator.test.ts +201 -0
  238. package/src/__tests__/uber-validation.test.ts +502 -0
  239. package/src/action-compiler.ts +361 -0
  240. package/src/babel/emitters/experience-transform.ts +199 -0
  241. package/src/babel/emitters/ir-to-tsx-emitter.ts +110 -0
  242. package/src/babel/emitters/pure-form-emitter.ts +1023 -0
  243. package/src/babel/emitters/runtime-glue-emitter.ts +39 -0
  244. package/src/babel/extractors/change-extractor.ts +199 -0
  245. package/src/babel/extractors/component-extractor.ts +907 -0
  246. package/src/babel/extractors/computed-extractor.ts +262 -0
  247. package/src/babel/extractors/context-extractor.ts +277 -0
  248. package/src/babel/extractors/during-extractor.ts +295 -0
  249. package/src/babel/extractors/effect-extractor.ts +340 -0
  250. package/src/babel/extractors/event-extractor.ts +235 -0
  251. package/src/babel/extractors/grammar-island-extractor.ts +302 -0
  252. package/src/babel/extractors/model-extractor.ts +1018 -0
  253. package/src/babel/extractors/router-extractor.ts +303 -0
  254. package/src/babel/extractors/server-action-extractor.ts +173 -0
  255. package/src/babel/extractors/server-action-hook-extractor.ts +72 -0
  256. package/src/babel/extractors/server-state-extractor.ts +88 -0
  257. package/src/babel/extractors/state-extractor.ts +214 -0
  258. package/src/babel/extractors/transition-effect-extractor.ts +176 -0
  259. package/src/babel/extractors/transition-extractor.ts +143 -0
  260. package/src/babel/index.ts +24 -0
  261. package/src/babel/transpilers/ts-to-expression.ts +674 -0
  262. package/src/babel/visitor.ts +807 -0
  263. package/src/cli/auth.ts +255 -0
  264. package/src/cli/build.ts +288 -0
  265. package/src/cli/deploy.ts +206 -0
  266. package/src/cli/index.ts +328 -0
  267. package/src/cli/init.ts +388 -0
  268. package/src/cli/installer.ts +261 -0
  269. package/src/cli/lock-file.ts +94 -0
  270. package/src/cli/mmrc.ts +22 -0
  271. package/src/cli/pull.ts +172 -0
  272. package/src/cli/registry-client.ts +175 -0
  273. package/src/cli/test.ts +397 -0
  274. package/src/cli/type-generator.ts +243 -0
  275. package/src/codemod/__tests__/forward.test.ts +239 -0
  276. package/src/codemod/__tests__/reverse.test.ts +145 -0
  277. package/src/codemod/__tests__/round-trip.test.ts +137 -0
  278. package/src/codemod/annotation.ts +97 -0
  279. package/src/codemod/classify.ts +197 -0
  280. package/src/codemod/cli.ts +207 -0
  281. package/src/codemod/control-flow.ts +409 -0
  282. package/src/codemod/forward.ts +244 -0
  283. package/src/codemod/import-manager.ts +171 -0
  284. package/src/codemod/index.ts +120 -0
  285. package/src/codemod/reverse.ts +197 -0
  286. package/src/codemod/rules.ts +174 -0
  287. package/src/codemod/state-transform.ts +126 -0
  288. package/src/decompiler/ast-builder.ts +538 -0
  289. package/src/decompiler/config-generator.ts +151 -0
  290. package/src/decompiler/index.ts +315 -0
  291. package/src/decompiler/project-decompiler.ts +1776 -0
  292. package/src/decompiler/project.ts +862 -0
  293. package/src/decompiler/split-strategy.ts +140 -0
  294. package/src/decompiler/state-emitter.ts +1053 -0
  295. package/src/decompiler/sx-emitter.ts +318 -0
  296. package/src/decompiler/workspace-hydrator.ts +189 -0
  297. package/src/dev-server.ts +238 -0
  298. package/src/envelope/fs-tree.ts +217 -0
  299. package/src/envelope/source-envelope.ts +264 -0
  300. package/src/envelope.ts +315 -0
  301. package/src/incremental-compiler.ts +401 -0
  302. package/src/index.ts +99 -0
  303. package/src/model-compiler.ts +277 -0
  304. package/src/project-compiler.ts +1629 -0
  305. package/src/route-extractor.ts +333 -0
  306. package/src/testing/index.ts +32 -0
  307. package/src/testing/snapshot.ts +252 -0
  308. package/src/testing/test-utils.ts +226 -0
  309. package/src/types.ts +68 -0
  310. package/src/vite/index.ts +288 -0
  311. package/test-compile.mjs +142 -0
  312. package/tsconfig.json +25 -0
  313. package/tsup.config.ts +23 -0
  314. package/vitest.config.ts +9 -0
@@ -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 = "@mindmatrix/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
+ };