@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,1104 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
+ // If the importer is in node compatibility mode or this is not an ESM
19
+ // file that has been converted to a CommonJS file using a Babel-
20
+ // compatible transform (i.e. "__esModule" has not been set), then set
21
+ // "default" to the CommonJS "module.exports" for node compatibility.
22
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
+ mod
24
+ ));
25
+
26
+ // src/codemod/cli.ts
27
+ var import_fs = require("fs");
28
+ var import_path = require("path");
29
+ var import_glob = require("glob");
30
+
31
+ // src/codemod/index.ts
32
+ var import_core = require("@babel/core");
33
+ var import_helper_plugin_utils = require("@babel/helper-plugin-utils");
34
+
35
+ // src/codemod/forward.ts
36
+ var t2 = __toESM(require("@babel/types"));
37
+
38
+ // src/codemod/rules.ts
39
+ var FORWARD_RULES = [
40
+ // div with flex-col → Stack
41
+ {
42
+ htmlTag: "div",
43
+ atom: "Stack",
44
+ classSignal: ["flex-col"],
45
+ implicitClasses: ["flex", "flex-col"],
46
+ priority: 20
47
+ },
48
+ // div with grid → Grid
49
+ {
50
+ htmlTag: "div",
51
+ atom: "Grid",
52
+ classSignal: ["grid"],
53
+ implicitClasses: ["grid"],
54
+ priority: 20
55
+ },
56
+ // div with flex (no flex-col) → Row
57
+ {
58
+ htmlTag: "div",
59
+ atom: "Row",
60
+ classSignal: ["flex"],
61
+ implicitClasses: ["flex"],
62
+ priority: 10
63
+ },
64
+ // div with no layout signal → Stack (default container)
65
+ {
66
+ htmlTag: "div",
67
+ atom: "Stack",
68
+ classSignal: [],
69
+ implicitClasses: [],
70
+ priority: 0
71
+ },
72
+ // Semantic HTML
73
+ { htmlTag: "main", atom: "Stack", implicitClasses: [] },
74
+ { htmlTag: "aside", atom: "Stack", implicitClasses: [] },
75
+ { htmlTag: "nav", atom: "Stack", implicitClasses: [] },
76
+ { htmlTag: "section", atom: "Section", implicitClasses: [] },
77
+ { htmlTag: "header", atom: "Row", implicitClasses: [] },
78
+ { htmlTag: "footer", atom: "Row", implicitClasses: [] },
79
+ // Text elements
80
+ { htmlTag: "span", atom: "Text", implicitClasses: [] },
81
+ { htmlTag: "p", atom: "Text", implicitClasses: [] },
82
+ { htmlTag: "label", atom: "Text", implicitClasses: [] },
83
+ { htmlTag: "h1", atom: "Text", implicitClasses: [], props: { variant: "h1" } },
84
+ { htmlTag: "h2", atom: "Text", implicitClasses: [], props: { variant: "h2" } },
85
+ { htmlTag: "h3", atom: "Text", implicitClasses: [], props: { variant: "h3" } },
86
+ { htmlTag: "h4", atom: "Text", implicitClasses: [], props: { variant: "h4" } },
87
+ { htmlTag: "h5", atom: "Text", implicitClasses: [], props: { variant: "h5" } },
88
+ { htmlTag: "h6", atom: "Text", implicitClasses: [], props: { variant: "h6" } },
89
+ // Interactive elements
90
+ { htmlTag: "button", atom: "Button", implicitClasses: [] },
91
+ { htmlTag: "a", atom: "Link", implicitClasses: [] },
92
+ // Form elements
93
+ { htmlTag: "input", atom: "TextInput", implicitClasses: [] },
94
+ {
95
+ htmlTag: "textarea",
96
+ atom: "TextInput",
97
+ implicitClasses: [],
98
+ props: { multiline: true }
99
+ },
100
+ // Media
101
+ { htmlTag: "img", atom: "Image", implicitClasses: [] }
102
+ ];
103
+ var REVERSE_RULES = [
104
+ { atom: "Stack", htmlTag: "div", injectClasses: ["flex", "flex-col"] },
105
+ { atom: "Row", htmlTag: "div", injectClasses: ["flex"] },
106
+ { atom: "Grid", htmlTag: "div", injectClasses: ["grid"] },
107
+ { atom: "Text", htmlTag: "span" },
108
+ { atom: "Button", htmlTag: "button" },
109
+ { atom: "Link", htmlTag: "a" },
110
+ { atom: "TextInput", htmlTag: "input" },
111
+ { atom: "Image", htmlTag: "img" },
112
+ { atom: "Section", htmlTag: "section" }
113
+ ];
114
+ var CONTROL_FLOW_ATOMS = /* @__PURE__ */ new Set([
115
+ "Show",
116
+ "Each",
117
+ "Modal",
118
+ "Slot",
119
+ "Divider"
120
+ ]);
121
+ var ATOM_IMPORT_SOURCE = "@mindmatrix/react/atoms";
122
+ var TEXT_VARIANT_TO_TAG = {
123
+ h1: "h1",
124
+ h2: "h2",
125
+ h3: "h3",
126
+ h4: "h4",
127
+ h5: "h5",
128
+ h6: "h6"
129
+ };
130
+
131
+ // src/codemod/classify.ts
132
+ function extractStaticClasses(attrValue) {
133
+ if (!attrValue) return [];
134
+ if (attrValue.type === "StringLiteral") {
135
+ return attrValue.value.split(/\s+/).filter(Boolean);
136
+ }
137
+ if (attrValue.type === "JSXExpressionContainer") {
138
+ return extractStaticClasses(attrValue.expression);
139
+ }
140
+ if (attrValue.type === "TemplateLiteral") {
141
+ const staticParts = attrValue.quasis.map((q) => q.value.raw).join(" ");
142
+ return staticParts.split(/\s+/).filter(Boolean);
143
+ }
144
+ if (attrValue.type === "CallExpression" && attrValue.callee.type === "Identifier" && attrValue.callee.name === "cn" && attrValue.arguments.length > 0) {
145
+ const firstArg = attrValue.arguments[0];
146
+ if (firstArg.type === "StringLiteral") {
147
+ return firstArg.value.split(/\s+/).filter(Boolean);
148
+ }
149
+ }
150
+ return [];
151
+ }
152
+ function classifyElement(tagName, classNames) {
153
+ if (tagName[0] === tagName[0].toUpperCase() && tagName[0] !== tagName[0].toLowerCase()) {
154
+ return null;
155
+ }
156
+ if (tagName.startsWith("motion.")) {
157
+ return null;
158
+ }
159
+ const candidates = FORWARD_RULES.filter((r) => r.htmlTag === tagName).sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
160
+ if (candidates.length === 0) return null;
161
+ if (tagName === "div") {
162
+ for (const rule2 of candidates) {
163
+ if (!rule2.classSignal || rule2.classSignal.length === 0) {
164
+ continue;
165
+ }
166
+ const hasAllSignals = rule2.classSignal.every((s) => classNames.includes(s));
167
+ if (hasAllSignals) {
168
+ return makeResult(rule2, tagName);
169
+ }
170
+ }
171
+ const defaultRule = candidates.find((r) => (r.priority ?? 0) === 0);
172
+ if (defaultRule) {
173
+ return makeResult(defaultRule, tagName);
174
+ }
175
+ }
176
+ const rule = candidates[0];
177
+ return makeResult(rule, tagName);
178
+ }
179
+ function makeResult(rule, tagName) {
180
+ return {
181
+ atom: rule.atom,
182
+ removeClasses: rule.implicitClasses ?? [],
183
+ addProps: rule.props ?? {},
184
+ originalTag: tagName
185
+ };
186
+ }
187
+ function reverseClassifyAtom(atomName, props) {
188
+ if (CONTROL_FLOW_ATOMS.has(atomName)) return null;
189
+ if (atomName === "Text") {
190
+ const variantNode = props.get("variant");
191
+ if (variantNode && variantNode.type === "StringLiteral") {
192
+ const tag = TEXT_VARIANT_TO_TAG[variantNode.value];
193
+ if (tag) {
194
+ return {
195
+ htmlTag: tag,
196
+ injectClasses: [],
197
+ removeProps: ["variant"]
198
+ };
199
+ }
200
+ }
201
+ return { htmlTag: "span", injectClasses: [], removeProps: [] };
202
+ }
203
+ if (atomName === "TextInput") {
204
+ const multilineNode = props.get("multiline");
205
+ if (multilineNode) {
206
+ const isMultiline = multilineNode.type === "BooleanLiteral" && multilineNode.value || multilineNode.type === "JSXExpressionContainer" && multilineNode.expression?.type === "BooleanLiteral" && multilineNode.expression?.value;
207
+ if (isMultiline) {
208
+ return { htmlTag: "textarea", injectClasses: [], removeProps: ["multiline"] };
209
+ }
210
+ }
211
+ return { htmlTag: "input", injectClasses: [], removeProps: [] };
212
+ }
213
+ const rule = REVERSE_RULES.find((r) => r.atom === atomName);
214
+ if (!rule) return null;
215
+ return {
216
+ htmlTag: rule.htmlTag,
217
+ injectClasses: rule.injectClasses ?? [],
218
+ removeProps: rule.removeProps ?? []
219
+ };
220
+ }
221
+ function removeClassesFromString(className, toRemove) {
222
+ if (toRemove.length === 0) return className;
223
+ const removeSet = new Set(toRemove);
224
+ return className.split(/\s+/).filter((c) => c && !removeSet.has(c)).join(" ");
225
+ }
226
+ function addClassesToString(className, toAdd) {
227
+ if (toAdd.length === 0) return className;
228
+ const existing = new Set(className.split(/\s+/).filter(Boolean));
229
+ const newClasses = toAdd.filter((c) => !existing.has(c));
230
+ if (newClasses.length === 0) return className;
231
+ return [...newClasses, ...className.split(/\s+/).filter(Boolean)].join(" ");
232
+ }
233
+
234
+ // src/codemod/control-flow.ts
235
+ var t = __toESM(require("@babel/types"));
236
+ function matchConditionalRender(expr) {
237
+ if (expr.type !== "LogicalExpression" || expr.operator !== "&&") return null;
238
+ if (!isJSXLike(expr.right)) return null;
239
+ return { condition: expr.left, consequent: expr.right };
240
+ }
241
+ function matchTernaryRender(expr) {
242
+ if (expr.type !== "ConditionalExpression") return null;
243
+ if (!isJSXLike(expr.consequent) && !isJSXLike(expr.alternate)) return null;
244
+ return {
245
+ condition: expr.test,
246
+ consequent: expr.consequent,
247
+ alternate: expr.alternate
248
+ };
249
+ }
250
+ function matchMapRender(expr) {
251
+ if (expr.type !== "CallExpression") return null;
252
+ if (expr.callee.type !== "MemberExpression") return null;
253
+ const prop = expr.callee.property;
254
+ if (!(prop.type === "Identifier" && prop.name === "map")) return null;
255
+ const array = expr.callee.object;
256
+ const callback = expr.arguments[0];
257
+ if (!callback) return null;
258
+ if (callback.type !== "ArrowFunctionExpression" && callback.type !== "FunctionExpression")
259
+ return null;
260
+ const param = callback.params[0] || t.identifier("item");
261
+ const indexParam = callback.params[1] && callback.params[1].type === "Identifier" ? callback.params[1] : null;
262
+ let keyExpression = null;
263
+ const returnedJSX = getReturnedJSX(callback.body);
264
+ if (returnedJSX && returnedJSX.type === "JSXElement") {
265
+ const keyAttr = returnedJSX.openingElement.attributes.find(
266
+ (a) => a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && a.name.name === "key"
267
+ );
268
+ if (keyAttr && keyAttr.value) {
269
+ if (keyAttr.value.type === "JSXExpressionContainer") {
270
+ keyExpression = keyAttr.value.expression;
271
+ } else if (keyAttr.value.type === "StringLiteral") {
272
+ keyExpression = keyAttr.value;
273
+ }
274
+ }
275
+ }
276
+ return {
277
+ array,
278
+ param,
279
+ indexParam,
280
+ body: callback.body,
281
+ keyExpression
282
+ };
283
+ }
284
+ function createShowElement(condition, children) {
285
+ const whenAttr = t.jsxAttribute(
286
+ t.jsxIdentifier("when"),
287
+ t.jsxExpressionContainer(condition)
288
+ );
289
+ const childNodes = [];
290
+ if (t.isJSXElement(children) || t.isJSXFragment(children)) {
291
+ childNodes.push(children);
292
+ } else {
293
+ childNodes.push(t.jsxExpressionContainer(children));
294
+ }
295
+ return t.jsxElement(
296
+ t.jsxOpeningElement(t.jsxIdentifier("Show"), [whenAttr]),
297
+ t.jsxClosingElement(t.jsxIdentifier("Show")),
298
+ childNodes,
299
+ false
300
+ );
301
+ }
302
+ function createEachElement(items, paramName, body, keyExpression, indexParam) {
303
+ const attrs = [
304
+ t.jsxAttribute(
305
+ t.jsxIdentifier("items"),
306
+ t.jsxExpressionContainer(items)
307
+ ),
308
+ t.jsxAttribute(t.jsxIdentifier("as"), t.stringLiteral(paramName))
309
+ ];
310
+ if (keyExpression) {
311
+ attrs.push(
312
+ t.jsxAttribute(
313
+ t.jsxIdentifier("keyField"),
314
+ t.jsxExpressionContainer(keyExpression)
315
+ )
316
+ );
317
+ }
318
+ const params = [t.identifier(paramName)];
319
+ if (indexParam) params.push(indexParam);
320
+ const arrow = t.arrowFunctionExpression(params, body);
321
+ const child = t.jsxExpressionContainer(arrow);
322
+ removeKeyFromBody(body);
323
+ return t.jsxElement(
324
+ t.jsxOpeningElement(t.jsxIdentifier("Each"), attrs),
325
+ t.jsxClosingElement(t.jsxIdentifier("Each")),
326
+ [child],
327
+ false
328
+ );
329
+ }
330
+ function matchShowElement(node) {
331
+ const tag = node.openingElement.name;
332
+ if (tag.type !== "JSXIdentifier" || tag.name !== "Show") return null;
333
+ const whenAttr = node.openingElement.attributes.find(
334
+ (a) => a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && a.name.name === "when"
335
+ );
336
+ if (!whenAttr || !whenAttr.value) return null;
337
+ let condition;
338
+ if (whenAttr.value.type === "JSXExpressionContainer") {
339
+ condition = whenAttr.value.expression;
340
+ } else if (whenAttr.value.type === "StringLiteral") {
341
+ condition = whenAttr.value;
342
+ } else {
343
+ return null;
344
+ }
345
+ return { condition, children: node.children };
346
+ }
347
+ function matchEachElement(node) {
348
+ const tag = node.openingElement.name;
349
+ if (tag.type !== "JSXIdentifier" || tag.name !== "Each") return null;
350
+ const itemsAttr = node.openingElement.attributes.find(
351
+ (a) => a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && a.name.name === "items"
352
+ );
353
+ if (!itemsAttr?.value) return null;
354
+ const asAttr = node.openingElement.attributes.find(
355
+ (a) => a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && a.name.name === "as"
356
+ );
357
+ const keyAttr = node.openingElement.attributes.find(
358
+ (a) => a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && a.name.name === "keyField"
359
+ );
360
+ let items;
361
+ if (itemsAttr.value.type === "JSXExpressionContainer") {
362
+ items = itemsAttr.value.expression;
363
+ } else {
364
+ return null;
365
+ }
366
+ const paramName = asAttr?.value?.type === "StringLiteral" ? asAttr.value.value : "item";
367
+ let keyExpression = null;
368
+ if (keyAttr?.value?.type === "JSXExpressionContainer") {
369
+ keyExpression = keyAttr.value.expression;
370
+ }
371
+ return { items, paramName, keyExpression, children: node.children };
372
+ }
373
+ function showToConditional(condition, children) {
374
+ const content = unwrapChildren(children);
375
+ const logical = t.logicalExpression("&&", condition, content);
376
+ return t.jsxExpressionContainer(logical);
377
+ }
378
+ function eachToMap(items, paramName, keyExpression, children) {
379
+ let callback = null;
380
+ for (const child of children) {
381
+ if (child.type === "JSXExpressionContainer" && child.expression.type !== "JSXEmptyExpression") {
382
+ const expr = child.expression;
383
+ if (expr.type === "ArrowFunctionExpression" || expr.type === "FunctionExpression") {
384
+ callback = expr;
385
+ break;
386
+ }
387
+ }
388
+ }
389
+ if (!callback) {
390
+ const content = unwrapChildren(children);
391
+ callback = t.arrowFunctionExpression([t.identifier(paramName)], content);
392
+ }
393
+ if (keyExpression) {
394
+ addKeyToCallback(callback, keyExpression);
395
+ }
396
+ const mapCall = t.callExpression(
397
+ t.memberExpression(items, t.identifier("map")),
398
+ [callback]
399
+ );
400
+ return t.jsxExpressionContainer(mapCall);
401
+ }
402
+ function isJSXLike(node) {
403
+ return node.type === "JSXElement" || node.type === "JSXFragment" || node.type === "ParenthesizedExpression" && isJSXLike(node.expression);
404
+ }
405
+ function getReturnedJSX(body) {
406
+ if (body.type === "JSXElement" || body.type === "JSXFragment") return body;
407
+ if (body.type === "ParenthesizedExpression") {
408
+ return getReturnedJSX(body.expression);
409
+ }
410
+ if (body.type === "BlockStatement") {
411
+ for (const stmt of body.body) {
412
+ if (stmt.type === "ReturnStatement" && stmt.argument) {
413
+ if (stmt.argument.type === "JSXElement" || stmt.argument.type === "JSXFragment") {
414
+ return stmt.argument;
415
+ }
416
+ if (stmt.argument.type === "ParenthesizedExpression") {
417
+ return getReturnedJSX(stmt.argument.expression);
418
+ }
419
+ }
420
+ }
421
+ }
422
+ return null;
423
+ }
424
+ function removeKeyFromBody(body) {
425
+ const jsx = getReturnedJSX(body);
426
+ if (jsx && jsx.type === "JSXElement") {
427
+ jsx.openingElement.attributes = jsx.openingElement.attributes.filter(
428
+ (a) => !(a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && a.name.name === "key")
429
+ );
430
+ }
431
+ }
432
+ function addKeyToCallback(callback, keyExpr) {
433
+ const jsx = getReturnedJSX(callback.body);
434
+ if (jsx && jsx.type === "JSXElement") {
435
+ const hasKey = jsx.openingElement.attributes.some(
436
+ (a) => a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && a.name.name === "key"
437
+ );
438
+ if (!hasKey) {
439
+ jsx.openingElement.attributes.unshift(
440
+ t.jsxAttribute(
441
+ t.jsxIdentifier("key"),
442
+ t.jsxExpressionContainer(keyExpr)
443
+ )
444
+ );
445
+ }
446
+ }
447
+ }
448
+ function unwrapChildren(children) {
449
+ const meaningful = children.filter((c) => {
450
+ if (c.type === "JSXText") return c.value.trim().length > 0;
451
+ return true;
452
+ });
453
+ if (meaningful.length === 1) {
454
+ const child = meaningful[0];
455
+ if (child.type === "JSXElement" || child.type === "JSXFragment") return child;
456
+ if (child.type === "JSXExpressionContainer") {
457
+ return child.expression;
458
+ }
459
+ }
460
+ return t.jsxFragment(t.jsxOpeningFragment(), t.jsxClosingFragment(), meaningful);
461
+ }
462
+
463
+ // src/codemod/annotation.ts
464
+ var ANNOTATION_PREFIX = "@mm-original";
465
+ function createAnnotation(originalTag, classNames) {
466
+ const parts = [originalTag, ...classNames.slice(0, 10)];
467
+ return `${ANNOTATION_PREFIX} ${parts.join(".")}`;
468
+ }
469
+ function parseAnnotation(comment) {
470
+ const trimmed = comment.trim();
471
+ if (!trimmed.startsWith(ANNOTATION_PREFIX)) return null;
472
+ const rest = trimmed.slice(ANNOTATION_PREFIX.length).trim();
473
+ if (!rest) return null;
474
+ const parts = rest.split(".");
475
+ const tag = parts[0];
476
+ const classes = parts.slice(1);
477
+ return { tag, classes };
478
+ }
479
+ function addAnnotationComment(node, originalTag, classNames) {
480
+ const text = ` ${createAnnotation(originalTag, classNames)} `;
481
+ if (!node.leadingComments) {
482
+ node.leadingComments = [];
483
+ }
484
+ node.leadingComments.push({
485
+ type: "CommentBlock",
486
+ value: text
487
+ });
488
+ }
489
+ function readAnnotationComment(node) {
490
+ if (!node.leadingComments) return null;
491
+ for (let i = node.leadingComments.length - 1; i >= 0; i--) {
492
+ const comment = node.leadingComments[i];
493
+ const parsed = parseAnnotation(comment.value);
494
+ if (parsed) {
495
+ node.leadingComments.splice(i, 1);
496
+ return parsed;
497
+ }
498
+ }
499
+ return null;
500
+ }
501
+
502
+ // src/codemod/forward.ts
503
+ function createForwardVisitor(imports, options = {}) {
504
+ const { annotate = true } = options;
505
+ return {
506
+ JSXElement(path) {
507
+ const opening = path.node.openingElement;
508
+ const tag = opening.name;
509
+ if (tag.type !== "JSXIdentifier") return;
510
+ const tagName = tag.name;
511
+ const classAttr = opening.attributes.find(
512
+ (a) => a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && a.name.name === "className"
513
+ );
514
+ const staticClasses = extractStaticClasses(classAttr?.value ?? null);
515
+ const result = classifyElement(tagName, staticClasses);
516
+ if (!result) return;
517
+ if (annotate) {
518
+ addAnnotationComment(path.node, result.originalTag, staticClasses);
519
+ }
520
+ tag.name = result.atom;
521
+ if (path.node.closingElement) {
522
+ path.node.closingElement.name.name = result.atom;
523
+ }
524
+ imports.addAtom(result.atom);
525
+ if (classAttr && result.removeClasses.length > 0) {
526
+ updateClassName(classAttr, result.removeClasses, "remove");
527
+ }
528
+ for (const [key, value] of Object.entries(result.addProps)) {
529
+ const existing = opening.attributes.find(
530
+ (a) => a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && a.name.name === key
531
+ );
532
+ if (!existing) {
533
+ if (typeof value === "boolean") {
534
+ opening.attributes.push(
535
+ t2.jsxAttribute(
536
+ t2.jsxIdentifier(key),
537
+ value ? null : t2.jsxExpressionContainer(t2.booleanLiteral(false))
538
+ )
539
+ );
540
+ } else {
541
+ opening.attributes.push(
542
+ t2.jsxAttribute(t2.jsxIdentifier(key), t2.stringLiteral(value))
543
+ );
544
+ }
545
+ }
546
+ }
547
+ renameEventHandlers(opening, "forward");
548
+ },
549
+ JSXExpressionContainer(path) {
550
+ if (!path.parentPath.isJSXElement() && !path.parentPath.isJSXFragment()) return;
551
+ const expr = path.node.expression;
552
+ if (expr.type === "JSXEmptyExpression") return;
553
+ const conditional = matchConditionalRender(expr);
554
+ if (conditional) {
555
+ const showEl = createShowElement(conditional.condition, conditional.consequent);
556
+ imports.addAtom("Show");
557
+ path.replaceWith(showEl);
558
+ return;
559
+ }
560
+ const ternary = matchTernaryRender(expr);
561
+ if (ternary) {
562
+ const show1 = createShowElement(ternary.condition, ternary.consequent);
563
+ const negated = t2.unaryExpression("!", ternary.condition);
564
+ const show2 = createShowElement(negated, ternary.alternate);
565
+ imports.addAtom("Show");
566
+ path.replaceWithMultiple([show1, show2]);
567
+ return;
568
+ }
569
+ const mapRender = matchMapRender(expr);
570
+ if (mapRender) {
571
+ const paramName = mapRender.param.type === "Identifier" ? mapRender.param.name : "item";
572
+ const eachEl = createEachElement(
573
+ mapRender.array,
574
+ paramName,
575
+ mapRender.body,
576
+ mapRender.keyExpression,
577
+ mapRender.indexParam
578
+ );
579
+ imports.addAtom("Each");
580
+ path.replaceWith(eachEl);
581
+ return;
582
+ }
583
+ }
584
+ };
585
+ }
586
+ function updateClassName(attr, classes, operation) {
587
+ if (!attr.value) return;
588
+ if (attr.value.type === "StringLiteral") {
589
+ const result = operation === "remove" ? removeClassesFromString(attr.value.value, classes) : attr.value.value;
590
+ if (result.trim()) {
591
+ attr.value = t2.stringLiteral(result);
592
+ } else {
593
+ attr.value = t2.stringLiteral("");
594
+ }
595
+ return;
596
+ }
597
+ if (attr.value.type === "JSXExpressionContainer") {
598
+ const expr = attr.value.expression;
599
+ if (expr.type === "TemplateLiteral") {
600
+ for (const quasi of expr.quasis) {
601
+ if (operation === "remove") {
602
+ quasi.value.raw = removeClassesFromString(quasi.value.raw, classes);
603
+ quasi.value.cooked = removeClassesFromString(quasi.value.cooked ?? quasi.value.raw, classes);
604
+ }
605
+ }
606
+ return;
607
+ }
608
+ if (expr.type === "CallExpression" && expr.callee.type === "Identifier" && expr.callee.name === "cn" && expr.arguments.length > 0) {
609
+ const firstArg = expr.arguments[0];
610
+ if (firstArg.type === "StringLiteral" && operation === "remove") {
611
+ firstArg.value = removeClassesFromString(firstArg.value, classes);
612
+ }
613
+ return;
614
+ }
615
+ }
616
+ }
617
+ function renameEventHandlers(opening, direction) {
618
+ const map = direction === "forward" ? { onClick: "onPress", onChange: "onChange", onSubmit: "onSubmit" } : { onPress: "onClick" };
619
+ for (const attr of opening.attributes) {
620
+ if (attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier" && attr.name.name in map) {
621
+ attr.name.name = map[attr.name.name];
622
+ }
623
+ }
624
+ }
625
+
626
+ // src/codemod/reverse.ts
627
+ var t3 = __toESM(require("@babel/types"));
628
+ function createReverseVisitor(imports, _options = {}) {
629
+ return {
630
+ JSXElement: {
631
+ // Use exit so children are processed first (bottom-up)
632
+ exit(path) {
633
+ const opening = path.node.openingElement;
634
+ const tag = opening.name;
635
+ if (tag.type !== "JSXIdentifier") return;
636
+ const atomName = tag.name;
637
+ const showMatch = matchShowElement(path.node);
638
+ if (showMatch) {
639
+ const replacement = showToConditional(showMatch.condition, showMatch.children);
640
+ imports.removeAtom("Show");
641
+ path.replaceWith(replacement);
642
+ return;
643
+ }
644
+ const eachMatch = matchEachElement(path.node);
645
+ if (eachMatch) {
646
+ const replacement = eachToMap(
647
+ eachMatch.items,
648
+ eachMatch.paramName,
649
+ eachMatch.keyExpression,
650
+ eachMatch.children
651
+ );
652
+ imports.removeAtom("Each");
653
+ path.replaceWith(replacement);
654
+ return;
655
+ }
656
+ const annotation = readAnnotationComment(path.node);
657
+ const propsMap = /* @__PURE__ */ new Map();
658
+ for (const attr of opening.attributes) {
659
+ if (attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier") {
660
+ propsMap.set(attr.name.name, attr.value ?? t3.booleanLiteral(true));
661
+ }
662
+ }
663
+ const result = reverseClassifyAtom(atomName, propsMap);
664
+ if (!result) return;
665
+ const targetTag = annotation?.tag ?? result.htmlTag;
666
+ tag.name = targetTag;
667
+ if (path.node.closingElement) {
668
+ path.node.closingElement.name.name = targetTag;
669
+ }
670
+ imports.removeAtom(atomName);
671
+ if (result.removeProps.length > 0) {
672
+ opening.attributes = opening.attributes.filter(
673
+ (attr) => !(attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier" && result.removeProps.includes(attr.name.name))
674
+ );
675
+ }
676
+ if (result.injectClasses.length > 0) {
677
+ injectClasses(opening, result.injectClasses, annotation?.classes);
678
+ }
679
+ renameEventHandlers2(opening);
680
+ }
681
+ }
682
+ };
683
+ }
684
+ function injectClasses(opening, injectClasses2, _annotationClasses) {
685
+ const classAttr = opening.attributes.find(
686
+ (a) => a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && a.name.name === "className"
687
+ );
688
+ if (classAttr && classAttr.value) {
689
+ if (classAttr.value.type === "StringLiteral") {
690
+ classAttr.value = t3.stringLiteral(
691
+ addClassesToString(classAttr.value.value, injectClasses2)
692
+ );
693
+ return;
694
+ }
695
+ if (classAttr.value.type === "JSXExpressionContainer") {
696
+ const expr = classAttr.value.expression;
697
+ if (expr.type === "TemplateLiteral" && expr.quasis.length > 0) {
698
+ const first = expr.quasis[0];
699
+ first.value.raw = addClassesToString(first.value.raw, injectClasses2);
700
+ first.value.cooked = addClassesToString(first.value.cooked ?? first.value.raw, injectClasses2);
701
+ return;
702
+ }
703
+ if (expr.type === "CallExpression" && expr.callee.type === "Identifier" && expr.callee.name === "cn" && expr.arguments.length > 0 && expr.arguments[0].type === "StringLiteral") {
704
+ expr.arguments[0] = t3.stringLiteral(
705
+ addClassesToString(expr.arguments[0].value, injectClasses2)
706
+ );
707
+ return;
708
+ }
709
+ }
710
+ } else {
711
+ const classValue = injectClasses2.join(" ");
712
+ if (classValue) {
713
+ opening.attributes.push(
714
+ t3.jsxAttribute(
715
+ t3.jsxIdentifier("className"),
716
+ t3.stringLiteral(classValue)
717
+ )
718
+ );
719
+ }
720
+ }
721
+ }
722
+ function renameEventHandlers2(opening) {
723
+ const map = { onPress: "onClick" };
724
+ for (const attr of opening.attributes) {
725
+ if (attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier" && attr.name.name in map) {
726
+ attr.name.name = map[attr.name.name];
727
+ }
728
+ }
729
+ }
730
+
731
+ // src/codemod/state-transform.ts
732
+ var t4 = __toESM(require("@babel/types"));
733
+ function createStateVisitor(mode) {
734
+ if (mode === "preserve") return {};
735
+ if (mode === "annotate") {
736
+ return {
737
+ VariableDeclaration(path) {
738
+ for (const decl of path.node.declarations) {
739
+ if (!isUseStateCall(decl.init)) continue;
740
+ if (hasFieldAnnotation(path.node)) continue;
741
+ const fieldType = inferFieldType(decl.init);
742
+ const comment = ` @mm-field type=${fieldType} `;
743
+ if (!path.node.trailingComments) {
744
+ path.node.trailingComments = [];
745
+ }
746
+ path.node.trailingComments.push({
747
+ type: "CommentLine",
748
+ value: comment
749
+ });
750
+ }
751
+ }
752
+ };
753
+ }
754
+ return {
755
+ VariableDeclaration(path) {
756
+ for (const decl of path.node.declarations) {
757
+ if (!isUseStateCall(decl.init)) continue;
758
+ const migrateAnnotation = getMigrateAnnotation(path.node);
759
+ if (!migrateAnnotation) continue;
760
+ if (migrateAnnotation.type === "query") {
761
+ if (decl.id.type !== "ArrayPattern" || decl.id.elements.length < 1)
762
+ continue;
763
+ const nameNode = decl.id.elements[0];
764
+ if (!nameNode || nameNode.type !== "Identifier") continue;
765
+ decl.id = nameNode;
766
+ decl.init = t4.callExpression(t4.identifier("useQuery"), [
767
+ t4.stringLiteral(migrateAnnotation.model || nameNode.name),
768
+ t4.objectExpression([
769
+ t4.objectProperty(
770
+ t4.identifier("where"),
771
+ t4.objectExpression([])
772
+ )
773
+ ])
774
+ ]);
775
+ }
776
+ }
777
+ }
778
+ };
779
+ }
780
+ function isUseStateCall(node) {
781
+ return !!node && node.type === "CallExpression" && node.callee.type === "Identifier" && node.callee.name === "useState";
782
+ }
783
+ function hasFieldAnnotation(node) {
784
+ return !!node.trailingComments && node.trailingComments.some((c) => c.value.includes("@mm-field"));
785
+ }
786
+ function inferFieldType(call) {
787
+ if (call.arguments.length === 0) return "any";
788
+ const arg = call.arguments[0];
789
+ if (arg.type === "StringLiteral") return "text";
790
+ if (arg.type === "NumericLiteral") return "number";
791
+ if (arg.type === "BooleanLiteral") return "boolean";
792
+ if (arg.type === "ArrayExpression") return "list";
793
+ if (arg.type === "ObjectExpression") return "object";
794
+ if (arg.type === "NullLiteral") return "any";
795
+ return "any";
796
+ }
797
+ function getMigrateAnnotation(node) {
798
+ const comments = [
799
+ ...node.leadingComments || [],
800
+ ...node.trailingComments || []
801
+ ];
802
+ for (const c of comments) {
803
+ const match = c.value.match(/@mm-migrate:\s*(query|mutation)(?:\s+(\w+))?/);
804
+ if (match) {
805
+ return {
806
+ type: match[1],
807
+ model: match[2]
808
+ };
809
+ }
810
+ }
811
+ return null;
812
+ }
813
+
814
+ // src/codemod/import-manager.ts
815
+ var t5 = __toESM(require("@babel/types"));
816
+ function createImportTracker() {
817
+ const used = /* @__PURE__ */ new Set();
818
+ const removed = /* @__PURE__ */ new Set();
819
+ return {
820
+ addAtom(name) {
821
+ used.add(name);
822
+ removed.delete(name);
823
+ },
824
+ removeAtom(name) {
825
+ removed.add(name);
826
+ },
827
+ getUsedAtoms() {
828
+ return used;
829
+ },
830
+ getRemovedAtoms() {
831
+ return removed;
832
+ }
833
+ };
834
+ }
835
+ function rewriteImportsForward(programPath, tracker) {
836
+ const usedAtoms = tracker.getUsedAtoms();
837
+ if (usedAtoms.size === 0) return;
838
+ let existingImport = null;
839
+ programPath.traverse({
840
+ ImportDeclaration(path) {
841
+ if (path.node.source.value === ATOM_IMPORT_SOURCE) {
842
+ existingImport = path;
843
+ }
844
+ }
845
+ });
846
+ if (existingImport) {
847
+ const existing = new Set(
848
+ existingImport.node.specifiers.filter((s) => s.type === "ImportSpecifier").map((s) => s.imported.name)
849
+ );
850
+ for (const atom of usedAtoms) {
851
+ if (!existing.has(atom)) {
852
+ existingImport.node.specifiers.push(
853
+ t5.importSpecifier(t5.identifier(atom), t5.identifier(atom))
854
+ );
855
+ }
856
+ }
857
+ } else {
858
+ const specifiers = Array.from(usedAtoms).sort().map((name) => t5.importSpecifier(t5.identifier(name), t5.identifier(name)));
859
+ const importDecl = t5.importDeclaration(
860
+ specifiers,
861
+ t5.stringLiteral(ATOM_IMPORT_SOURCE)
862
+ );
863
+ const lastImport = programPath.get("body").filter((p) => p.isImportDeclaration()).pop();
864
+ if (lastImport) {
865
+ lastImport.insertAfter(importDecl);
866
+ } else {
867
+ programPath.get("body")[0].insertBefore(importDecl);
868
+ }
869
+ }
870
+ }
871
+ function rewriteImportsReverse(programPath, tracker) {
872
+ const removed = tracker.getRemovedAtoms();
873
+ if (removed.size === 0) return;
874
+ programPath.traverse({
875
+ ImportDeclaration(path) {
876
+ if (path.node.source.value !== ATOM_IMPORT_SOURCE) return;
877
+ path.node.specifiers = path.node.specifiers.filter((spec) => {
878
+ if (spec.type !== "ImportSpecifier") return true;
879
+ const name = spec.imported.name;
880
+ return !removed.has(name);
881
+ });
882
+ if (path.node.specifiers.length === 0) {
883
+ path.remove();
884
+ }
885
+ }
886
+ });
887
+ let hasReactImport = false;
888
+ programPath.traverse({
889
+ ImportDeclaration(path) {
890
+ if (path.node.source.value === "react") {
891
+ hasReactImport = true;
892
+ }
893
+ }
894
+ });
895
+ if (!hasReactImport) {
896
+ const reactImport = t5.importDeclaration(
897
+ [t5.importDefaultSpecifier(t5.identifier("React"))],
898
+ t5.stringLiteral("react")
899
+ );
900
+ programPath.get("body")[0].insertBefore(reactImport);
901
+ }
902
+ }
903
+
904
+ // src/codemod/index.ts
905
+ var codemodPlugin = (0, import_helper_plugin_utils.declare)(
906
+ (api, options) => {
907
+ api.assertVersion(7);
908
+ const direction = options.direction || "forward";
909
+ const stateMode = options.stateMode || "preserve";
910
+ return {
911
+ name: "mm-codemod",
912
+ visitor: {
913
+ Program: {
914
+ enter(programPath) {
915
+ const imports = createImportTracker();
916
+ const stateVisitor = createStateVisitor(stateMode);
917
+ if (direction === "forward") {
918
+ const forwardVisitor = createForwardVisitor(imports, {
919
+ annotate: options.annotate ?? true,
920
+ stateMode
921
+ });
922
+ programPath.traverse(stateVisitor);
923
+ programPath.traverse(forwardVisitor);
924
+ rewriteImportsForward(programPath, imports);
925
+ } else {
926
+ const reverseVisitor = createReverseVisitor(imports, {
927
+ stripAnnotations: !options.annotate
928
+ });
929
+ programPath.traverse(reverseVisitor);
930
+ rewriteImportsReverse(programPath, imports);
931
+ }
932
+ }
933
+ }
934
+ }
935
+ };
936
+ }
937
+ );
938
+ function transform(source, options) {
939
+ const babelOptions = {
940
+ filename: "file.tsx",
941
+ plugins: [
942
+ ["@babel/plugin-syntax-typescript", { isTSX: true }],
943
+ [codemodPlugin, options]
944
+ ],
945
+ // Preserve formatting as much as possible
946
+ retainLines: true,
947
+ compact: false,
948
+ sourceMaps: true
949
+ };
950
+ const result = (0, import_core.transformSync)(source, babelOptions);
951
+ if (!result || !result.code) {
952
+ throw new Error("Codemod transform produced no output");
953
+ }
954
+ return { code: result.code, map: result.map };
955
+ }
956
+
957
+ // src/codemod/cli.ts
958
+ function parseArgs(argv) {
959
+ const args = argv.slice(2);
960
+ const direction = args[0];
961
+ if (!direction || !["forward", "reverse", "verify"].includes(direction)) {
962
+ console.error("Usage: mm-codemod <forward|reverse|verify> <paths...> [options]");
963
+ console.error("");
964
+ console.error("Options:");
965
+ console.error(" --dry-run Print diff without writing");
966
+ console.error(" --strip-annotations Remove @mm-original comments");
967
+ console.error(" --mode <mode> State mode: preserve|migrate|annotate");
968
+ console.error(" --out <dir> Output directory (default: in-place)");
969
+ console.error(" --verbose Log every transformation");
970
+ process.exit(1);
971
+ }
972
+ const paths = [];
973
+ let dryRun = false;
974
+ let stripAnnotations = false;
975
+ let stateMode = "preserve";
976
+ let verbose = false;
977
+ let outDir;
978
+ for (let i = 1; i < args.length; i++) {
979
+ const arg = args[i];
980
+ if (arg === "--dry-run") {
981
+ dryRun = true;
982
+ } else if (arg === "--strip-annotations") {
983
+ stripAnnotations = true;
984
+ } else if (arg === "--mode") {
985
+ stateMode = args[++i];
986
+ } else if (arg === "--out") {
987
+ outDir = args[++i];
988
+ } else if (arg === "--verbose") {
989
+ verbose = true;
990
+ } else if (!arg.startsWith("-")) {
991
+ paths.push(arg);
992
+ }
993
+ }
994
+ if (paths.length === 0) {
995
+ console.error("Error: No paths specified");
996
+ process.exit(1);
997
+ }
998
+ return { direction, paths, dryRun, stripAnnotations, stateMode, verbose, outDir };
999
+ }
1000
+ async function findFiles(paths) {
1001
+ const files = [];
1002
+ for (const p of paths) {
1003
+ const resolved = (0, import_path.resolve)(p);
1004
+ const matches = await (0, import_glob.glob)("**/*.{tsx,jsx}", {
1005
+ cwd: resolved,
1006
+ absolute: true,
1007
+ ignore: ["**/node_modules/**", "**/__tests__/**", "**/dist/**"]
1008
+ });
1009
+ files.push(...matches);
1010
+ }
1011
+ return files.sort();
1012
+ }
1013
+ function transformFile(filePath, options, verbose) {
1014
+ const source = (0, import_fs.readFileSync)(filePath, "utf-8");
1015
+ try {
1016
+ const result = transform(source, options);
1017
+ const changed = result.code !== source;
1018
+ if (verbose && changed) {
1019
+ console.log(` [${options.direction}] ${(0, import_path.relative)(process.cwd(), filePath)}`);
1020
+ }
1021
+ return { code: result.code, changed };
1022
+ } catch (err) {
1023
+ console.error(` [ERROR] ${(0, import_path.relative)(process.cwd(), filePath)}: ${err.message}`);
1024
+ return { code: source, changed: false };
1025
+ }
1026
+ }
1027
+ async function main() {
1028
+ const opts = parseArgs(process.argv);
1029
+ const files = await findFiles(opts.paths);
1030
+ console.log(`mm-codemod: ${opts.direction} \u2014 ${files.length} file(s)`);
1031
+ if (opts.direction === "verify") {
1032
+ let pass = 0;
1033
+ let fail = 0;
1034
+ for (const file of files) {
1035
+ const source = (0, import_fs.readFileSync)(file, "utf-8");
1036
+ const forward = transform(source, {
1037
+ direction: "forward",
1038
+ annotate: true,
1039
+ stateMode: opts.stateMode
1040
+ });
1041
+ const roundTripped = transform(forward.code, {
1042
+ direction: "reverse",
1043
+ annotate: false,
1044
+ stateMode: opts.stateMode
1045
+ });
1046
+ const normalize = (s) => s.replace(/\s+/g, " ").trim();
1047
+ if (normalize(roundTripped.code) === normalize(source)) {
1048
+ pass++;
1049
+ if (opts.verbose) console.log(` [PASS] ${(0, import_path.relative)(process.cwd(), file)}`);
1050
+ } else {
1051
+ fail++;
1052
+ console.log(` [FAIL] ${(0, import_path.relative)(process.cwd(), file)}`);
1053
+ if (opts.verbose) {
1054
+ console.log(" Expected (normalized):");
1055
+ console.log(` ${normalize(source).slice(0, 200)}...`);
1056
+ console.log(" Got (normalized):");
1057
+ console.log(` ${normalize(roundTripped.code).slice(0, 200)}...`);
1058
+ }
1059
+ }
1060
+ }
1061
+ console.log(`
1062
+ Results: ${pass} pass, ${fail} fail out of ${files.length} files`);
1063
+ process.exit(fail > 0 ? 1 : 0);
1064
+ }
1065
+ const codemodOptions = {
1066
+ direction: opts.direction,
1067
+ annotate: !opts.stripAnnotations,
1068
+ stateMode: opts.stateMode
1069
+ };
1070
+ let changed = 0;
1071
+ let unchanged = 0;
1072
+ let errors = 0;
1073
+ for (const file of files) {
1074
+ try {
1075
+ const result = transformFile(file, codemodOptions, opts.verbose);
1076
+ if (!result.changed) {
1077
+ unchanged++;
1078
+ continue;
1079
+ }
1080
+ changed++;
1081
+ if (opts.dryRun) {
1082
+ console.log(` [WOULD CHANGE] ${(0, import_path.relative)(process.cwd(), file)}`);
1083
+ continue;
1084
+ }
1085
+ let outPath = file;
1086
+ if (opts.outDir) {
1087
+ const rel = (0, import_path.relative)((0, import_path.resolve)(opts.paths[0]), file);
1088
+ outPath = (0, import_path.resolve)(opts.outDir, rel);
1089
+ const dir = (0, import_path.dirname)(outPath);
1090
+ if (!(0, import_fs.existsSync)(dir)) (0, import_fs.mkdirSync)(dir, { recursive: true });
1091
+ }
1092
+ (0, import_fs.writeFileSync)(outPath, result.code, "utf-8");
1093
+ } catch (err) {
1094
+ errors++;
1095
+ console.error(` [ERROR] ${(0, import_path.relative)(process.cwd(), file)}: ${err.message}`);
1096
+ }
1097
+ }
1098
+ console.log(`
1099
+ Done: ${changed} changed, ${unchanged} unchanged, ${errors} errors`);
1100
+ }
1101
+ main().catch((err) => {
1102
+ console.error(err);
1103
+ process.exit(1);
1104
+ });